fix: show usernames in group info
This commit is contained in:
parent
b70a29f059
commit
1c564a410d
|
@ -33,7 +33,7 @@ QtObject:
|
|||
new(result, delete)
|
||||
result.status = status
|
||||
result.chats = newChannelsList()
|
||||
result.activeChannel = newChatItemView()
|
||||
result.activeChannel = newChatItemView(status)
|
||||
result.messageList = initTable[string, ChatMessageList]()
|
||||
result.setup()
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import NimQml
|
||||
import std/wrapnils
|
||||
import ../../../status/chat/chat
|
||||
import ../../../status/status
|
||||
import chat_members
|
||||
|
||||
QtObject:
|
||||
|
@ -14,11 +15,11 @@ QtObject:
|
|||
proc delete*(self: ChatItemView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newChatItemView*(): ChatItemView =
|
||||
proc newChatItemView*(status: Status): ChatItemView =
|
||||
new(result, delete)
|
||||
result = ChatItemView()
|
||||
result.chatItem = nil
|
||||
result.chatMembers = newChatMembersView()
|
||||
result.chatMembers = newChatMembersView(status)
|
||||
result.setup
|
||||
|
||||
proc setChatItem*(self: ChatItemView, chatItem: Chat) =
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import NimQml, Tables
|
||||
import ../../../status/chat/[chat, message]
|
||||
import ../../../status/chat as status_chat
|
||||
import ../../../status/status
|
||||
import ../../../status/ens
|
||||
|
||||
type
|
||||
ChatMemberRoles {.pure.} = enum
|
||||
|
@ -12,15 +15,17 @@ type
|
|||
QtObject:
|
||||
type
|
||||
ChatMembersView* = ref object of QAbstractListModel
|
||||
status: Status
|
||||
members*: seq[ChatMember]
|
||||
|
||||
proc setup(self: ChatMembersView) = self.QAbstractListModel.setup
|
||||
|
||||
proc delete(self: ChatMembersView) = self.QAbstractListModel.delete
|
||||
|
||||
proc newChatMembersView*(): ChatMembersView =
|
||||
proc newChatMembersView*(status: Status): ChatMembersView =
|
||||
new(result, delete)
|
||||
result.members = @[]
|
||||
result.status = status
|
||||
result.setup()
|
||||
|
||||
proc setMembers*(self: ChatMembersView, members: seq[ChatMember]) =
|
||||
|
@ -30,6 +35,12 @@ QtObject:
|
|||
|
||||
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 =
|
||||
if not index.isValid:
|
||||
return
|
||||
|
@ -39,7 +50,7 @@ QtObject:
|
|||
let chatMember = self.members[index.row]
|
||||
let chatMemberRole = role.ChatMemberRoles
|
||||
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.IsAdmin: result = newQVariant(chatMember.admin)
|
||||
of ChatMemberRoles.Joined: result = newQVariant(chatMember.joined)
|
||||
|
|
|
@ -30,22 +30,16 @@ QtObject:
|
|||
method rowCount(self: ContactList, index: QModelIndex = nil): int =
|
||||
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.} =
|
||||
for contact in self.contacts:
|
||||
if(contact.id != pubKey): continue
|
||||
return getUserName(contact)
|
||||
return ens.userNameOrAlias(contact)
|
||||
return defaultValue
|
||||
|
||||
proc rowData(self: ContactList, index: int, column: string): string {.slot.} =
|
||||
let contact = self.contacts[index]
|
||||
case column:
|
||||
of "name": result = getUserName(contact)
|
||||
of "name": result = ens.userNameOrAlias(contact)
|
||||
of "address": result = contact.address
|
||||
of "identicon": result = contact.identicon
|
||||
of "pubKey": result = contact.id
|
||||
|
@ -57,7 +51,7 @@ QtObject:
|
|||
return
|
||||
let contact = self.contacts[index.row]
|
||||
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.Identicon: result = newQVariant(contact.identicon)
|
||||
of ContactRoles.PubKey: result = newQVariant(contact.id)
|
||||
|
|
Loading…
Reference in New Issue