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