chore: autoremove chat groups

This commit is contained in:
Richard Ramos 2021-04-05 13:47:17 -04:00 committed by Jonathan Rainville
parent 31f85787a6
commit 55ecb50f1b
1 changed files with 20 additions and 0 deletions

View File

@ -153,12 +153,32 @@ proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
self.contacts[c.id] = c self.contacts[c.id] = c
self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts)) self.events.emit("chatUpdate", ChatUpdateArgs(contacts: contacts))
proc deleteSpamGroupChats(self: ChatModel, chats: seq[Chat], contacts: seq[Profile]) =
for chat in chats:
if chat.chatType == ChatType.PrivateGroupChat:
var isContact = false
var joined = false
for member in chat.members:
if member.id == self.publicKey and member.joined:
joined = true
if member.admin and member.joined:
for contact in contacts:
if contact.address == member.id:
isContact = true
if not isContact and not joined:
discard status_chat.leaveGroupChat(chat.id)
status_chat.deactivateChat(chat)
proc init*(self: ChatModel, pubKey: string) = proc init*(self: ChatModel, pubKey: string) =
self.publicKey = pubKey self.publicKey = pubKey
var chatList = status_chat.loadChats() var chatList = status_chat.loadChats()
var contacts = getAddedContacts() var contacts = getAddedContacts()
self.deleteSpamGroupChats(chatList, contacts)
let profileUpdatesChatIds = chatList.filter(c => c.chatType == ChatType.Profile).map(c => c.id) let profileUpdatesChatIds = chatList.filter(c => c.chatType == ChatType.Profile).map(c => c.id)
if chatList.filter(c => c.chatType == ChatType.Timeline).len == 0: if chatList.filter(c => c.chatType == ChatType.Timeline).len == 0: