-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message thread #12
base: master
Are you sure you want to change the base?
Message thread #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ class CommandsRecognizerBot(override val bus: MessageEventBus) extends IncomingM | |
|
||
def receive: Receive = { | ||
|
||
case bm@BaseMessage(text, channel, user, dateTime, edited) => | ||
case bm@BaseMessage(text, channel, user, dateTime, Some(thread_ts),edited) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space before |
||
//COMMAND links list with bot's nam jack can be called: | ||
// jack link list | ||
// jack: link list | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,84 @@ object MessageJsonProtocol extends DefaultJsonProtocol { | |
|
||
def read(value: JsValue) = { | ||
|
||
value.asJsObject.getFields("text", "channel", "user", "ts", "edited") match { | ||
value.asJsObject.getFields("text", "channel", "user", "ts", "edited", "thread_ts") match { | ||
|
||
case Seq(JsString(text), JsString(channel), JsString(user), JsString(ts)) => | ||
BaseMessage(text, channel, user, ts, edited = false) | ||
|
||
case Seq(JsString(text), JsString(channel), JsString(user), JsString(ts), JsObject(edited)) => | ||
|
||
BaseMessage(text, channel, user, ts, edited = true) | ||
|
||
case Seq(JsString(text), JsString(channel), JsString(user), JsString(ts), JsString(thread_ts)) => | ||
BaseMessage(text, channel, user, ts, Some(thread_ts)) | ||
|
||
case Seq(JsString(text), JsString(channel), JsString(user), JsString(ts), JsString(thread_ts), JsObject(edited)) => | ||
BaseMessage(text, channel, user, ts, Some(thread_ts), edited = true) | ||
|
||
case _ => | ||
throw new DeserializationException("BaseMessage expected") | ||
} | ||
} | ||
} | ||
|
||
implicit object MessageThreadJsonReader extends RootJsonReader[MessageThread] { | ||
def read(value: JsValue) = { | ||
value.asJsObject.getFields("message","hidden","channel", "event_ts", "ts") match { | ||
case Vector(message,JsTrue, JsString(channel), JsString(event_ts), JsString(ts)) => | ||
MessageThread(message.convertTo[Message], true, channel,event_ts,ts) | ||
|
||
implicit val messageTypeFormat = jsonFormat(MessageType, "type", "subtype") | ||
case _ => | ||
throw new DeserializationException("MessageThread expected") | ||
} | ||
} | ||
} | ||
|
||
implicit object MessageJsonReader extends RootJsonReader[Message] { | ||
|
||
def read(value: JsValue) = { | ||
value.asJsObject.getFields("user", "text", "thread_ts", "reply_count", "replies", "unread_count", "ts") match { | ||
case Vector(JsString(user), JsString(text), JsString(thread_ts), JsNumber(reply_count), replies, JsNumber(unread_count),JsString(ts)) => | ||
Message(user, text, thread_ts, reply_count, replies.convertTo[Replies], unread_count, ts) | ||
|
||
case _ => | ||
throw new DeserializationException("Message expected") | ||
} | ||
} | ||
} | ||
|
||
implicit object RepliesJsonReader extends RootJsonFormat[Replies] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a |
||
|
||
def read(value: JsValue) = { | ||
println(value.getClass) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove ;) |
||
value match { | ||
case JsArray(replies) => | ||
val r = replies.map{ x => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a space before Replies {
replies.map(_.convertTo[Reply])
} |
||
x.convertTo[Reply] | ||
} | ||
Replies(r) | ||
|
||
case _ => | ||
throw new DeserializationException("Reply expected") | ||
} | ||
} | ||
|
||
override def write(obj: Replies): JsValue = serializationError("not supported") | ||
} | ||
|
||
implicit object ReplyJsonReader extends RootJsonFormat[Reply] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question about format vs reader |
||
|
||
def read(value: JsValue) = { | ||
value.asJsObject.getFields("user", "ts") match { | ||
case Seq(JsString(user), JsString(ts)) => | ||
Reply(user, ts) | ||
|
||
case _ => | ||
throw new DeserializationException("Reply expected") | ||
} | ||
} | ||
|
||
override def write(obj: Reply): JsValue = serializationError("not supported") | ||
} | ||
|
||
implicit val messageTypeFormat = jsonFormat(MessageType, "type", "subtype") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case will match also
Some
, unless the order is reversed.