diff --git a/src/app/chat/core.nim b/src/app/chat/core.nim index cace6a9ee7..2bcc98f101 100644 --- a/src/app/chat/core.nim +++ b/src/app/chat/core.nim @@ -4,6 +4,7 @@ import ../../status/mailservers as mailserver_model import ../../status/messages as messages_model import ../../status/signals/types import ../../status/libstatus/types as status_types +import ../../status/libstatus/settings as status_settings import ../../status/[chat, contacts, status, wallet, stickers] import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view import ../../eventemitter @@ -34,8 +35,11 @@ proc init*(self: ChatController) = self.handleChatEvents() self.handleSignals() + let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0") + + self.view.pubKey = pubKey self.status.mailservers.init() - self.status.chat.init() + self.status.chat.init(pubKey) self.status.stickers.init() self.view.reactions.init() diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index c5dbdf1ab8..712c340cfe 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -40,6 +40,7 @@ QtObject: unreadMessageCnt: int oldestMessageTimestamp: int64 loadingMessages: bool + pubKey*: string proc setup(self: ChatsView) = self.QAbstractListModel.setup @@ -123,7 +124,7 @@ QtObject: proc plainText(self: ChatsView, input: string): string {.slot.} = result = plain_text(input) - proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int) {.slot.} = + proc sendMessage*(self: ChatsView, message: string, replyTo: string, contentType: int = ContentType.Message.int, isStatusUpdate: bool = false) {.slot.} = let aliasPattern = re(r"(@[A-z][a-z]+ [A-z][a-z]* [A-z][a-z]*)", flags = {reStudy, reIgnoreCase}) let ensPattern = re(r"(@\w+(?=(\.stateofus)?\.eth))", flags = {reStudy, reIgnoreCase}) let namePattern = re(r"(@\w+)", flags = {reStudy, reIgnoreCase}) @@ -137,7 +138,13 @@ QtObject: var m = self.replaceMentionsWithPubKeys(aliasMentions, contacts, message, (c => c.alias)) m = self.replaceMentionsWithPubKeys(ensMentions, contacts, m, (c => c.ensName)) m = self.replaceMentionsWithPubKeys(nameMentions, contacts, m, (c => c.ensName.split(".")[0])) - self.status.chat.sendMessage(self.activeChannel.id, m, replyTo, contentType) + + var channelId = self.activeChannel.id + + if isStatusUpdate: + channelId = "@" & self.pubKey + + self.status.chat.sendMessage(channelId, m, replyTo, contentType) proc verifyMessageSent*(self: ChatsView, data: string) {.slot.} = let messageData = data.parseJson @@ -148,12 +155,18 @@ QtObject: self.status.chat.resendMessage(messageId) self.messageList[chatId].resetTimeOut(messageId) - proc sendImage*(self: ChatsView, imagePath: string): string {.slot.} = + proc sendImage*(self: ChatsView, imagePath: string, isStatusUpdate: bool = false): string {.slot.} = result = "" try: var image = image_utils.formatImagePath(imagePath) let tmpImagePath = image_resizer(image, 2000, TMPDIR) - self.status.chat.sendImage(self.activeChannel.id, tmpImagePath) + + var channelId = self.activeChannel.id + + if isStatusUpdate: + channelId = "@" & self.pubKey + + self.status.chat.sendImage(channelId, tmpImagePath) removeFile(tmpImagePath) except Exception as e: error "Error sending the image", msg = e.msg diff --git a/src/status/chat.nim b/src/status/chat.nim index 1956b547d6..cccdf21764 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -125,8 +125,8 @@ proc updateContacts*(self: ChatModel, contacts: seq[Profile]) = self.contacts[c.id] = c self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts)) -proc init*(self: ChatModel) = - let chatList = status_chat.loadChats() +proc init*(self: ChatModel, pubKey: string) = + var chatList = status_chat.loadChats() var filters:seq[JsonNode] = @[] for chat in chatList: