feat: Replace pubkeys by alias/ens in group system message

This commit is contained in:
Richard Ramos 2020-06-24 14:52:49 -04:00 committed by Iuri Matias
parent 21af287654
commit e8858f25ba
5 changed files with 23 additions and 8 deletions

View File

@ -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.}

View File

@ -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("<span style=\"background-color: #1a356b; color: #FFFFFF\">{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 "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
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 = "<p>"
for children in pMsg.children:
result = result & renderInline(children)
result = result & self.renderInline(children)
result = result & "</p>"
of "blockquote":
# TODO: extract this from the theme somehow

View File

@ -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)

View File

@ -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)

View File

@ -151,6 +151,7 @@ Item {
width: parent.width - 120
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
textFormat: Text.RichText
}
// Messages