fix: show usernames in group info

This commit is contained in:
Richard Ramos 2020-06-17 21:58:07 -04:00 committed by Iuri Matias
parent b70a29f059
commit 1c564a410d
4 changed files with 20 additions and 14 deletions

View File

@ -33,7 +33,7 @@ QtObject:
new(result, delete) new(result, delete)
result.status = status result.status = status
result.chats = newChannelsList() result.chats = newChannelsList()
result.activeChannel = newChatItemView() result.activeChannel = newChatItemView(status)
result.messageList = initTable[string, ChatMessageList]() result.messageList = initTable[string, ChatMessageList]()
result.setup() result.setup()

View File

@ -1,6 +1,7 @@
import NimQml import NimQml
import std/wrapnils import std/wrapnils
import ../../../status/chat/chat import ../../../status/chat/chat
import ../../../status/status
import chat_members import chat_members
QtObject: QtObject:
@ -14,11 +15,11 @@ QtObject:
proc delete*(self: ChatItemView) = proc delete*(self: ChatItemView) =
self.QObject.delete self.QObject.delete
proc newChatItemView*(): ChatItemView = proc newChatItemView*(status: Status): ChatItemView =
new(result, delete) new(result, delete)
result = ChatItemView() result = ChatItemView()
result.chatItem = nil result.chatItem = nil
result.chatMembers = newChatMembersView() result.chatMembers = newChatMembersView(status)
result.setup result.setup
proc setChatItem*(self: ChatItemView, chatItem: Chat) = proc setChatItem*(self: ChatItemView, chatItem: Chat) =

View File

@ -1,5 +1,8 @@
import NimQml, Tables import NimQml, Tables
import ../../../status/chat/[chat, message] import ../../../status/chat/[chat, message]
import ../../../status/chat as status_chat
import ../../../status/status
import ../../../status/ens
type type
ChatMemberRoles {.pure.} = enum ChatMemberRoles {.pure.} = enum
@ -12,15 +15,17 @@ type
QtObject: QtObject:
type type
ChatMembersView* = ref object of QAbstractListModel ChatMembersView* = ref object of QAbstractListModel
status: Status
members*: seq[ChatMember] members*: seq[ChatMember]
proc setup(self: ChatMembersView) = self.QAbstractListModel.setup proc setup(self: ChatMembersView) = self.QAbstractListModel.setup
proc delete(self: ChatMembersView) = self.QAbstractListModel.delete proc delete(self: ChatMembersView) = self.QAbstractListModel.delete
proc newChatMembersView*(): ChatMembersView = proc newChatMembersView*(status: Status): ChatMembersView =
new(result, delete) new(result, delete)
result.members = @[] result.members = @[]
result.status = status
result.setup() result.setup()
proc setMembers*(self: ChatMembersView, members: seq[ChatMember]) = proc setMembers*(self: ChatMembersView, members: seq[ChatMember]) =
@ -30,6 +35,12 @@ QtObject:
method rowCount(self: ChatMembersView, index: QModelIndex = nil): int = self.members.len method rowCount(self: ChatMembersView, index: QModelIndex = nil): int = self.members.len
proc userName(self: ChatMembersView, id: string, alias: string): string =
if self.status.chat.contacts.hasKey(id):
result = ens.userNameOrAlias(self.status.chat.contacts[id])
else:
result = alias
method data(self: ChatMembersView, index: QModelIndex, role: int): QVariant = method data(self: ChatMembersView, index: QModelIndex, role: int): QVariant =
if not index.isValid: if not index.isValid:
return return
@ -39,7 +50,7 @@ QtObject:
let chatMember = self.members[index.row] let chatMember = self.members[index.row]
let chatMemberRole = role.ChatMemberRoles let chatMemberRole = role.ChatMemberRoles
case chatMemberRole: case chatMemberRole:
of ChatMemberRoles.UserName: result = newQVariant(chatMember.userName) of ChatMemberRoles.UserName: result = newQVariant(self.userName(chatMember.id, chatMember.userName))
of ChatMemberRoles.PubKey: result = newQVariant(chatMember.id) of ChatMemberRoles.PubKey: result = newQVariant(chatMember.id)
of ChatMemberRoles.IsAdmin: result = newQVariant(chatMember.admin) of ChatMemberRoles.IsAdmin: result = newQVariant(chatMember.admin)
of ChatMemberRoles.Joined: result = newQVariant(chatMember.joined) of ChatMemberRoles.Joined: result = newQVariant(chatMember.joined)

View File

@ -30,22 +30,16 @@ QtObject:
method rowCount(self: ContactList, index: QModelIndex = nil): int = method rowCount(self: ContactList, index: QModelIndex = nil): int =
return self.contacts.len return self.contacts.len
proc getUserName(contact: Profile): string =
if(contact.ensName != "" and contact.ensVerified):
result = "@" & ens.userName(contact.ensName, true)
else:
result = contact.alias
proc userName(self: ContactList, pubKey: string, defaultValue: string = ""): string {.slot.} = proc userName(self: ContactList, pubKey: string, defaultValue: string = ""): string {.slot.} =
for contact in self.contacts: for contact in self.contacts:
if(contact.id != pubKey): continue if(contact.id != pubKey): continue
return getUserName(contact) return ens.userNameOrAlias(contact)
return defaultValue return defaultValue
proc rowData(self: ContactList, index: int, column: string): string {.slot.} = proc rowData(self: ContactList, index: int, column: string): string {.slot.} =
let contact = self.contacts[index] let contact = self.contacts[index]
case column: case column:
of "name": result = getUserName(contact) of "name": result = ens.userNameOrAlias(contact)
of "address": result = contact.address of "address": result = contact.address
of "identicon": result = contact.identicon of "identicon": result = contact.identicon
of "pubKey": result = contact.id of "pubKey": result = contact.id
@ -57,7 +51,7 @@ QtObject:
return return
let contact = self.contacts[index.row] let contact = self.contacts[index.row]
case role.ContactRoles: case role.ContactRoles:
of ContactRoles.Name: result = newQVariant(getUserName(contact)) of ContactRoles.Name: result = newQVariant(ens.userNameOrAlias(contact))
of ContactRoles.Address: result = newQVariant(contact.address) of ContactRoles.Address: result = newQVariant(contact.address)
of ContactRoles.Identicon: result = newQVariant(contact.identicon) of ContactRoles.Identicon: result = newQVariant(contact.identicon)
of ContactRoles.PubKey: result = newQVariant(contact.id) of ContactRoles.PubKey: result = newQVariant(contact.id)