mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-02 17:54:01 +00:00
parent
8a7d6d3f7e
commit
1c2a7b0569
@ -11,6 +11,7 @@ proc handleChatEvents(self: ChatController) =
|
||||
self.status.events.on("contactUpdate") do(e: Args):
|
||||
var evArgs = ContactUpdateArgs(e)
|
||||
self.view.updateUsernames(evArgs.contacts)
|
||||
self.view.updateChannelForContacts(evArgs.contacts)
|
||||
|
||||
self.status.events.on("chatUpdate") do(e: Args):
|
||||
var evArgs = ChatUpdateArgs(e)
|
||||
|
@ -402,6 +402,20 @@ QtObject:
|
||||
for k in self.messageList.keys:
|
||||
self.messageList[k].updateUsernames(contacts)
|
||||
|
||||
proc updateChannelForContacts*(self: ChatsView, contacts: seq[Profile]) =
|
||||
for contact in contacts:
|
||||
let channel = self.chats.getChannelById(contact.id)
|
||||
if not channel.isNil:
|
||||
if contact.localNickname == "":
|
||||
channel.name = contact.username
|
||||
else:
|
||||
channel.name = contact.localNickname
|
||||
self.chats.updateChat(channel, false)
|
||||
if (self.activeChannel.id == channel.id):
|
||||
self.activeChannel.setChatItem(channel)
|
||||
self.activeChannelChanged()
|
||||
|
||||
|
||||
proc markMessageAsSent*(self:ChatsView, chat: string, messageId: string) =
|
||||
self.messageList[chat].markMessageAsSent(messageId)
|
||||
|
||||
|
@ -7,6 +7,7 @@ import libstatus/types
|
||||
import stickers
|
||||
|
||||
import profile/profile
|
||||
import contacts
|
||||
import chat/[chat, message]
|
||||
import signals/messages
|
||||
import ens
|
||||
@ -114,6 +115,10 @@ proc join*(self: ChatModel, chatId: string, chatType: ChatType) =
|
||||
|
||||
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||
|
||||
proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
|
||||
for c in contacts:
|
||||
self.contacts[c.id] = c
|
||||
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
|
||||
|
||||
proc init*(self: ChatModel) =
|
||||
let chatList = status_chat.loadChats()
|
||||
@ -152,6 +157,10 @@ proc init*(self: ChatModel) =
|
||||
self.events.once("mailserverAvailable") do(a: Args):
|
||||
self.events.emit("mailserverTopics", TopicArgs(topics: topics));
|
||||
|
||||
self.events.on("contactUpdate") do(a: Args):
|
||||
var evArgs = ContactUpdateArgs(a)
|
||||
self.updateContacts(evArgs.contacts)
|
||||
|
||||
proc leave*(self: ChatModel, chatId: string) =
|
||||
self.removeChatFilters(chatId)
|
||||
|
||||
@ -266,11 +275,6 @@ proc getUserName*(self: ChatModel, id: string, defaultUserName: string):string =
|
||||
else:
|
||||
return defaultUserName
|
||||
|
||||
proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
|
||||
for c in contacts:
|
||||
self.contacts[c.id] = c
|
||||
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
|
||||
|
||||
proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) =
|
||||
var response = parseJson(status_chat.createGroup(groupName, pubKeys))
|
||||
var (chats, messages) = formatChatUpdate(response)
|
||||
|
@ -43,7 +43,9 @@ proc getContacts*(self: ContactModel): seq[Profile] =
|
||||
|
||||
proc addContact*(self: ContactModel, id: string, localNickname: string): string =
|
||||
let contact = self.getContactByID(id)
|
||||
contact.systemTags.add(":contact/added")
|
||||
let updating = contact.systemTags.contains(":contact/added")
|
||||
if not updating:
|
||||
contact.systemTags.add(":contact/added")
|
||||
let nickname =
|
||||
if (localNickname == ""):
|
||||
contact.localNickname
|
||||
@ -53,6 +55,21 @@ proc addContact*(self: ContactModel, id: string, localNickname: string): string
|
||||
localNickname
|
||||
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, contact.systemTags, nickname)
|
||||
self.events.emit("contactAdded", Args())
|
||||
if updating:
|
||||
let profile = Profile(
|
||||
id: contact.id,
|
||||
username: contact.alias,
|
||||
identicon: contact.identicon,
|
||||
alias: contact.alias,
|
||||
ensName: contact.ensName,
|
||||
ensVerified: contact.ensVerified,
|
||||
ensVerifiedAt: contact.ensVerifiedAt,
|
||||
appearance: 0,
|
||||
ensVerificationRetries: contact.ensVerificationRetries,
|
||||
systemTags: contact.systemTags,
|
||||
localNickname: nickname
|
||||
)
|
||||
self.events.emit("contactUpdate", ContactUpdateArgs(contacts: @[profile]))
|
||||
|
||||
proc addContact*(self: ContactModel, id: string): string =
|
||||
result = self.addContact(id, "")
|
||||
|
Loading…
x
Reference in New Issue
Block a user