From 358f6477355fe21d7061600f620eafa0eec1ffe8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 25 Feb 2021 09:51:43 -0400 Subject: [PATCH] fix: delete mailserver topic on leaving channel --- src/app/chat/view.nim | 4 +++- src/status/libstatus/mailservers.nim | 3 +++ src/status/mailservers.nim | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index c41c351f6f..fafedf850f 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -109,7 +109,7 @@ QtObject: read = getOldestMessageTimestamp notify = oldestMessageTimestampChanged - proc setLastMessageTimestamp(self: ChatsView, force = false) = + proc setLastMessageTimestamp*(self: ChatsView, force = false) = if self.status.chat.lastMessageTimestamps.hasKey(self.activeChannel.id): if force or self.status.chat.lastMessageTimestamps[self.activeChannel.id] <= self.oldestMessageTimestamp: self.oldestMessageTimestamp = self.status.chat.lastMessageTimestamps[self.activeChannel.id] @@ -539,9 +539,11 @@ QtObject: let selectedChannel = self.chats.getChannel(channelIndex) if (selectedChannel == nil): return self.status.chat.leave(selectedChannel.id) + self.status.mailservers.deleteMailserverTopic(selectedChannel.id) proc leaveActiveChat*(self: ChatsView) {.slot.} = self.status.chat.leave(self.activeChannel.id) + self.status.mailservers.deleteMailserverTopic(self.activeChannel.id) proc removeChat*(self: ChatsView, chatId: string) = discard self.chats.removeChatItemFromList(chatId) diff --git a/src/status/libstatus/mailservers.nim b/src/status/libstatus/mailservers.nim index 617f54f510..e669d6cf63 100644 --- a/src/status/libstatus/mailservers.nim +++ b/src/status/libstatus/mailservers.nim @@ -56,3 +56,6 @@ proc addMailserverTopic*(topic: MailserverTopic): string = "chat-ids": topic.chatIds, "last-request": topic.lastRequest }]) + +proc deleteMailserverTopic*(topic: string): string = + return callPrivateRPC("mailservers_deleteMailserverTopic", %*[topic]) diff --git a/src/status/mailservers.nim b/src/status/mailservers.nim index 668ad61795..342efca52b 100644 --- a/src/status/mailservers.nim +++ b/src/status/mailservers.nim @@ -207,6 +207,12 @@ proc getMailserverTopicsByChatId*(self: MailserverModel, chatId: string): seq[Ma proc addMailserverTopic*(self: MailserverModel, topic: MailserverTopic) = discard status_mailservers.addMailserverTopic(topic) +proc deleteMailserverTopic*(self: MailserverModel, chatId: string) = + var topic:MailserverTopic = self.getMailserverTopicsByChatId(chatId)[0] + if(topic.chatIds.len > 1): + discard status_mailservers.addMailserverTopic(topic) + else: + discard status_mailservers.deleteMailserverTopic(topic.topic) proc findNewMailserver(self: MailserverModel) = warn "Finding a new mailserver..."