fix: show ens usernames when creating a 1:1 chat
This commit is contained in:
parent
9aedc5cd1c
commit
a5b9511a55
|
@ -256,7 +256,7 @@ QtObject:
|
|||
let selectedChannel = self.chats.getChannel(index)
|
||||
if self.activeChannel.id == selectedChannel.id: return
|
||||
|
||||
if selectedChannel.chatType.isOneToOne:
|
||||
if selectedChannel.chatType.isOneToOne and selectedChannel.id == selectedChannel.name:
|
||||
selectedChannel.name = self.userNameOrAlias(selectedChannel.id)
|
||||
|
||||
self.activeChannel.setChatItem(selectedChannel)
|
||||
|
@ -418,6 +418,10 @@ QtObject:
|
|||
let channel = self.chats.getChannelById(contact.id)
|
||||
if not channel.isNil:
|
||||
if contact.localNickname == "":
|
||||
if channel.name == "" or channel.name == channel.id:
|
||||
if channel.ensName != "":
|
||||
channel.name = channel.ensName
|
||||
else:
|
||||
channel.name = contact.username
|
||||
else:
|
||||
channel.name = contact.localNickname
|
||||
|
@ -461,6 +465,10 @@ QtObject:
|
|||
self.status.chat.join(channel, ChatType(chatTypeInt))
|
||||
self.setActiveChannel(channel)
|
||||
|
||||
proc joinChatWithENS*(self: ChatsView, channel: string, ensName: string): int {.slot.} =
|
||||
self.status.chat.join(channel, ChatType.OneToOne, ensName=status_ens.addDomain(ensName))
|
||||
self.setActiveChannel(channel)
|
||||
|
||||
proc chatGroupJoined(self: ChatsView, channel: string) {.signal.}
|
||||
|
||||
proc joinGroup*(self: ChatsView) {.slot.} =
|
||||
|
|
|
@ -37,11 +37,17 @@ QtObject:
|
|||
result.status = status
|
||||
result.setup()
|
||||
|
||||
proc userNameOrAlias(self: ChannelsList, pubKey: string): string {.slot.} =
|
||||
proc userNameOrAlias(self: ChannelsList, pubKey: string): string =
|
||||
if self.status.chat.contacts.hasKey(pubKey):
|
||||
return ens.userNameOrAlias(self.status.chat.contacts[pubKey])
|
||||
generateAlias(pubKey)
|
||||
|
||||
proc chatName(self: ChannelsList, chatItem: Chat): string =
|
||||
if not chatItem.chatType.isOneToOne: return chatItem.name
|
||||
if chatItem.ensName != "":
|
||||
return "@" & userName(chatItem.ensName).userName(true)
|
||||
return self.userNameOrAlias(chatItem.id)
|
||||
|
||||
method rowCount*(self: ChannelsList, index: QModelIndex = nil): int = self.chats.len
|
||||
|
||||
proc renderBlock(self: ChannelsList, message: Message): string
|
||||
|
@ -54,13 +60,9 @@ QtObject:
|
|||
|
||||
let chatItem = self.chats[index.row]
|
||||
|
||||
var name = chatItem.name
|
||||
if chatItem.chatType.isOneToOne:
|
||||
name = self.userNameOrAlias(chatItem.id)
|
||||
|
||||
let chatItemRole = role.ChannelsRoles
|
||||
case chatItemRole:
|
||||
of ChannelsRoles.Name: result = newQVariant(name)
|
||||
of ChannelsRoles.Name: result = newQVariant(self.chatName(chatItem))
|
||||
of ChannelsRoles.Timestamp: result = newQVariant($chatItem.timestamp)
|
||||
of ChannelsRoles.LastMessage: result = newQVariant(self.renderBlock(chatItem.lastMessage))
|
||||
of ChannelsRoles.ContentType: result = newQVariant(chatItem.lastMessage.contentType.int)
|
||||
|
|
|
@ -44,10 +44,17 @@ QtObject:
|
|||
|
||||
proc name*(self: ChatItemView): string {.slot.} =
|
||||
if self.chatItem != nil and self.chatItem.chatType.isOneToOne:
|
||||
if self.chatItem.name == self.chatItem.id:
|
||||
result = self.userNameOrAlias(self.chatItem.id)
|
||||
else:
|
||||
if self.chatItem.ensName != "":
|
||||
result = "@" & userName(self.chatItem.ensName).userName(true)
|
||||
else:
|
||||
result = self.chatItem.name
|
||||
else:
|
||||
result = ?.self.chatItem.name
|
||||
|
||||
|
||||
QtProperty[string] name:
|
||||
read = name
|
||||
notify = contactsUpdated
|
||||
|
|
|
@ -89,12 +89,16 @@ proc hasChannel*(self: ChatModel, chatId: string): bool =
|
|||
proc getActiveChannel*(self: ChatModel): string =
|
||||
if (self.channels.len == 0): "" else: toSeq(self.channels.values)[self.channels.len - 1].id
|
||||
|
||||
proc join*(self: ChatModel, chatId: string, chatType: ChatType) =
|
||||
proc join*(self: ChatModel, chatId: string, chatType: ChatType, ensName: string = "") =
|
||||
if self.hasChannel(chatId): return
|
||||
|
||||
var chat = newChat(chatId, ChatType(chatType))
|
||||
self.channels[chat.id] = chat
|
||||
status_chat.saveChat(chatId, chatType.isOneToOne, true, chat.color)
|
||||
status_chat.saveChat(chatId, chatType.isOneToOne, true, chat.color, ensName)
|
||||
if ensName != "":
|
||||
chat.name = ensName
|
||||
chat.ensName = ensName
|
||||
|
||||
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chat)])
|
||||
|
||||
var topics:seq[MailserverTopic] = @[]
|
||||
|
@ -124,9 +128,15 @@ proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
|
|||
proc init*(self: ChatModel) =
|
||||
let chatList = status_chat.loadChats()
|
||||
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
echo $chatList
|
||||
|
||||
var filters:seq[JsonNode] = @[]
|
||||
for chat in chatList:
|
||||
if self.hasChannel(chat.id): continue
|
||||
echo ",,,,,,,,,", chat.name
|
||||
if self.hasChannel(chat.id):
|
||||
echo "Has channel"
|
||||
continue
|
||||
filters.add status_chat.buildFilter(chat)
|
||||
self.channels[chat.id] = chat
|
||||
self.events.emit("channelLoaded", ChannelArgs(chat: chat))
|
||||
|
|
|
@ -68,6 +68,7 @@ type Chat* = ref object
|
|||
membershipUpdateEvents*: seq[ChatMembershipEvent]
|
||||
hasMentions*: bool
|
||||
muted*: bool
|
||||
ensName*: string
|
||||
|
||||
proc `$`*(self: Chat): string =
|
||||
result = fmt"Chat(id:{self.id}, name:{self.name}, active:{self.isActive}, type:{self.chatType})"
|
||||
|
@ -83,7 +84,7 @@ proc toJsonNode*(self: Chat): JsonNode =
|
|||
"lastMessage": nil,
|
||||
"members": self.members.toJsonNode,
|
||||
"membershipUpdateEvents": self.membershipUpdateEvents.toJsonNode,
|
||||
"name": self.name,
|
||||
"name": (if self.ensName != "": self.ensName else: self.name),
|
||||
"timestamp": self.timestamp,
|
||||
"unviewedMessagesCount": self.unviewedMessagesCount
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ proc userName*(ensName: string, removeSuffix: bool = false): string =
|
|||
else:
|
||||
result = ensName
|
||||
else:
|
||||
if ensName.endsWith(".eth") and removeSuffix:
|
||||
return ensName.split(".")[0]
|
||||
result = ensName
|
||||
|
||||
proc addDomain*(username: string): string =
|
||||
|
|
|
@ -18,14 +18,14 @@ proc removeFilters*(chatId: string, filterId: string) =
|
|||
[{ "ChatID": chatId, "FilterID": filterId }]
|
||||
])
|
||||
|
||||
proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, color: string) =
|
||||
proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, color: string, ensName: string = "") =
|
||||
# TODO: ideally status-go/stimbus should handle some of these fields instead of having the client
|
||||
# send them: lastMessage, unviewedMEssagesCount, timestamp, lastClockValue, name?
|
||||
discard callPrivateRPC("saveChat".prefix, %* [
|
||||
{
|
||||
"lastClockValue": 0, # TODO:
|
||||
"color": color,
|
||||
"name": chatId,
|
||||
"name": (if ensName != "": ensName else: chatId),
|
||||
"lastMessage": nil, # TODO:
|
||||
"active": active,
|
||||
"id": chatId,
|
||||
|
|
|
@ -121,7 +121,8 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
|||
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
|
||||
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
|
||||
hasMentions: false,
|
||||
muted: false
|
||||
muted: false,
|
||||
ensName: ""
|
||||
)
|
||||
|
||||
if jsonChat.hasKey("muted") and jsonChat["muted"].kind != JNull:
|
||||
|
@ -132,6 +133,9 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
|||
|
||||
if result.chatType == ChatType.OneToOne:
|
||||
result.identicon = generateIdenticon(result.id)
|
||||
if result.name.endsWith(".eth"):
|
||||
result.ensName = result.name
|
||||
if result.name == "":
|
||||
result.name = generateAlias(result.id)
|
||||
|
||||
if jsonChat["members"].kind != JNull:
|
||||
|
|
|
@ -48,8 +48,13 @@ ModalPopup {
|
|||
}
|
||||
|
||||
function doJoin() {
|
||||
if (!validate() || pubKey.trim() === "") return;
|
||||
if (!validate() || pubKey.trim() === "" || validationError !== "") return;
|
||||
if(Utils.isChatKey(chatKey.text)){
|
||||
chatsModel.joinChat(pubKey, Constants.chatTypeOneToOne);
|
||||
} else {
|
||||
chatsModel.joinChatWithENS(pubKey, chatKey.text);
|
||||
}
|
||||
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
@ -86,10 +91,14 @@ ModalPopup {
|
|||
//% "User not found"
|
||||
ensUsername.text = qsTrId("user-not-found");
|
||||
pubKey = "";
|
||||
} else {
|
||||
if (profileModel.profile.pubKey === resolvedPubKey) {
|
||||
validationError = qsTr("Can't chat with yourself");
|
||||
} else {
|
||||
ensUsername.text = chatsModel.formatENSUsername(chatKey.text) + " • " + Utils.compactAddress(resolvedPubKey, 4)
|
||||
pubKey = resolvedPubKey;
|
||||
}
|
||||
}
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue