diff --git a/src/status/chat/utils.nim b/src/status/chat/utils.nim index 82b5c0b5e0..a2c32d46e9 100644 --- a/src/status/chat/utils.nim +++ b/src/status/chat/utils.nim @@ -1,20 +1,24 @@ +import ../libstatus/settings as status_settings + proc formatChatUpdate(response: JsonNode): (seq[Chat], seq[Message]) = var chats: seq[Chat] = @[] var messages: seq[Message] = @[] + let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0") if response["result"]{"chats"} != nil: for jsonMsg in response["result"]["messages"]: - messages.add(jsonMsg.toMessage) + messages.add(jsonMsg.toMessage(pk)) if response["result"]{"chats"} != nil: for jsonChat in response["result"]["chats"]: chats.add(jsonChat.toChat) result = (chats, messages) proc processChatUpdate(self: ChatModel, response: JsonNode): (seq[Chat], seq[Message]) = + let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0") var chats: seq[Chat] = @[] var messages: seq[Message] = @[] if response{"result"}{"chats"} != nil: for jsonMsg in response["result"]["messages"]: - messages.add(jsonMsg.toMessage) + messages.add(jsonMsg.toMessage(pk)) if response{"result"}{"chats"} != nil: for jsonChat in response["result"]["chats"]: let chat = jsonChat.toChat diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index 521f7863bc..717787fa0f 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -61,9 +61,7 @@ proc parseChatMessagesResponse*(chatId: string, rpcResult: JsonNode): (string, s var msg: Message if rpcResult["messages"].kind != JNull: for jsonMsg in rpcResult["messages"]: - msg = jsonMsg.toMessage - msg.hasMention = concat(msg.parsedText.map(t => t.children.filter(c => c.textType == "mention" and c.literal == pk))).len > 0 - messages.add(msg) + messages.add(jsonMsg.toMessage(pk)) return (rpcResult{"cursor"}.getStr, messages) proc rpcChatMessages*(chatId: string, cursorVal: JsonNode, limit: int, success: var bool): string = diff --git a/src/status/signals/messages.nim b/src/status/signals/messages.nim index 91ee3a2948..c261b0a4c4 100644 --- a/src/status/signals/messages.nim +++ b/src/status/signals/messages.nim @@ -13,7 +13,7 @@ import types import web3/conversions from ../libstatus/utils import parseAddress, wei2Eth -proc toMessage*(jsonMsg: JsonNode): Message +proc toMessage*(jsonMsg: JsonNode, pk: string): Message proc toChat*(jsonChat: JsonNode): Chat @@ -36,8 +36,7 @@ proc fromEvent*(event: JsonNode): Signal = if event["event"]{"messages"} != nil: for jsonMsg in event["event"]["messages"]: - var message = jsonMsg.toMessage - message.hasMention = concat(message.parsedText.map(t => t.children.filter(c => c.textType == "mention" and c.literal == pk))).len > 0 + var message = jsonMsg.toMessage(pk) if message.hasMention: chatsWithMentions.add(message.chatId) signal.messages.add(message) @@ -120,6 +119,8 @@ proc toChat*(jsonChat: JsonNode): Chat = let chatTypeInt = jsonChat{"chatType"}.getInt let chatType: ChatType = if chatTypeInt >= ord(low(ChatType)) or chatTypeInt <= ord(high(ChatType)): ChatType(chatTypeInt) else: ChatType.Unknown + let pk = status_settings.getSetting[string](Setting.PublicKey, "0x0") + result = Chat( id: jsonChat{"id"}.getStr, communityId: jsonChat{"communityId"}.getStr, @@ -141,7 +142,7 @@ proc toChat*(jsonChat: JsonNode): Chat = result.muted = jsonChat["muted"].getBool if jsonChat["lastMessage"].kind != JNull: - result.lastMessage = jsonChat{"lastMessage"}.toMessage + result.lastMessage = jsonChat{"lastMessage"}.toMessage(pk) if result.chatType == ChatType.OneToOne: result.identicon = generateIdenticon(result.id) @@ -202,7 +203,7 @@ proc toTextItem*(jsonText: JsonNode): TextItem = result.children.add(child.toTextItem) -proc toMessage*(jsonMsg: JsonNode): Message = +proc toMessage*(jsonMsg: JsonNode, pk: string): Message = var contentType: ContentType try: contentType = ContentType(jsonMsg{"contentType"}.getInt) @@ -277,6 +278,8 @@ proc toMessage*(jsonMsg: JsonNode): Message = signature: jsonMsg["commandParameters"]["signature"].getStr ) + message.hasMention = concat(message.parsedText.map(t => t.children.filter(c => c.textType == "mention" and c.literal == pk))).len > 0 + result = message proc toReaction*(jsonReaction: JsonNode): Reaction =