Skip to content

Commit

Permalink
properly handle messages in threads
Browse files Browse the repository at this point in the history
  • Loading branch information
paulchen committed Feb 4, 2024
1 parent 3c7ef0b commit bfabdd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RoomMessageStreamHandler(eventHandler: EventHandler, botConfiguration: Bot

private fun handleStreamMessageItem(messageNode: JsonNode): List<SendMessageMessage> {
val messageText = messageNode.get("msg").textValue().trim()
val parentMessageId = messageNode.get("tmid")?.textValue()?.trim()
val roomId = messageNode.get("rid").textValue()
val roomName = getRoomName(messageNode)
val timestamp = messageNode.get("ts")?.get("\$date")?.asLong()
Expand Down Expand Up @@ -71,7 +72,7 @@ class RoomMessageStreamHandler(eventHandler: EventHandler, botConfiguration: Bot
eventHandler.handleRoomMessage(channel, user, message)
}
return outgoingMessages.map {
MessageHelper.instance.createSendMessage(roomId, it.message, botConfiguration.botId, it.emoji, it.username)
MessageHelper.instance.createSendMessage(roomId, it.message, botConfiguration.botId, parentMessageId, it.username, it.emoji)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class MessageHelper {
val instance = MessageHelper()
}

fun createSendMessage(roomId: String, message: String, botId: String, emoji: String? = null, username: String? = null): SendMessageMessage {
fun createSendMessage(roomId: String, message: String, botId: String, parentMessageId: String? = null, emoji: String? = null, username: String? = null): SendMessageMessage {
val id = UUID.randomUUID().toString()
val botTag = mapOf("i" to botId)
val params = mutableMapOf("_id" to id, "rid" to roomId, "msg" to message, "bot" to botTag)
if (StringUtils.isNotBlank(parentMessageId)) {
params["tmid"] = parentMessageId!!
}
if (StringUtils.isNotBlank(emoji)) {
params["emoji"] = emoji!!
}
Expand Down

0 comments on commit bfabdd0

Please sign in to comment.