fix(@desktop/chats): restore last opened chat during app launch
This commit is contained in:
parent
f6660654f7
commit
a7a69e1320
|
@ -53,6 +53,8 @@ const LSS_KEY_DOWNLOAD_CHANNEL_MESSAGES_ENABLED* = "downloadChannelMessagesEnabl
|
||||||
const DEFAULT_DOWNLOAD_CHANNEL_MESSAGES_ENABLED = false
|
const DEFAULT_DOWNLOAD_CHANNEL_MESSAGES_ENABLED = false
|
||||||
const LSS_KEY_ACTIVE_SECTION* = "activeSection"
|
const LSS_KEY_ACTIVE_SECTION* = "activeSection"
|
||||||
const DEFAULT_ACTIVE_SECTION = ""
|
const DEFAULT_ACTIVE_SECTION = ""
|
||||||
|
const LAST_SECTION_CHAT = "LastSectionChat"
|
||||||
|
const DEFAULT_ACTIVE_CHAT = ""
|
||||||
const LSS_KEY_SHOW_BROWSER_SELECTOR* = "showBrowserSelector"
|
const LSS_KEY_SHOW_BROWSER_SELECTOR* = "showBrowserSelector"
|
||||||
const DEFAULT_SHOW_BROWSER_SELECTOR = true
|
const DEFAULT_SHOW_BROWSER_SELECTOR = true
|
||||||
const LSS_KEY_OPEN_LINKS_IN_STATUS* = "openLinksInStatus"
|
const LSS_KEY_OPEN_LINKS_IN_STATUS* = "openLinksInStatus"
|
||||||
|
@ -149,6 +151,16 @@ QtObject:
|
||||||
when T is bool:
|
when T is bool:
|
||||||
result = getSettingsPropBool(self, prop, default)
|
result = getSettingsPropBool(self, prop, default)
|
||||||
|
|
||||||
|
template getSettingsGroupProp[T](self: LocalAccountSensitiveSettings, group: string, prop: string, default: QVariant): untyped =
|
||||||
|
# This doesn't work in case of QVariant, such properties will be handled in a common way.
|
||||||
|
if(self.settings.isNil):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.settings.beginGroup(group);
|
||||||
|
getSettingsProp[T](self, prop, default)
|
||||||
|
self.settings.endGroup();
|
||||||
|
|
||||||
|
|
||||||
template setSettingsProp(self: LocalAccountSensitiveSettings, prop: string, value: QVariant, signal: untyped) =
|
template setSettingsProp(self: LocalAccountSensitiveSettings, prop: string, value: QVariant, signal: untyped) =
|
||||||
if(self.settings.isNil):
|
if(self.settings.isNil):
|
||||||
return
|
return
|
||||||
|
@ -156,6 +168,30 @@ QtObject:
|
||||||
self.settings.setValue(prop, value)
|
self.settings.setValue(prop, value)
|
||||||
signal
|
signal
|
||||||
|
|
||||||
|
template setSettingsGroupProp(self: LocalAccountSensitiveSettings, group: string, key: string, value: QVariant) =
|
||||||
|
if(self.settings.isNil):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.settings.beginGroup(group)
|
||||||
|
self.settings.setValue(key, value)
|
||||||
|
self.settings.endGroup()
|
||||||
|
|
||||||
|
proc removeSettingsGroupKey(self: LocalAccountSensitiveSettings, group: string, key: string) =
|
||||||
|
if(self.settings.isNil):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.settings.beginGroup(group)
|
||||||
|
self.settings.remove(key)
|
||||||
|
self.settings.endGroup()
|
||||||
|
|
||||||
|
proc getSectionLastOpenChat*(self: LocalAccountSensitiveSettings, sectionId: string): string =
|
||||||
|
getSettingsGroupProp[string](self, LAST_SECTION_CHAT, sectionId, newQVariant(DEFAULT_ACTIVE_CHAT))
|
||||||
|
|
||||||
|
proc setSectionLastOpenChat*(self: LocalAccountSensitiveSettings, sectionId: string, value: string) =
|
||||||
|
self.setSettingsGroupProp(LAST_SECTION_CHAT, sectionId, newQVariant(value))
|
||||||
|
|
||||||
|
proc removeSectionChatRecord*(self: LocalAccountSensitiveSettings, sectionId: string) =
|
||||||
|
self.removeSettingsGroupKey(LAST_SECTION_CHAT, sectionId)
|
||||||
|
|
||||||
proc chatSplitViewChanged*(self: LocalAccountSensitiveSettings) {.signal.}
|
proc chatSplitViewChanged*(self: LocalAccountSensitiveSettings) {.signal.}
|
||||||
proc getChatSplitView*(self: LocalAccountSensitiveSettings): QVariant {.slot.} =
|
proc getChatSplitView*(self: LocalAccountSensitiveSettings): QVariant {.slot.} =
|
||||||
|
@ -498,7 +534,6 @@ QtObject:
|
||||||
write = setActiveSection
|
write = setActiveSection
|
||||||
notify = activeSectionChanged
|
notify = activeSectionChanged
|
||||||
|
|
||||||
|
|
||||||
proc showBrowserSelectorChanged*(self: LocalAccountSensitiveSettings) {.signal.}
|
proc showBrowserSelectorChanged*(self: LocalAccountSensitiveSettings) {.signal.}
|
||||||
proc getShowBrowserSelector*(self: LocalAccountSensitiveSettings): bool {.slot.} =
|
proc getShowBrowserSelector*(self: LocalAccountSensitiveSettings): bool {.slot.} =
|
||||||
# getSettingsProp[bool](self, LSS_KEY_SHOW_BROWSER_SELECTOR, newQVariant(DEFAULT_SHOW_BROWSER_SELECTOR)) # https://github.com/status-im/status-desktop/issues/8568
|
# getSettingsProp[bool](self, LSS_KEY_SHOW_BROWSER_SELECTOR, newQVariant(DEFAULT_SHOW_BROWSER_SELECTOR)) # https://github.com/status-im/status-desktop/issues/8568
|
||||||
|
|
|
@ -129,6 +129,7 @@ proc buildChatSectionUI(
|
||||||
mailserversService: mailservers_service.Service) =
|
mailserversService: mailservers_service.Service) =
|
||||||
var selectedItemId = ""
|
var selectedItemId = ""
|
||||||
var selectedSubItemId = ""
|
var selectedSubItemId = ""
|
||||||
|
let sectionLastOpenChat = singletonInstance.localAccountSensitiveSettings.getSectionLastOpenChat(self.controller.getMySectionId())
|
||||||
|
|
||||||
# handle channels which don't belong to any category
|
# handle channels which don't belong to any category
|
||||||
for chatDto in channelGroup.chats:
|
for chatDto in channelGroup.chats:
|
||||||
|
@ -173,8 +174,9 @@ proc buildChatSectionUI(
|
||||||
self.addSubmodule(chatDto.id, belongToCommunity, isUsersListAvailable, events, settingsService, nodeConfigurationService,
|
self.addSubmodule(chatDto.id, belongToCommunity, isUsersListAvailable, events, settingsService, nodeConfigurationService,
|
||||||
contactService, chatService, communityService, messageService, gifService, mailserversService)
|
contactService, chatService, communityService, messageService, gifService, mailserversService)
|
||||||
|
|
||||||
# make the first channel which doesn't belong to any category active when load the app
|
# restore on a startup last open channel for the section or
|
||||||
if(selectedItemId.len == 0):
|
# make the first channel which doesn't belong to any category active
|
||||||
|
if selectedItemId.len == 0 or chatDto.id == sectionLastOpenChat:
|
||||||
selectedItemId = channelItem.id
|
selectedItemId = channelItem.id
|
||||||
|
|
||||||
# handle categories and channels for each category
|
# handle categories and channels for each category
|
||||||
|
@ -203,9 +205,10 @@ proc buildChatSectionUI(
|
||||||
settingsService, nodeConfigurationService, contactService, chatService, communityService, messageService, gifService,
|
settingsService, nodeConfigurationService, contactService, chatService, communityService, messageService, gifService,
|
||||||
mailserversService)
|
mailserversService)
|
||||||
|
|
||||||
|
# restore on a startup last open channel in the category for the section or
|
||||||
# in case there is no channels beyond categories,
|
# in case there is no channels beyond categories,
|
||||||
# make the first channel of the first category active when load the app
|
# make the first channel of the first category active
|
||||||
if(selectedItemId.len == 0):
|
if selectedItemId.len == 0 or channelItem.id == sectionLastOpenChat:
|
||||||
selectedItemId = cat.id
|
selectedItemId = cat.id
|
||||||
selectedSubItemId = channelItem.id
|
selectedSubItemId = channelItem.id
|
||||||
|
|
||||||
|
@ -331,10 +334,13 @@ method makeChatWithIdActive*(self: Module, chatId: string) =
|
||||||
|
|
||||||
# here, in this step we have appropriate item and subitem assigned
|
# here, in this step we have appropriate item and subitem assigned
|
||||||
self.setActiveItemSubItem(item.BaseItem.id, subItemId)
|
self.setActiveItemSubItem(item.BaseItem.id, subItemId)
|
||||||
|
singletonInstance.localAccountSensitiveSettings.setSectionLastOpenChat(self.controller.getMySectionId(), chatId)
|
||||||
|
|
||||||
method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
|
method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
|
||||||
|
let mySectionId = self.controller.getMySectionId()
|
||||||
if (itemId == "" and subItemId == ""):
|
if (itemId == "" and subItemId == ""):
|
||||||
self.view.activeItem().resetActiveItemData()
|
self.view.activeItem().resetActiveItemData()
|
||||||
|
singletonInstance.localAccountSensitiveSettings.removeSectionChatRecord(mySectionId)
|
||||||
return
|
return
|
||||||
|
|
||||||
let item = self.view.chatsModel().getItemById(itemId)
|
let item = self.view.chatsModel().getItemById(itemId)
|
||||||
|
@ -358,8 +364,13 @@ method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
|
||||||
else:
|
else:
|
||||||
chatContentModule.onMadeInactive()
|
chatContentModule.onMadeInactive()
|
||||||
|
|
||||||
|
let activeChatId = self.controller.getActiveChatId()
|
||||||
|
|
||||||
|
# save last open chat in settings for restore on the next app launch
|
||||||
|
singletonInstance.localAccountSensitiveSettings.setSectionLastOpenChat(mySectionId, activeChatId)
|
||||||
|
|
||||||
# notify parent module about active chat/channel
|
# notify parent module about active chat/channel
|
||||||
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId())
|
self.delegate.onActiveChatChange(mySectionId, activeChatId)
|
||||||
|
|
||||||
method getModuleAsVariant*(self: Module): QVariant =
|
method getModuleAsVariant*(self: Module): QVariant =
|
||||||
return self.viewVariant
|
return self.viewVariant
|
||||||
|
|
|
@ -749,6 +749,8 @@ method communityLeft*[T](self: Module[T], communityId: string) =
|
||||||
|
|
||||||
self.view.model().removeItem(communityId)
|
self.view.model().removeItem(communityId)
|
||||||
|
|
||||||
|
singletonInstance.localAccountSensitiveSettings.removeSectionChatRecord(communityId)
|
||||||
|
|
||||||
if (self.controller.getActiveSectionId() == communityId):
|
if (self.controller.getActiveSectionId() == communityId):
|
||||||
let item = self.view.model().getItemById(singletonInstance.userProfile.getPubKey())
|
let item = self.view.model().getItemById(singletonInstance.userProfile.getPubKey())
|
||||||
self.setActiveSection(item)
|
self.setActiveSection(item)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 75b70971caf863629b4af83be254c04a84ef8c1e
|
Subproject commit d1926ff252c7645b04cfff014d6a6c80313d8628
|
|
@ -1 +1 @@
|
||||||
Subproject commit c428cf43976be8e647e8cf6412e783b06765b5ee
|
Subproject commit 743674eff154c49386254d8fbb1fc756fffee09c
|
Loading…
Reference in New Issue