From 75e3e10f58c853ee8125844661809e0bceceb04f Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Tue, 7 Jul 2020 15:45:00 +0200 Subject: [PATCH] feat(chat): open user profile from mentions Closes #455 --- src/app/chat/view.nim | 9 +++++++++ src/app/chat/views/message_format.nim | 2 +- src/status/accounts.nim | 3 +++ ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index ebf383a8a7..48ccaed35e 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -1,6 +1,7 @@ import NimQml, Tables, json, sequtils, chronicles import ../../status/status +import ../../status/accounts as status_accounts import ../../status/chat as status_chat import ../../status/contacts as status_contacts import ../../status/ens as status_ens @@ -238,3 +239,11 @@ QtObject: proc formatENSUsername*(self: ChatsView, username: string): string {.slot.} = result = status_ens.addDomain(username) + + proc generateIdenticon*(self: ChatsView, pk: string): string {.slot.} = + result = status_accounts.generateIdenticon(pk) + + proc userNameOrAlias*(self: ChatsView, pubKey: string): string {.slot.} = + if self.status.chat.contacts.hasKey(pubKey): + return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey]) + generateAlias(pubKey) diff --git a/src/app/chat/views/message_format.nim b/src/app/chat/views/message_format.nim index 1b6b767ef1..69a473c7c2 100644 --- a/src/app/chat/views/message_format.nim +++ b/src/app/chat/views/message_format.nim @@ -19,7 +19,7 @@ proc renderInline(self: ChatMessageList, elem: TextItem): string = of "emph": result = fmt("{elem.literal} ") of "strong": result = fmt("{elem.literal} ") of "link": result = elem.destination - of "mention": result = fmt("{self.mention(elem.literal)} ") + of "mention": result = fmt("@{self.mention(elem.literal)} ") of "status-tag": result = fmt("{elem.literal} ") # See render-block in status-react/src/status_im/ui/screens/chat/message/message.cljs diff --git a/src/status/accounts.nim b/src/status/accounts.nim index 73d7a8c09f..d66268824c 100644 --- a/src/status/accounts.nim +++ b/src/status/accounts.nim @@ -48,3 +48,6 @@ proc reset*(self: AccountModel) = proc generateAlias*(publicKey: string): string = result = status_accounts.generateAlias(publicKey) + +proc generateIdenticon*(publicKey: string): string = + result = status_accounts.generateIdenticon(publicKey) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index dc8fd94396..d9c59195f0 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -288,6 +288,12 @@ Item { return; } + if (link.startsWith('//')) { + let pk = link.replace("//", ""); + profileClick(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk)) + return; + } + Qt.openUrlExternally(link) } MouseArea {