mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-26 13:36:04 +00:00
feat: Replace pubkeys by alias/ens in group system message
This commit is contained in:
parent
21af287654
commit
e8858f25ba
@ -121,7 +121,7 @@ QtObject:
|
|||||||
|
|
||||||
proc upsertChannel(self: ChatsView, channel: string) =
|
proc upsertChannel(self: ChatsView, channel: string) =
|
||||||
if not self.messageList.hasKey(channel):
|
if not self.messageList.hasKey(channel):
|
||||||
self.messageList[channel] = newChatMessageList(channel)
|
self.messageList[channel] = newChatMessageList(channel, self.status)
|
||||||
|
|
||||||
proc messagePushed*(self: ChatsView) {.signal.}
|
proc messagePushed*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
|
@ -5,27 +5,32 @@ proc sectionIdentifier(message: Message): string =
|
|||||||
if message.contentType == ContentType.Group:
|
if message.contentType == ContentType.Group:
|
||||||
result = "GroupChatMessage"
|
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
|
# 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:
|
case elem.textType:
|
||||||
of "": result = elem.literal
|
of "": result = elem.literal
|
||||||
of "code": result = fmt("<span style=\"background-color: #1a356b; color: #FFFFFF\">{elem.literal}</span> ")
|
of "code": result = fmt("<span style=\"background-color: #1a356b; color: #FFFFFF\">{elem.literal}</span> ")
|
||||||
of "emph": result = fmt("<span style=\"font-style: italic;\">{elem.literal}</span> ")
|
of "emph": result = fmt("<span style=\"font-style: italic;\">{elem.literal}</span> ")
|
||||||
of "strong": result = fmt("<span style=\"font-weight: bold;\">{elem.literal}</span> ")
|
of "strong": result = fmt("<span style=\"font-weight: bold;\">{elem.literal}</span> ")
|
||||||
of "link": result = "TODO: write safe link here: " & elem.destination
|
of "link": result = "TODO: write safe link here: " & elem.destination
|
||||||
of "mention": result = elem.literal
|
of "mention": result = fmt("<span style=\"color: #000000;\">{self.mention(elem.literal)}</span> ")
|
||||||
|
|
||||||
# See render-block in status-react/src/status_im/ui/screens/chat/message/message.cljs
|
# 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
|
# TODO: find out how to extract the css styles
|
||||||
for pMsg in message.parsedText:
|
for pMsg in message.parsedText:
|
||||||
case pMsg.textType:
|
case pMsg.textType:
|
||||||
of "paragraph":
|
of "paragraph":
|
||||||
result = "<p>"
|
result = "<p>"
|
||||||
for children in pMsg.children:
|
for children in pMsg.children:
|
||||||
result = result & renderInline(children)
|
result = result & self.renderInline(children)
|
||||||
result = result & "</p>"
|
result = result & "</p>"
|
||||||
of "blockquote":
|
of "blockquote":
|
||||||
# TODO: extract this from the theme somehow
|
# TODO: extract this from the theme somehow
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import NimQml, Tables
|
import NimQml, Tables
|
||||||
|
import ../../../status/status
|
||||||
|
import ../../../status/accounts
|
||||||
import ../../../status/chat
|
import ../../../status/chat
|
||||||
import ../../../status/chat/[message,stickers]
|
import ../../../status/chat/[message,stickers]
|
||||||
import ../../../status/profile/profile
|
import ../../../status/profile/profile
|
||||||
import ../../../status/ens
|
import ../../../status/ens
|
||||||
import strformat
|
import strformat
|
||||||
include message_format
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ChatMessageRoles {.pure.} = enum
|
ChatMessageRoles {.pure.} = enum
|
||||||
@ -25,6 +26,7 @@ QtObject:
|
|||||||
type
|
type
|
||||||
ChatMessageList* = ref object of QAbstractListModel
|
ChatMessageList* = ref object of QAbstractListModel
|
||||||
messages*: seq[Message]
|
messages*: seq[Message]
|
||||||
|
status: Status
|
||||||
|
|
||||||
proc delete(self: ChatMessageList) =
|
proc delete(self: ChatMessageList) =
|
||||||
self.messages = @[]
|
self.messages = @[]
|
||||||
@ -33,14 +35,17 @@ QtObject:
|
|||||||
proc setup(self: ChatMessageList) =
|
proc setup(self: ChatMessageList) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
|
||||||
|
include message_format
|
||||||
|
|
||||||
proc chatIdentifier(self: ChatMessageList, chatId:string): Message =
|
proc chatIdentifier(self: ChatMessageList, chatId:string): Message =
|
||||||
result = Message()
|
result = Message()
|
||||||
result.contentType = ContentType.ChatIdentifier;
|
result.contentType = ContentType.ChatIdentifier;
|
||||||
result.chatId = chatId
|
result.chatId = chatId
|
||||||
|
|
||||||
proc newChatMessageList*(chatId: string): ChatMessageList =
|
proc newChatMessageList*(chatId: string, status: Status): ChatMessageList =
|
||||||
new(result, delete)
|
new(result, delete)
|
||||||
result.messages = @[result.chatIdentifier(chatId)]
|
result.messages = @[result.chatIdentifier(chatId)]
|
||||||
|
result.status = status
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
||||||
@ -55,7 +60,7 @@ QtObject:
|
|||||||
let chatMessageRole = role.ChatMessageRoles
|
let chatMessageRole = role.ChatMessageRoles
|
||||||
case chatMessageRole:
|
case chatMessageRole:
|
||||||
of ChatMessageRoles.UserName: result = newQVariant(message.alias)
|
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.Timestamp: result = newQVariant(message.timestamp)
|
||||||
of ChatMessageRoles.Clock: result = newQVariant($message.clock)
|
of ChatMessageRoles.Clock: result = newQVariant($message.clock)
|
||||||
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import eventemitter, options
|
import eventemitter, options
|
||||||
import libstatus/accounts as status_accounts
|
import libstatus/accounts as status_accounts
|
||||||
import libstatus/types
|
import libstatus/types
|
||||||
|
import libstatus/utils
|
||||||
|
|
||||||
type
|
type
|
||||||
AccountModel* = ref object
|
AccountModel* = ref object
|
||||||
@ -44,3 +45,6 @@ proc importMnemonic*(self: AccountModel, mnemonic: string): GeneratedAccount =
|
|||||||
proc reset*(self: AccountModel) =
|
proc reset*(self: AccountModel) =
|
||||||
self.nodeAccounts = @[]
|
self.nodeAccounts = @[]
|
||||||
self.generatedAddresses = @[]
|
self.generatedAddresses = @[]
|
||||||
|
|
||||||
|
proc generateAlias*(publicKey: string): string =
|
||||||
|
result = status_accounts.generateAlias(publicKey)
|
||||||
|
@ -151,6 +151,7 @@ Item {
|
|||||||
width: parent.width - 120
|
width: parent.width - 120
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
textFormat: Text.RichText
|
||||||
}
|
}
|
||||||
|
|
||||||
// Messages
|
// Messages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user