refactor(user-list): implement getMembers to populate user list
Fixes #5122
This commit is contained in:
parent
d054ea58f2
commit
e1b9332ab3
|
@ -132,6 +132,12 @@ proc getChatMemberInfo*(self: Controller, id: string): (bool, bool) =
|
|||
|
||||
return (false, false)
|
||||
|
||||
proc getChatMembers*(self: Controller): seq[ChatMember] =
|
||||
var communityId = ""
|
||||
if (self.belongsToCommunity):
|
||||
communityId = self.sectionId
|
||||
return self.chatService.getMembers(communityId, self.chatId)
|
||||
|
||||
proc getMembersPublicKeys*(self: Controller): seq[string] =
|
||||
if(self.belongsToCommunity):
|
||||
let communityDto = self.communityService.getCommunityById(self.sectionId)
|
||||
|
|
|
@ -49,37 +49,21 @@ method isLoaded*(self: Module): bool =
|
|||
return self.moduleLoaded
|
||||
|
||||
method viewDidLoad*(self: Module) =
|
||||
# add me as the first user to the list
|
||||
let (admin, joined) = self.controller.getChatMemberInfo(singletonInstance.userProfile.getPubKey())
|
||||
let loggedInUserDisplayName = singletonInstance.userProfile.getName() & " (You)"
|
||||
self.view.model().addItem(initItem(
|
||||
singletonInstance.userProfile.getPubKey(),
|
||||
loggedInUserDisplayName,
|
||||
singletonInstance.userProfile.getEnsName(),
|
||||
localNickname = "",
|
||||
alias = singletonInstance.userProfile.getUsername(),
|
||||
OnlineStatus.Online,
|
||||
singletonInstance.userProfile.getIcon(),
|
||||
singletonInstance.userProfile.getIdenticon(),
|
||||
singletonInstance.userProfile.getIsIdenticon(),
|
||||
isAdded = true,
|
||||
admin,
|
||||
joined,
|
||||
))
|
||||
|
||||
# add other memebers
|
||||
let publicKeys = self.controller.getMembersPublicKeys()
|
||||
for publicKey in publicKeys:
|
||||
if (publicKey == singletonInstance.userProfile.getPubKey()):
|
||||
continue
|
||||
|
||||
let (admin, joined) = self.controller.getChatMemberInfo(publicKey)
|
||||
let contactDetails = self.controller.getContactDetails(publicKey)
|
||||
let statusUpdateDto = self.controller.getStatusForContact(publicKey)
|
||||
let status = statusUpdateDto.statusType.int.OnlineStatus
|
||||
let members = self.controller.getChatMembers()
|
||||
for member in members:
|
||||
let isMe = member.id == singletonInstance.userProfile.getPubKey()
|
||||
let contactDetails = self.controller.getContactDetails(member.id)
|
||||
var status = OnlineStatus.Online
|
||||
if (not isMe):
|
||||
let statusUpdateDto = self.controller.getStatusForContact(member.id)
|
||||
status = statusUpdateDto.statusType.int.OnlineStatus
|
||||
|
||||
self.view.model().addItem(initItem(
|
||||
publicKey,
|
||||
contactDetails.displayName,
|
||||
member.id,
|
||||
if (isMe):
|
||||
contactDetails.displayName & " (You)"
|
||||
else:
|
||||
contactDetails.displayName,
|
||||
contactDetails.details.name,
|
||||
contactDetails.details.localNickname,
|
||||
contactDetails.details.alias,
|
||||
|
@ -88,8 +72,8 @@ method viewDidLoad*(self: Module) =
|
|||
contactDetails.details.identicon,
|
||||
contactDetails.isidenticon,
|
||||
contactDetails.details.added,
|
||||
admin,
|
||||
joined
|
||||
member.admin,
|
||||
member.joined
|
||||
))
|
||||
|
||||
self.moduleLoaded = true
|
||||
|
|
|
@ -77,7 +77,7 @@ proc `$`*(self: ChatDto): string =
|
|||
highlight: {self.highlight}
|
||||
)"""
|
||||
|
||||
proc toChatMember(jsonObj: JsonNode): ChatMember =
|
||||
proc toChatMember*(jsonObj: JsonNode): ChatMember =
|
||||
result = ChatMember()
|
||||
discard jsonObj.getProp("id", result.id)
|
||||
discard jsonObj.getProp("admin", result.admin)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, Tables, json, sequtils, strformat, chronicles, os
|
||||
import NimQml, Tables, json, sequtils, strformat, chronicles, os, std/algorithm, strutils
|
||||
|
||||
import ./dto/chat as chat_dto
|
||||
import ../message/dto/message as message_dto
|
||||
|
@ -471,3 +471,19 @@ QtObject:
|
|||
except Exception as e:
|
||||
error "error while creating group chat", msg = e.msg
|
||||
|
||||
proc getMembers*(self: Service, communityID, chatId: string): seq[ChatMember] =
|
||||
try:
|
||||
var realChatId = chatId.replace(communityID, "")
|
||||
let response = status_chat.getMembers(communityID, realChatId)
|
||||
let myPubkey = singletonInstance.userProfile.getPubKey()
|
||||
result = @[]
|
||||
for (id, memberObj) in response.result.pairs:
|
||||
var member = toChatMember(memberObj)
|
||||
member.id = id
|
||||
# Make yourself as the first result
|
||||
if (id == myPubkey):
|
||||
result.insert(member)
|
||||
else:
|
||||
result.add(member)
|
||||
except Exception as e:
|
||||
error "error while getting members", msg = e.msg, communityID, chatId
|
||||
|
|
|
@ -134,3 +134,6 @@ proc createGroupChatFromInvitation*(groupName: string, chatId: string, adminPK:
|
|||
|
||||
proc getLinkPreviewData*(link: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("getLinkPreviewData".prefix, %* [link])
|
||||
|
||||
proc getMembers*(communityId, chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("chat_getMembers", %* [communityId, chatId])
|
||||
|
|
Loading…
Reference in New Issue