refactor(chat-communities): position field and `isCommunity` added to the chat section module

Position field added to a model/submodle of the chat section module.
`isCommunity` method is exposed to qml from the view of the section module.
This commit is contained in:
Sale Djenic 2021-11-10 13:39:53 +01:00
parent ed09f82305
commit 4b6469c373
11 changed files with 54 additions and 15 deletions

View File

@ -86,6 +86,12 @@ QtObject:
QtProperty[bool] muted: QtProperty[bool] muted:
read = getMuted read = getMuted
proc getPosition(self: ActiveItem): int {.slot.} =
return self.item.position
QtProperty[int] position:
read = getPosition
proc getActiveSubItem(self: ActiveItem): QVariant {.slot.} = proc getActiveSubItem(self: ActiveItem): QVariant {.slot.} =
return self.activeSubItemVariant return self.activeSubItemVariant

View File

@ -66,4 +66,10 @@ QtObject:
QtProperty[bool] muted: QtProperty[bool] muted:
read = getMuted read = getMuted
proc getPosition(self: ActiveSubItem): int {.slot.} =
return self.item.position
QtProperty[int] position:
read = getPosition

View File

@ -9,9 +9,10 @@ type
notificationsCount: int notificationsCount: int
muted: bool muted: bool
active: bool active: bool
position: int
proc setup*(self: BaseItem, id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int, proc setup*(self: BaseItem, id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int,
muted, active: bool) = muted, active: bool, position: int) =
self.id = id self.id = id
self.name = name self.name = name
self.icon = icon self.icon = icon
@ -21,11 +22,12 @@ proc setup*(self: BaseItem, id, name, icon, color, description: string, hasNotif
self.notificationsCount = notificationsCount self.notificationsCount = notificationsCount
self.muted = muted self.muted = muted
self.active = active self.active = active
self.position = position
proc initBaseItem*(id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int, proc initBaseItem*(id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int,
muted, active: bool): BaseItem = muted, active: bool, position: int): BaseItem =
result = BaseItem() result = BaseItem()
result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active) result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active, position)
proc delete*(self: BaseItem) = proc delete*(self: BaseItem) =
discard discard
@ -68,3 +70,9 @@ method active*(self: BaseItem): bool {.inline base.} =
method `active=`*(self: var BaseItem, value: bool) {.inline base.} = method `active=`*(self: var BaseItem, value: bool) {.inline base.} =
self.active = value self.active = value
method position*(self: BaseItem): int {.inline base.} =
self.position
method `position=`*(self: var BaseItem, value: int) {.inline base.} =
self.position = value

View File

@ -7,9 +7,9 @@ type
subItems: SubModel subItems: SubModel
proc initItem*(id, name, icon, color, description: string, `type`: int, hasNotification: bool, notificationsCount: int, proc initItem*(id, name, icon, color, description: string, `type`: int, hasNotification: bool, notificationsCount: int,
muted, active: bool): Item = muted, active: bool, position: int): Item =
result = Item() result = Item()
result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active) result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active, position)
result.`type` = `type` result.`type` = `type`
result.subItems = newSubModel() result.subItems = newSubModel()
@ -35,6 +35,7 @@ proc `$`*(self: Item): string =
notificationsCount: {self.notificationsCount}, notificationsCount: {self.notificationsCount},
muted: {self.muted}, muted: {self.muted},
active: {self.active}, active: {self.active},
position: {self.position},
subItems:[ subItems:[
{$self.subItems} {$self.subItems}
]""" ]"""

View File

@ -14,6 +14,7 @@ type
NotificationsCount NotificationsCount
Muted Muted
Active Active
Position
SubItems SubItems
QtObject: QtObject:
@ -65,6 +66,7 @@ QtObject:
ModelRole.NotificationsCount.int:"notificationsCount", ModelRole.NotificationsCount.int:"notificationsCount",
ModelRole.Muted.int:"muted", ModelRole.Muted.int:"muted",
ModelRole.Active.int:"active", ModelRole.Active.int:"active",
ModelRole.Position.int:"position",
ModelRole.SubItems.int:"subItems", ModelRole.SubItems.int:"subItems",
}.toTable }.toTable
@ -99,6 +101,8 @@ QtObject:
result = newQVariant(item.muted) result = newQVariant(item.muted)
of ModelRole.Active: of ModelRole.Active:
result = newQVariant(item.active) result = newQVariant(item.active)
of ModelRole.Position:
result = newQVariant(item.position)
of ModelRole.SubItems: of ModelRole.SubItems:
result = newQVariant(item.subItems) result = newQVariant(item.subItems)

View File

