fix: limit suggestions to member list in communities

Fixes #3021
This commit is contained in:
Richard Ramos 2021-07-22 10:31:18 -04:00 committed by Iuri Matias
parent e097d2bfe7
commit 55a11f016e
2 changed files with 26 additions and 6 deletions

View File

@ -65,6 +65,9 @@ QtObject:
else:
result = self.status.accounts.generateAlias(pk)
proc localNickname(self: CommunityMembersView, pk: string): string =
if self.status.chat.contacts.hasKey(pk):
result = self.status.chat.contacts[pk].localNickname
method data(self: CommunityMembersView, index: QModelIndex, role: int): QVariant =
if not index.isValid:
@ -79,6 +82,17 @@ QtObject:
of CommunityMembersRoles.PubKey: result = newQVariant(communityMemberPubkey)
of CommunityMembersRoles.Identicon: result = newQVariant(self.identicon(communityMemberPubkey))
proc rowData(self: CommunityMembersView, index: int, column: string): string {.slot.} =
if (index >= self.members.len):
return
let communityMemberPubkey = self.members[index]
case column:
of "alias": result = self.alias(communityMemberPubkey)
of "address": result = communityMemberPubkey
of "identicon": result = self.identicon(communityMemberPubkey)
of "localNickname": result = self.localNickname(communityMemberPubkey)
of "ensName": result = self.userName(communityMemberPubkey, self.alias(communityMemberPubkey))
method roleNames(self: CommunityMembersView): Table[int, string] =
{
CommunityMembersRoles.UserName.int:"userName",

View File

@ -83,24 +83,30 @@ Item {
function populateSuggestions() {
chatInput.suggestionsList.clear()
const len = chatsModel.suggestionList.rowCount()
idMap = {}
let isCommunity = chatsModel.communities.activeCommunity.active
let dataSource = isCommunity ? chatsModel.communities.activeCommunity.members : chatsModel.suggestionList
const len = dataSource.rowCount()
for (let i = 0; i < len; i++) {
const contactAddr = chatsModel.suggestionList.rowData(i, "address");
const contactAddr = dataSource.rowData(i, "address");
if(idMap[contactAddr]) continue;
suggestionsObj.push({
alias: chatsModel.suggestionList.rowData(i, "alias"),
ensName: chatsModel.suggestionList.rowData(i, "ensName"),
alias: dataSource.rowData(i, "alias"),
ensName: dataSource.rowData(i, "ensName"),
address: contactAddr,
identicon: getProfileImage(contactAddr, false, false) || chatsModel.suggestionList.rowData(i, "identicon"),
localNickname: chatsModel.suggestionList.rowData(i, "localNickname")
identicon: getProfileImage(contactAddr, false, false) || dataSource.rowData(i, "identicon"),
localNickname: dataSource.rowData(i, "localNickname")
})
chatInput.suggestionsList.append(suggestionsObj[suggestionsObj.length - 1]);
idMap[contactAddr] = true;
}
if (!isCommunity) return;
const len2 = chatsModel.messageView.messageList.rowCount();
for (let f = 0; f < len2; f++) {
addSuggestionFromMessageList(f);