fix(categories): fixes categories being always closed on start
Part of https://github.com/status-im/status-desktop/issues/14886 The problem was that we converted `collapsed` to `opened` way too early and with a logic error. By using collapsed until the module, it's way easier to understand and also fixes the logic mistakes. I also renamed a couple of functions and variables so that the mistake doesn't happen again.
This commit is contained in:
parent
1692651184
commit
6a820c9e72
|
@ -695,12 +695,12 @@ proc addNewChat(
|
||||||
if category.id == "":
|
if category.id == "":
|
||||||
error "No category found for chat", chatName=chatDto.name, categoryId=chatDto.categoryId
|
error "No category found for chat", chatName=chatDto.name, categoryId=chatDto.categoryId
|
||||||
else:
|
else:
|
||||||
categoryOpened = category.categoryOpened
|
categoryOpened = not category.collapsed
|
||||||
categoryPosition = category.position
|
categoryPosition = category.position
|
||||||
|
|
||||||
# TODO: This call will update the model for each category in channels which is not
|
# TODO: This call will update the model for each category in channels which is not
|
||||||
# preferable. Please fix-me in https://github.com/status-im/status-desktop/issues/14431
|
# preferable. Please fix-me in https://github.com/status-im/status-desktop/issues/14431
|
||||||
self.view.chatsModel().changeCategoryOpened(category.id, category.categoryOpened)
|
self.view.chatsModel().changeCategoryOpened(category.id, categoryOpened)
|
||||||
|
|
||||||
var canPostReactions = true
|
var canPostReactions = true
|
||||||
var hideIfPermissionsNotMet = false
|
var hideIfPermissionsNotMet = false
|
||||||
|
@ -1394,7 +1394,7 @@ method toggleCollapsedCommunityCategory*(self: Module, categoryId: string, colla
|
||||||
self.controller.toggleCollapsedCommunityCategory(categoryId, collapsed)
|
self.controller.toggleCollapsedCommunityCategory(categoryId, collapsed)
|
||||||
|
|
||||||
method onToggleCollapsedCommunityCategory*(self: Module, categoryId: string, collapsed: bool) =
|
method onToggleCollapsedCommunityCategory*(self: Module, categoryId: string, collapsed: bool) =
|
||||||
self.view.chatsModel().changeCategoryOpened(categoryId, collapsed)
|
self.view.chatsModel().changeCategoryOpened(categoryId, not collapsed)
|
||||||
|
|
||||||
method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, toPosition: int) =
|
method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, toPosition: int) =
|
||||||
self.controller.reorderCommunityChat(categoryId, chatId, toPosition + 1)
|
self.controller.reorderCommunityChat(categoryId, chatId, toPosition + 1)
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Category* = object
|
||||||
id*: string
|
id*: string
|
||||||
name*: string
|
name*: string
|
||||||
position*: int
|
position*: int
|
||||||
categoryOpened*: bool
|
collapsed*: bool
|
||||||
|
|
||||||
type
|
type
|
||||||
Permission* = object
|
Permission* = object
|
||||||
|
@ -189,7 +189,7 @@ proc toCategory*(jsonObj: JsonNode): Category =
|
||||||
discard jsonObj.getProp("id", result.id)
|
discard jsonObj.getProp("id", result.id)
|
||||||
discard jsonObj.getProp("name", result.name)
|
discard jsonObj.getProp("name", result.name)
|
||||||
discard jsonObj.getProp("position", result.position)
|
discard jsonObj.getProp("position", result.position)
|
||||||
discard jsonObj.getProp("categoryOpened", result.categoryOpened)
|
discard jsonObj.getProp("collapsed", result.collapsed)
|
||||||
|
|
||||||
proc toChatMember*(jsonObj: JsonNode, memberId: string): ChatMember =
|
proc toChatMember*(jsonObj: JsonNode, memberId: string): ChatMember =
|
||||||
# Parse status-go "Member" type
|
# Parse status-go "Member" type
|
||||||
|
|
|
@ -391,10 +391,13 @@ proc toCommunityMembershipRequestDto*(jsonObj: JsonNode): CommunityMembershipReq
|
||||||
discard jsonObj.getProp("communityId", result.communityId)
|
discard jsonObj.getProp("communityId", result.communityId)
|
||||||
discard jsonObj.getProp("our", result.our)
|
discard jsonObj.getProp("our", result.our)
|
||||||
|
|
||||||
proc toCategoryDto*(jsonObj: JsonNode): Category =
|
proc toCollapsedCategoryDto*(jsonObj: JsonNode, isCollapsed: bool = false): Category =
|
||||||
result = Category()
|
result = Category()
|
||||||
discard jsonObj.getProp("categoryId", result.id)
|
discard jsonObj.getProp("categoryId", result.id)
|
||||||
discard jsonObj.getProp("collapsed", result.categoryOpened)
|
# The CollapsedCommunityCategories API only returns **collapsed** categories.
|
||||||
|
# So if a category is **not** collapsed, it's not in the list
|
||||||
|
# The collapsed property on the json is always false
|
||||||
|
result.collapsed = true
|
||||||
|
|
||||||
proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
|
proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
|
||||||
result = CommunityDto()
|
result = CommunityDto()
|
||||||
|
@ -499,16 +502,16 @@ proc toCommunitySettingsDto*(jsonObj: JsonNode): CommunitySettingsDto =
|
||||||
discard jsonObj.getProp("historyArchiveSupportEnabled", result.historyArchiveSupportEnabled)
|
discard jsonObj.getProp("historyArchiveSupportEnabled", result.historyArchiveSupportEnabled)
|
||||||
|
|
||||||
proc parseCommunities*(response: JsonNode, categories: seq[Category]): seq[CommunityDto] =
|
proc parseCommunities*(response: JsonNode, categories: seq[Category]): seq[CommunityDto] =
|
||||||
var categoryMap = initTable[string, bool]()
|
var categoryCollapsedMap = initTable[string, bool]()
|
||||||
for category in categories:
|
for category in categories:
|
||||||
categoryMap[category.id] = true
|
categoryCollapsedMap[category.id] = true
|
||||||
|
|
||||||
for communityNode in response["result"].getElems():
|
for communityNode in response["result"].getElems():
|
||||||
var community = communityNode.toCommunityDto()
|
var community = communityNode.toCommunityDto()
|
||||||
|
|
||||||
for category in community.categories.mitems:
|
for category in community.categories.mitems:
|
||||||
if categoryMap.hasKey(category.id):
|
if categoryCollapsedMap.hasKey(category.id):
|
||||||
category.categoryOpened = true
|
category.collapsed = true
|
||||||
result.add(community)
|
result.add(community)
|
||||||
|
|
||||||
proc parseKnownCuratedCommunities(jsonCommunities: JsonNode): seq[CommunityDto] =
|
proc parseKnownCuratedCommunities(jsonCommunities: JsonNode): seq[CommunityDto] =
|
||||||
|
|
|
@ -817,7 +817,7 @@ QtObject:
|
||||||
let collapsedCommunityCategories = responseObj["collapsedCommunityCategories"]
|
let collapsedCommunityCategories = responseObj["collapsedCommunityCategories"]
|
||||||
if collapsedCommunityCategories{"result"}.kind != JNull:
|
if collapsedCommunityCategories{"result"}.kind != JNull:
|
||||||
for jsonCategory in collapsedCommunityCategories["result"]:
|
for jsonCategory in collapsedCommunityCategories["result"]:
|
||||||
categories.add(jsonCategory.toCategoryDto())
|
categories.add(jsonCategory.toCollapsedCategoryDto())
|
||||||
|
|
||||||
# All communities
|
# All communities
|
||||||
let communities = parseCommunities(responseObj["communities"], categories)
|
let communities = parseCommunities(responseObj["communities"], categories)
|
||||||
|
|
|
@ -147,11 +147,13 @@ Item {
|
||||||
highlighted = true;
|
highlighted = true;
|
||||||
categoryPopupMenuSlot.item.popup()
|
categoryPopupMenuSlot.item.popup()
|
||||||
} else if (mouse.button === Qt.LeftButton) {
|
} else if (mouse.button === Qt.LeftButton) {
|
||||||
root.toggleCollapsedCommunityCategory(model.categoryId, !statusChatListCategoryItem.opened)
|
// We pass the value for collapsed that we want
|
||||||
|
// So if opened == true, we want opened == false -> we pass collapsed = true
|
||||||
|
root.toggleCollapsedCommunityCategory(model.categoryId, statusChatListCategoryItem.opened)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onToggleButtonClicked: {
|
onToggleButtonClicked: {
|
||||||
root.toggleCollapsedCommunityCategory(model.categoryId, !statusChatListCategoryItem.opened)
|
root.toggleCollapsedCommunityCategory(model.categoryId, statusChatListCategoryItem.opened)
|
||||||
}
|
}
|
||||||
onMenuButtonClicked: {
|
onMenuButtonClicked: {
|
||||||
statusChatListCategoryItem.setupPopup()
|
statusChatListCategoryItem.setupPopup()
|
||||||
|
|
Loading…
Reference in New Issue