diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index eef60474e2..e7097cd128 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -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) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 613618d828..ca53b08db2 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -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.} = diff --git a/src/app/chat/views/community_item.nim b/src/app/chat/views/community_item.nim index 9cc625d8c2..afbd4a9fde 100644 --- a/src/app/chat/views/community_item.nim +++ b/src/app/chat/views/community_item.nim @@ -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.} diff --git a/src/status/chat.nim b/src/status/chat.nim index ee4bdcd0ad..cf86a2ef9d 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -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] diff --git a/src/status/chat/chat.nim b/src/status/chat/chat.nim index 074018f5fc..7c53bf8da1 100644 --- a/src/status/chat/chat.nim +++ b/src/status/chat/chat.nim @@ -95,6 +95,7 @@ type CommunityMembershipRequest* = object type Community* = object id*: string name*: string + lastChannelSeen*: string description*: string chats*: seq[Chat] members*: seq[string] diff --git a/src/status/contacts.nim b/src/status/contacts.nim index 2c7a5d3cec..b6a32e64bc 100644 --- a/src/status/contacts.nim +++ b/src/status/contacts.nim @@ -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 = diff --git a/src/status/libstatus/contacts.nim b/src/status/libstatus/contacts.nim index 5086d3d657..025d32ac01 100644 --- a/src/status/libstatus/contacts.nim +++ b/src/status/libstatus/contacts.nim @@ -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, diff --git a/ui/app/AppLayouts/Chat/CommunityColumn.qml b/ui/app/AppLayouts/Chat/CommunityColumn.qml index 9459c80845..eaf5f58f15 100644 --- a/ui/app/AppLayouts/Chat/CommunityColumn.qml +++ b/ui/app/AppLayouts/Chat/CommunityColumn.qml @@ -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 } diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml index 1ed4d33881..7ba0d52f5c 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/ChannelList.qml @@ -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;