diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 6873ca0866..34c1a9450d 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -121,7 +121,7 @@ QtObject: proc upsertChannel(self: ChatsView, channel: string) = if not self.messageList.hasKey(channel): - self.messageList[channel] = newChatMessageList(channel) + self.messageList[channel] = newChatMessageList(channel, self.status) proc messagePushed*(self: ChatsView) {.signal.} diff --git a/src/app/chat/views/message_format.nim b/src/app/chat/views/message_format.nim index dcc1aa7629..1afcf7c814 100644 --- a/src/app/chat/views/message_format.nim +++ b/src/app/chat/views/message_format.nim @@ -5,27 +5,32 @@ proc sectionIdentifier(message: Message): string = if message.contentType == ContentType.Group: result = "GroupChatMessage" +proc mention(self: ChatMessageList, pubKey: string): string = + if self.status.chat.contacts.hasKey(pubKey): + result = ens.userNameOrAlias(self.status.chat.contacts[pubKey]) + else: + result = generateAlias(pubKey) # See render-inline in status-react/src/status_im/ui/screens/chat/message/message.cljs -proc renderInline(elem: TextItem): string = +proc renderInline(self: ChatMessageList, elem: TextItem): string = case elem.textType: of "": result = elem.literal of "code": result = fmt("{elem.literal} ") of "emph": result = fmt("{elem.literal} ") of "strong": result = fmt("{elem.literal} ") of "link": result = "TODO: write safe link here: " & elem.destination - of "mention": result = elem.literal + of "mention": result = fmt("{self.mention(elem.literal)} ") # See render-block in status-react/src/status_im/ui/screens/chat/message/message.cljs -proc renderBlock(message: Message): string = +proc renderBlock(self: ChatMessageList, message: Message): string = # TODO: find out how to extract the css styles for pMsg in message.parsedText: case pMsg.textType: of "paragraph": result = "
" for children in pMsg.children: - result = result & renderInline(children) + result = result & self.renderInline(children) result = result & "
" of "blockquote": # TODO: extract this from the theme somehow diff --git a/src/app/chat/views/message_list.nim b/src/app/chat/views/message_list.nim index 53c765a38e..62e4272811 100644 --- a/src/app/chat/views/message_list.nim +++ b/src/app/chat/views/message_list.nim @@ -1,10 +1,11 @@ import NimQml, Tables +import ../../../status/status +import ../../../status/accounts import ../../../status/chat import ../../../status/chat/[message,stickers] import ../../../status/profile/profile import ../../../status/ens import strformat -include message_format type ChatMessageRoles {.pure.} = enum @@ -25,6 +26,7 @@ QtObject: type ChatMessageList* = ref object of QAbstractListModel messages*: seq[Message] + status: Status proc delete(self: ChatMessageList) = self.messages = @[] @@ -33,14 +35,17 @@ QtObject: proc setup(self: ChatMessageList) = self.QAbstractListModel.setup + include message_format + proc chatIdentifier(self: ChatMessageList, chatId:string): Message = result = Message() result.contentType = ContentType.ChatIdentifier; result.chatId = chatId - proc newChatMessageList*(chatId: string): ChatMessageList = + proc newChatMessageList*(chatId: string, status: Status): ChatMessageList = new(result, delete) result.messages = @[result.chatIdentifier(chatId)] + result.status = status result.setup method rowCount(self: ChatMessageList, index: QModelIndex = nil): int = @@ -55,7 +60,7 @@ QtObject: let chatMessageRole = role.ChatMessageRoles case chatMessageRole: of ChatMessageRoles.UserName: result = newQVariant(message.alias) - of ChatMessageRoles.Message: result = newQVariant(renderBlock(message)) + of ChatMessageRoles.Message: result = newQVariant(self.renderBlock(message)) of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp) of ChatMessageRoles.Clock: result = newQVariant($message.clock) of ChatMessageRoles.Identicon: result = newQVariant(message.identicon) diff --git a/src/status/accounts.nim b/src/status/accounts.nim index b19ed6b391..73d7a8c09f 100644 --- a/src/status/accounts.nim +++ b/src/status/accounts.nim @@ -1,6 +1,7 @@ import eventemitter, options import libstatus/accounts as status_accounts import libstatus/types +import libstatus/utils type AccountModel* = ref object @@ -44,3 +45,6 @@ proc importMnemonic*(self: AccountModel, mnemonic: string): GeneratedAccount = proc reset*(self: AccountModel) = self.nodeAccounts = @[] self.generatedAddresses = @[] + +proc generateAlias*(publicKey: string): string = + result = status_accounts.generateAlias(publicKey) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index 3d3e4159bc..5a709da17f 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -151,6 +151,7 @@ Item { width: parent.width - 120 horizontalAlignment: Text.AlignHCenter anchors.horizontalCenter: parent.horizontalCenter + textFormat: Text.RichText } // Messages