fix: ste channels correctly when going back and forth to communities

This commit is contained in:
Jonathan Rainville 2021-02-11 13:13:21 -05:00 committed by Iuri Matias
parent f9817d4f52
commit 807048522a
9 changed files with 28 additions and 19 deletions

View File

@ -58,8 +58,14 @@ proc handleChatEvents(self: ChatController) =
self.view.appReady()
self.status.events.on("communityActiveChanged") do(e:Args):
# TODO set this back to the previous one instead
self.view.setActiveChannelByIndex(0)
var evArgs = CommunityActiveChangedArgs(e)
if (evArgs.active == false):
self.view.restorePreviousActiveChannel()
else:
if (self.view.activeCommunity.communityItem.lastChannelSeen == ""):
self.view.setActiveChannelByIndex(0)
else:
self.view.setActiveChannel(self.view.activeCommunity.communityItem.lastChannelSeen)
self.status.events.on("channelJoined") do(e: Args):
var channel = ChannelArgs(e)

View File

@ -240,11 +240,14 @@ QtObject:
self.clearUnreadIfNeeded(self.activeChannel.chatItem)
self.clearUnreadIfNeeded(selectedChannel)
if (self.activeCommunity.active and self.activeCommunity.communityItem.lastChannelSeen != selectedChannel.id):
self.activeCommunity.communityItem.lastChannelSeen = selectedChannel.id
self.joinedCommunityList.replaceCommunity(self.activeCommunity.communityItem)
if self.activeChannel.id == selectedChannel.id: return
if selectedChannel.chatType.isOneToOne and selectedChannel.id == selectedChannel.name:
selectedChannel.name = self.userNameOrAlias(selectedChannel.id)
selectedChannel.name = self.userNameOrAlias(selectedChannel.id)
self.previousActiveChannelIndex = index
self.activeChannel.setChatItem(selectedChannel)
@ -265,10 +268,10 @@ QtObject:
if(channel == ""): return
let selectedChannel =
if (self.activeCommunity.active):
self.activeCommunity.chats.getChannel(self.activeCommunity.chats.chats.findIndexById(channel))
else:
self.chats.getChannel(self.chats.chats.findIndexById(channel))
if (self.activeCommunity.active):
self.activeCommunity.chats.getChannel(self.activeCommunity.chats.chats.findIndexById(channel))
else:
self.chats.getChannel(self.chats.chats.findIndexById(channel))
self.activeChannel.setChatItem(selectedChannel)
@ -304,7 +307,7 @@ QtObject:
self.activeChannelChanged()
proc restorePreviousActiveChannel*(self: ChatsView) {.slot.} =
if self.activeChannel.id == self.timelineChat.id and not self.previousActiveChannelIndex == -1:
if self.previousActiveChannelIndex != -1:
self.setActiveChannelByIndex(self.previousActiveChannelIndex)
proc getCurrentSuggestions(self: ChatsView): QVariant {.slot.} =

View File

@ -41,7 +41,7 @@ QtObject:
proc setActive*(self: CommunityItemView, value: bool) {.slot.} =
self.active = value
self.status.events.emit("communityActiveChanged", Args())
self.status.events.emit("communityActiveChanged", CommunityActiveChangedArgs(active: value))
self.activeChanged()
proc nbMembersChanged*(self: CommunityItemView) {.signal.}

View File

@ -35,6 +35,9 @@ type
ChatArgs* = ref object of Args
chats*: seq[Chat]
CommunityActiveChangedArgs* = ref object of Args
active*: bool
TopicArgs* = ref object of Args
topics*: seq[MailserverTopic]

View File

@ -95,6 +95,7 @@ type CommunityMembershipRequest* = object
type Community* = object
id*: string
name*: string
lastChannelSeen*: string
description*: string
chats*: seq[Chat]
members*: seq[string]

View File

@ -40,8 +40,7 @@ proc blockContact*(self: ContactModel, id: string): string =
proc unblockContact*(self: ContactModel, id: string): string =
var contact = self.getContactByID(id)
contact.systemTags.delete(contact.systemTags.find(":contact/blocked"))
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries,contact.alias, contact.identicon, contact.identityImage.thumbnail, contact.systemTags, contact.localNickname)
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.alias, contact.identicon, contact.systemTags, contact.localNickname)
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.alias, contact.identicon, contact.identityImage.thumbnail, contact.systemTags, contact.localNickname)
self.events.emit("contactUnblocked", Args())
proc getAllContacts*(): seq[Profile] =
@ -85,7 +84,7 @@ proc addContact*(self: ContactModel, id: string, localNickname: string): string
if contact.identityImage != nil:
thumbnail = contact.identityImage.thumbnail
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, thumbnail, contact.systemTags, nickname)
result = status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.alias, contact.identicon, thumbnail, contact.systemTags, nickname)
self.events.emit("contactAdded", Args())
discard requestContactUpdate(contact.id)
@ -114,7 +113,7 @@ proc removeContact*(self: ContactModel, id: string) =
if contact.identityImage != nil:
thumbnail = contact.identityImage.thumbnail
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.ensVerifiedAt, contact.ensVerificationRetries, contact.alias, contact.identicon, thumbnail, contact.systemTags, contact.localNickname)
discard status_contacts.saveContact(contact.id, contact.ensVerified, contact.ensName, contact.alias, contact.identicon, thumbnail, contact.systemTags, contact.localNickname)
self.events.emit("contactRemoved", Args())
proc isAdded*(self: ContactModel, id: string): bool =

View File

@ -24,8 +24,7 @@ proc getContacts*(): JsonNode =
return %* []
return response["result"]
proc saveContact*(id: string, ensVerified: bool, ensName: string, ensVerifiedAt: int, ensVerificationRetries: int, alias: string, identicon: string, thumbnail: string, systemTags: seq[string], localNickname: string): string =
proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string, identicon: string, systemTags: seq[string], localNickname: string): string =
proc saveContact*(id: string, ensVerified: bool, ensName: string, alias: string, identicon: string, thumbnail: string, systemTags: seq[string], localNickname: string): string =
let payload = %* [{
"id": id,
"name": ensName,

View File

@ -39,7 +39,7 @@ Item {
iconColor: Style.current.inputColor
anchors.left: parent.left
anchors.leftMargin: Style.current.bigPadding
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenter: communityHeaderButton.verticalCenter
onClicked: chatsModel.activeCommunity.active = false
}

View File

@ -43,9 +43,7 @@ Item {
}
onCountChanged: {
if (count > 0 && chatsModel.activeChannelIndex > -1) {
// If a chat is added or removed, we set the current index to the first value
chatsModel.activeChannelIndex = 0;
currentIndex = 0;
currentIndex = chatsModel.activeChannelIndex;
} else {
if (chatsModel.activeChannelIndex > -1) {
chatGroupsListView.currentIndex = 0;