fix: fixes the ordering problem on deleting a channel
Fixes #2035 Also goes back to your first channel when deleting the current channel
This commit is contained in:
parent
41554a18ac
commit
7bb8a968c9
|
@ -91,6 +91,7 @@ QtObject:
|
||||||
|
|
||||||
result.setup()
|
result.setup()
|
||||||
|
|
||||||
|
proc getMessageListIndexById(self: ChatsView, id: string): int
|
||||||
|
|
||||||
proc getChannel*(self: ChatsView, index: int): Chat =
|
proc getChannel*(self: ChatsView, index: int): Chat =
|
||||||
if (self.communities.activeCommunity.active):
|
if (self.communities.activeCommunity.active):
|
||||||
|
@ -289,7 +290,11 @@ QtObject:
|
||||||
notify = activeChannelChanged
|
notify = activeChannelChanged
|
||||||
|
|
||||||
proc setActiveChannel*(self: ChatsView, channel: string) {.slot.} =
|
proc setActiveChannel*(self: ChatsView, channel: string) {.slot.} =
|
||||||
if(channel == ""): return
|
if (self.activeChannel.id == "" and channel == backToFirstChat):
|
||||||
|
self.setActiveChannelByIndex(0)
|
||||||
|
return
|
||||||
|
|
||||||
|
if(channel == "" or channel == backToFirstChat): return
|
||||||
let selectedChannel = self.getChannelById(channel)
|
let selectedChannel = self.getChannelById(channel)
|
||||||
|
|
||||||
self.activeChannel.setChatItem(selectedChannel)
|
self.activeChannel.setChatItem(selectedChannel)
|
||||||
|
@ -561,6 +566,8 @@ QtObject:
|
||||||
if (self.chats.chats.len == 0): return
|
if (self.chats.chats.len == 0): return
|
||||||
let selectedChannel = self.getChannel(channelIndex)
|
let selectedChannel = self.getChannel(channelIndex)
|
||||||
if (selectedChannel == nil): return
|
if (selectedChannel == nil): return
|
||||||
|
if (self.activeChannel.id == selectedChannel.id):
|
||||||
|
self.activeChannel.chatItem = nil
|
||||||
self.status.chat.leave(selectedChannel.id)
|
self.status.chat.leave(selectedChannel.id)
|
||||||
self.status.mailservers.deleteMailserverTopic(selectedChannel.id)
|
self.status.mailservers.deleteMailserverTopic(selectedChannel.id)
|
||||||
|
|
||||||
|
@ -571,8 +578,11 @@ QtObject:
|
||||||
proc removeChat*(self: ChatsView, chatId: string) =
|
proc removeChat*(self: ChatsView, chatId: string) =
|
||||||
discard self.chats.removeChatItemFromList(chatId)
|
discard self.chats.removeChatItemFromList(chatId)
|
||||||
if (self.messageList.hasKey(chatId)):
|
if (self.messageList.hasKey(chatId)):
|
||||||
|
let index = self.getMessageListIndexById(chatId)
|
||||||
|
self.beginRemoveRows(newQModelIndex(), index, index)
|
||||||
self.messageList[chatId].delete
|
self.messageList[chatId].delete
|
||||||
self.messageList.del(chatId)
|
self.messageList.del(chatId)
|
||||||
|
self.endRemoveRows()
|
||||||
|
|
||||||
proc toggleReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
|
proc toggleReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
|
||||||
if self.activeChannel.id == status_utils.getTimelineChatId():
|
if self.activeChannel.id == status_utils.getTimelineChatId():
|
||||||
|
@ -738,9 +748,16 @@ QtObject:
|
||||||
ChatViewRoles.MessageList.int:"messages"
|
ChatViewRoles.MessageList.int:"messages"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc getMessageListIndex(self: ChatsView):int {.slot.} =
|
proc getMessageListIndex(self: ChatsView): int {.slot.} =
|
||||||
var idx = -1
|
var idx = -1
|
||||||
for msg in toSeq(self.messageList.values):
|
for msg in toSeq(self.messageList.values):
|
||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
if(self.activeChannel.id == msg.id): return idx
|
if(self.activeChannel.id == msg.id): return idx
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
proc getMessageListIndexById(self: ChatsView, id: string): int {.slot.} =
|
||||||
|
var idx = -1
|
||||||
|
for msg in toSeq(self.messageList.values):
|
||||||
|
idx = idx + 1
|
||||||
|
if(id == msg.id): return idx
|
||||||
|
return idx
|
||||||
|
|
|
@ -18,6 +18,8 @@ import ens
|
||||||
logScope:
|
logScope:
|
||||||
topics = "chat-model"
|
topics = "chat-model"
|
||||||
|
|
||||||
|
const backToFirstChat* = "__goBackToFirstChat"
|
||||||
|
|
||||||
type
|
type
|
||||||
ChatUpdateArgs* = ref object of Args
|
ChatUpdateArgs* = ref object of Args
|
||||||
chats*: seq[Chat]
|
chats*: seq[Chat]
|
||||||
|
@ -215,7 +217,7 @@ proc leave*(self: ChatModel, chatId: string) =
|
||||||
self.channels.del(chatId)
|
self.channels.del(chatId)
|
||||||
discard status_chat.clearChatHistory(chatId)
|
discard status_chat.clearChatHistory(chatId)
|
||||||
self.events.emit("channelLeft", ChatIdArg(chatId: chatId))
|
self.events.emit("channelLeft", ChatIdArg(chatId: chatId))
|
||||||
self.events.emit("activeChannelChanged", ChatIdArg(chatId: ""))
|
self.events.emit("activeChannelChanged", ChatIdArg(chatId: backToFirstChat))
|
||||||
|
|
||||||
proc clearHistory*(self: ChatModel, chatId: string) =
|
proc clearHistory*(self: ChatModel, chatId: string) =
|
||||||
discard status_chat.clearChatHistory(chatId)
|
discard status_chat.clearChatHistory(chatId)
|
||||||
|
|
Loading…
Reference in New Issue