@ -48,6 +48,9 @@ method delete*(self: Module) =
self.viewVariant.delete self.viewVariant.delete
self.controller.delete self.controller.delete
method isCommunity*(self: Module): bool =
return self.controller.isCommunity()
proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, events: EventEmitter, proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, events: EventEmitter,
chatService: chat_service.Service, communityService: community_service.Service, chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service) = messageService: message_service.Service) =
@ -67,7 +70,7 @@ proc buildChatUI(self: Module, events: EventEmitter, chatService: chat_service.S
if(c.chatType == ChatType.OneToOne): if(c.chatType == ChatType.OneToOne):
chatName = self.controller.getPrettyChatName(c.id) chatName = self.controller.getPrettyChatName(c.id)
let item = initItem(c.id, chatName, c.identicon, c.color, c.description, c.chatType.int, hasNotification, let item = initItem(c.id, chatName, c.identicon, c.color, c.description, c.chatType.int, hasNotification,
notificationsCount, c.muted, false) notificationsCount, c.muted, false, 0)
self.view.appendItem(item) self.view.appendItem(item)
self.addSubmodule(c.id, false, events, chatService, communityService, messageService) self.addSubmodule(c.id, false, events, chatService, communityService, messageService)
@ -91,7 +94,7 @@ proc buildCommunityUI(self: Module, events: EventEmitter, chatService: chat_serv
let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0 let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0
let notificationsCount = chatDto.unviewedMentionsCount let notificationsCount = chatDto.unviewedMentionsCount
let channelItem = initItem(chatDto.id, chatDto.name, chatDto.identicon, chatDto.color, chatDto.description, let channelItem = initItem(chatDto.id, chatDto.name, chatDto.identicon, chatDto.color, chatDto.description,
chatDto.chatType.int, hasNotification, notificationsCount, chatDto.muted, false) chatDto.chatType.int, hasNotification, notificationsCount, chatDto.muted, false, c.position)
self.view.appendItem(channelItem) self.view.appendItem(channelItem)
self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService) self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
@ -117,7 +120,7 @@ proc buildCommunityUI(self: Module, events: EventEmitter, chatService: chat_serv
notificationsCountPerCategory += notificationsCount notificationsCountPerCategory += notificationsCount
let channelItem = initSubItem(chatDto.id, chatDto.name, chatDto.identicon, chatDto.color, chatDto.description, let channelItem = initSubItem(chatDto.id, chatDto.name, chatDto.identicon, chatDto.color, chatDto.description,
hasNotification, notificationsCount, chatDto.muted, false) hasNotification, notificationsCount, chatDto.muted, false, c.position)
categoryChannels.add(channelItem) categoryChannels.add(channelItem)
self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService) self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
@ -128,7 +131,7 @@ proc buildCommunityUI(self: Module, events: EventEmitter, chatService: chat_serv
selectedSubItemId = channelItem.id selectedSubItemId = channelItem.id
var categoryItem = initItem(cat.id, cat.name, "", "", "", ChatType.Unknown.int, hasNotificationPerCategory, var categoryItem = initItem(cat.id, cat.name, "", "", "", ChatType.Unknown.int, hasNotificationPerCategory,
notificationsCountPerCategory, false, false) notificationsCountPerCategory, false, false, cat.position)
categoryItem.prependSubItems(categoryChannels) categoryItem.prependSubItems(categoryChannels)
self.view.appendItem(categoryItem) self.view.appendItem(categoryItem)

View File

@ -8,3 +8,6 @@ method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: s
method getChatContentModule*(self: AccessInterface, chatId: string): QVariant {.base.} = method getChatContentModule*(self: AccessInterface, chatId: string): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -7,9 +7,9 @@ type
SubItem* = ref object of BaseItem SubItem* = ref object of BaseItem
proc initSubItem*(id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int, proc initSubItem*(id, name, icon, color, description: string, hasNotification: bool, notificationsCount: int,
muted, active: bool): SubItem = muted, active: bool, position: int): SubItem =
result = SubItem() result = SubItem()
result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active) result.setup(id, name, icon, color, description, hasNotification, notificationsCount, muted, active, position)
proc delete*(self: SubItem) = proc delete*(self: SubItem) =
self.BaseItem.delete self.BaseItem.delete
@ -24,5 +24,6 @@ proc `$`*(self: SubItem): string =
hasNotification: {self.hasNotification}, hasNotification: {self.hasNotification},
notificationsCount: {self.notificationsCount}, notificationsCount: {self.notificationsCount},
muted: {self.muted}, muted: {self.muted},
active: {self.active} active: {self.active},
position: {self.position},
]""" ]"""

View File

@ -13,6 +13,7 @@ type
NotificationsCount NotificationsCount
Muted Muted
Active Active
Position
QtObject: QtObject:
type type
@ -61,7 +62,8 @@ QtObject:
ModelRole.HasNotification.int:"hasNotification", ModelRole.HasNotification.int:"hasNotification",
ModelRole.NotificationsCount.int:"notificationsCount", ModelRole.NotificationsCount.int:"notificationsCount",
ModelRole.Muted.int:"muted", ModelRole.Muted.int:"muted",
ModelRole.Active.int:"active" ModelRole.Active.int:"active",
ModelRole.Position.int:"position",
}.toTable }.toTable
method data(self: SubModel, index: QModelIndex, role: int): QVariant = method data(self: SubModel, index: QModelIndex, role: int): QVariant =
@ -93,6 +95,8 @@ QtObject:
result = newQVariant(item.muted) result = newQVariant(item.muted)
of ModelRole.Active: of ModelRole.Active:
result = newQVariant(item.active) result = newQVariant(item.active)
of ModelRole.Position:
result = newQVariant(item.position)
proc appendItems*(self: SubModel, items: seq[SubItem]) = proc appendItems*(self: SubModel, items: seq[SubItem]) =
let parentModelIndex = newQModelIndex() let parentModelIndex = newQModelIndex()

View File

@ -31,6 +31,9 @@ QtObject:
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
proc isCommunity(self: View): bool {.slot.} =
return self.delegate.isCommunity()
proc model*(self: View): Model = proc model*(self: View): Model =
return self.model return self.model

View File

@ -107,7 +107,7 @@ method storePassword*(self: Controller, password: string) =
method setActiveSection*(self: Controller, sectionId: string, sectionType: SectionType) = method setActiveSection*(self: Controller, sectionId: string, sectionType: SectionType) =
self.activeSectionId = sectionId self.activeSectionId = sectionId
if(sectionType == SectionType.Chat or sectionType != SectionType.Community): if(sectionType == SectionType.Chat or sectionType == SectionType.Community):
# We need to take other actions here, in case of Chat or Community sections like # We need to take other actions here, in case of Chat or Community sections like
# notify status go that unviewed mentions count is updated and so... # notify status go that unviewed mentions count is updated and so...
echo "deal with appropriate service..." echo "deal with appropriate service..."