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:
parent
ed09f82305
commit
4b6469c373
|
@ -86,6 +86,12 @@ QtObject:
|
|||
QtProperty[bool] muted:
|
||||
read = getMuted
|
||||
|
||||
proc getPosition(self: ActiveItem): int {.slot.} =
|
||||
return self.item.position
|
||||
|
||||
QtProperty[int] position:
|
||||
read = getPosition
|
||||
|
||||
proc getActiveSubItem(self: ActiveItem): QVariant {.slot.} =
|
||||
return self.activeSubItemVariant
|
||||
|
||||
|
|
|
@ -66,4 +66,10 @@ QtObject:
|
|||
QtProperty[bool] muted:
|
||||
read = getMuted
|
||||
|
||||
proc getPosition(self: ActiveSubItem): int {.slot.} =
|
||||
return self.item.position
|
||||
|
||||
QtProperty[int] position:
|
||||
read = getPosition
|
||||
|
||||
|
|
@ -9,9 +9,10 @@ type
|
|||
notificationsCount: int
|
||||
muted: bool
|
||||
active: bool
|
||||
position: 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.name = name
|
||||
self.icon = icon
|
||||
|
@ -21,11 +22,12 @@ proc setup*(self: BaseItem, id, name, icon, color, description: string, hasNotif
|
|||
self.notificationsCount = notificationsCount
|
||||
self.muted = muted
|
||||
self.active = active
|
||||
self.position = position
|
||||
|
||||
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.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) =
|
||||
discard
|
||||
|
@ -67,4 +69,10 @@ method active*(self: BaseItem): bool {.inline base.} =
|
|||
self.active
|
||||
|
||||
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
|
|
@ -7,9 +7,9 @@ type
|
|||
subItems: SubModel
|
||||
|
||||
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.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.subItems = newSubModel()
|
||||
|
||||
|
@ -35,6 +35,7 @@ proc `$`*(self: Item): string =
|
|||
notificationsCount: {self.notificationsCount},
|
||||
muted: {self.muted},
|
||||
active: {self.active},
|
||||
position: {self.position},
|
||||
subItems:[
|
||||
{$self.subItems}
|
||||
]"""
|
||||
|
|
|
@ -14,6 +14,7 @@ type
|
|||
NotificationsCount
|
||||
Muted
|
||||
Active
|
||||
Position
|
||||
SubItems
|
||||
|
||||
QtObject:
|
||||
|
@ -65,6 +66,7 @@ QtObject:
|
|||
ModelRole.NotificationsCount.int:"notificationsCount",
|
||||
ModelRole.Muted.int:"muted",
|
||||
ModelRole.Active.int:"active",
|
||||
ModelRole.Position.int:"position",
|
||||
ModelRole.SubItems.int:"subItems",
|
||||
}.toTable
|
||||
|
||||
|
@ -99,6 +101,8 @@ QtObject:
|
|||
result = newQVariant(item.muted)
|
||||
of ModelRole.Active:
|
||||
result = newQVariant(item.active)
|
||||
of ModelRole.Position:
|
||||
result = newQVariant(item.position)
|
||||
of ModelRole.SubItems:
|
||||
result = newQVariant(item.subItems)
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ method delete*(self: Module) =
|
|||
self.viewVariant.delete
|
||||
self.controller.delete
|
||||
|
||||
method isCommunity*(self: Module): bool =
|
||||
return self.controller.isCommunity()
|
||||
|
||||
proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, events: EventEmitter,
|
||||
chatService: chat_service.Service, communityService: community_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):
|
||||
chatName = self.controller.getPrettyChatName(c.id)
|
||||
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.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 notificationsCount = chatDto.unviewedMentionsCount
|
||||
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.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
|
||||
|
||||
|
@ -117,7 +120,7 @@ proc buildCommunityUI(self: Module, events: EventEmitter, chatService: chat_serv
|
|||
notificationsCountPerCategory += notificationsCount
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
var categoryItem = initItem(cat.id, cat.name, "", "", "", ChatType.Unknown.int, hasNotificationPerCategory,
|
||||
notificationsCountPerCategory, false, false)
|
||||
notificationsCountPerCategory, false, false, cat.position)
|
||||
categoryItem.prependSubItems(categoryChannels)
|
||||
self.view.appendItem(categoryItem)
|
||||
|
||||
|
|
|
@ -7,4 +7,7 @@ method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: s
|
|||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getChatContentModule*(self: AccessInterface, chatId: string): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method isCommunity*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -7,9 +7,9 @@ type
|
|||
SubItem* = ref object of BaseItem
|
||||
|
||||
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.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) =
|
||||
self.BaseItem.delete
|
||||
|
@ -24,5 +24,6 @@ proc `$`*(self: SubItem): string =
|
|||
hasNotification: {self.hasNotification},
|
||||
notificationsCount: {self.notificationsCount},
|
||||
muted: {self.muted},
|
||||
active: {self.active}
|
||||
active: {self.active},
|
||||
position: {self.position},
|
||||
]"""
|
|
@ -13,6 +13,7 @@ type
|
|||
NotificationsCount
|
||||
Muted
|
||||
Active
|
||||
Position
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -61,7 +62,8 @@ QtObject:
|
|||
ModelRole.HasNotification.int:"hasNotification",
|
||||
ModelRole.NotificationsCount.int:"notificationsCount",
|
||||
ModelRole.Muted.int:"muted",
|
||||
ModelRole.Active.int:"active"
|
||||
ModelRole.Active.int:"active",
|
||||
ModelRole.Position.int:"position",
|
||||
}.toTable
|
||||
|
||||
method data(self: SubModel, index: QModelIndex, role: int): QVariant =
|
||||
|
@ -93,6 +95,8 @@ QtObject:
|
|||
result = newQVariant(item.muted)
|
||||
of ModelRole.Active:
|
||||
result = newQVariant(item.active)
|
||||
of ModelRole.Position:
|
||||
result = newQVariant(item.position)
|
||||
|
||||
proc appendItems*(self: SubModel, items: seq[SubItem]) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
|
|
@ -31,6 +31,9 @@ QtObject:
|
|||
proc load*(self: View) =
|
||||
self.delegate.viewDidLoad()
|
||||
|
||||
proc isCommunity(self: View): bool {.slot.} =
|
||||
return self.delegate.isCommunity()
|
||||
|
||||
proc model*(self: View): Model =
|
||||
return self.model
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ method storePassword*(self: Controller, password: string) =
|
|||
method setActiveSection*(self: Controller, sectionId: string, sectionType: SectionType) =
|
||||
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
|
||||
# notify status go that unviewed mentions count is updated and so...
|
||||
echo "deal with appropriate service..."
|
||||
|
|
Loading…
Reference in New Issue