fix(@desktop/chat): ensure replacement of mentions with pubkey works in communities
There were two issues why mentions didn't work in communities: 1. The function that replaces mentions with pubkey looked in the wrong place 2. The same function always prepented `userName` with `@` which isn't always necessary This commit fix this by ensuring the replacement function looks in the community memberlist instead of a messageList and also by checking if a `userName` already starts with a `@` and only prepends it if not. Fixes #3492
This commit is contained in:
parent
990e807008
commit
1bca5ee174
|
@ -1,6 +1,7 @@
|
|||
import NimQml, Tables
|
||||
import status/[chat/chat, ens, status, settings]
|
||||
import status/types/[setting, status_update]
|
||||
import user_list
|
||||
|
||||
type
|
||||
CommunityMembersRoles {.pure.} = enum
|
||||
|
@ -100,6 +101,11 @@ QtObject:
|
|||
if self.community.memberStatus.hasKey(pk):
|
||||
result = self.community.memberStatus[pk].statusType.int == StatusUpdateType.Online.int
|
||||
|
||||
proc getUserFromPubKey*(self: CommunityMembersView, pk: string): User =
|
||||
let alias = self.alias(pk)
|
||||
let userName = self.userName(pk, alias)
|
||||
result = User(alias: alias, userName: userName)
|
||||
|
||||
proc sortKey(self: CommunityMembersView, pk: string): string =
|
||||
let name = self.userName(pk, self.alias(pk))
|
||||
if self.isOnline(pk):
|
||||
|
|
|
@ -9,7 +9,7 @@ import ../../../app_service/[main]
|
|||
import ../../../app_service/tasks/[qt, threadpool]
|
||||
import ../../../app_service/tasks/marathon/mailserver/worker
|
||||
|
||||
import communities, chat_item, channels_list, communities, message_list, channel, message_item
|
||||
import communities, chat_item, channels_list, communities, community_list, user_list, community_members_list, message_list, channel, message_item
|
||||
|
||||
logScope:
|
||||
topics = "messages-view"
|
||||
|
@ -76,8 +76,22 @@ QtObject:
|
|||
let nameMentions = findAll(message, namePattern)
|
||||
var updatedMessage = message
|
||||
|
||||
for publicKey in self.messageList[self.channelView.activeChannel.id].userList.users:
|
||||
let user = self.messageList[self.channelView.activeChannel.id].userList.userDetails[publicKey]
|
||||
var userList = self.messageList[self.channelView.activeChannel.id].userList.users
|
||||
|
||||
if self.communities.activeCommunity.active:
|
||||
userList = self.communities.activeCommunity.members.community.members
|
||||
|
||||
for publicKey in userList:
|
||||
|
||||
var user = if self.communities.activeCommunity.active:
|
||||
self.communities.activeCommunity.members.getUserFromPubKey(publicKey)
|
||||
else:
|
||||
self.messageList[self.channelView.activeChannel.id].userList.userDetails[publicKey]
|
||||
|
||||
let userName = if user.userName.startsWith('@'):
|
||||
user.userName
|
||||
else:
|
||||
"@" & user.userName
|
||||
|
||||
for mention in aliasMentions:
|
||||
if "@" & user.alias.toLowerAscii != mention.toLowerAscii:
|
||||
|
@ -86,13 +100,13 @@ QtObject:
|
|||
updatedMessage = updatedMessage.replaceWord(mention, '@' & publicKey)
|
||||
|
||||
for mention in ensMentions:
|
||||
if "@" & user.userName.toLowerAscii != mention.toLowerAscii:
|
||||
if userName.toLowerAscii != mention.toLowerAscii:
|
||||
continue
|
||||
|
||||
updatedMessage = updatedMessage.replaceWord(mention, '@' & publicKey)
|
||||
|
||||
for mention in nameMentions:
|
||||
if "@" & user.userName.split(".")[0].toLowerAscii != mention.toLowerAscii:
|
||||
if userName.split(".")[0].toLowerAscii != mention.toLowerAscii:
|
||||
continue
|
||||
|
||||
updatedMessage = updatedMessage.replaceWord(mention, '@' & publicKey)
|
||||
|
@ -490,4 +504,4 @@ QtObject:
|
|||
"alias": message.alias, "from": message.fromAuthor
|
||||
})
|
||||
|
||||
writeFile(url_toLocalFile(filePath), $messages)
|
||||
writeFile(url_toLocalFile(filePath), $messages)
|
||||
|
|
|
@ -17,7 +17,7 @@ type
|
|||
LocalName = UserRole + 5
|
||||
Identicon = UserRole + 6
|
||||
|
||||
User = object
|
||||
User* = object
|
||||
username*: string
|
||||
alias*: string
|
||||
localName: string
|
||||
|
|
Loading…
Reference in New Issue