parent
0c88da4d81
commit
9a9d671014
|
@ -15,10 +15,11 @@ type
|
||||||
active: bool
|
active: bool
|
||||||
position: int
|
position: int
|
||||||
categoryId: string
|
categoryId: string
|
||||||
|
highlight: bool
|
||||||
|
|
||||||
proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, description: string,
|
proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, description: string,
|
||||||
`type`: int, amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
|
`type`: int, amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
|
||||||
position: int, categoryId: string = "") =
|
position: int, categoryId: string = "", highlight: bool = false) =
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.amIChatAdmin = amIChatAdmin
|
self.amIChatAdmin = amIChatAdmin
|
||||||
|
@ -34,13 +35,14 @@ proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, de
|
||||||
self.active = active
|
self.active = active
|
||||||
self.position = position
|
self.position = position
|
||||||
self.categoryId = categoryId
|
self.categoryId = categoryId
|
||||||
|
self.highlight = highlight
|
||||||
|
|
||||||
proc initBaseItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int,
|
proc initBaseItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int,
|
||||||
amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
|
amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
|
||||||
position: int, categoryId: string = ""): BaseItem =
|
position: int, categoryId: string = "", highlight: bool = false): BaseItem =
|
||||||
result = BaseItem()
|
result = BaseItem()
|
||||||
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
|
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
|
||||||
notificationsCount, muted, blocked, active, position, categoryId)
|
notificationsCount, muted, blocked, active, position, categoryId, highlight)
|
||||||
|
|
||||||
proc delete*(self: BaseItem) =
|
proc delete*(self: BaseItem) =
|
||||||
discard
|
discard
|
||||||
|
@ -122,3 +124,9 @@ method categoryId*(self: BaseItem): string {.inline base.} =
|
||||||
|
|
||||||
method `categoryId=`*(self: var BaseItem, value: string) {.inline base.} =
|
method `categoryId=`*(self: var BaseItem, value: string) {.inline base.} =
|
||||||
self.categoryId = value
|
self.categoryId = value
|
||||||
|
|
||||||
|
method highlight*(self: BaseItem): bool {.inline base.} =
|
||||||
|
self.highlight
|
||||||
|
|
||||||
|
method `highlight=`*(self: var BaseItem, value: bool) {.inline base.} =
|
||||||
|
self.highlight = value
|
||||||
|
|
|
@ -94,6 +94,12 @@ method init*(self: Controller) =
|
||||||
var args = ContactArgs(e)
|
var args = ContactArgs(e)
|
||||||
self.delegate.onContactUnblocked(args.contactId)
|
self.delegate.onContactUnblocked(args.contactId)
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args):
|
||||||
|
var args = ChatUpdateArgsNew(e)
|
||||||
|
self.delegate.addChatIfDontExist(args.chats, false, self.events, self.settingsService, self.contactService, self.chatService,
|
||||||
|
self.communityService, self.messageService, self.gifService, self.mailserversService, setChatAsActive = false)
|
||||||
|
|
||||||
|
|
||||||
if (self.isCommunitySection):
|
if (self.isCommunitySection):
|
||||||
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
|
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
|
||||||
let args = CommunityChatArgs(e)
|
let args = CommunityChatArgs(e)
|
||||||
|
|
|
@ -6,10 +6,10 @@ type
|
||||||
subItems: SubModel
|
subItems: SubModel
|
||||||
|
|
||||||
proc initItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool,
|
proc initItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool,
|
||||||
hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string): Item =
|
hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string, highlight: bool = false): Item =
|
||||||
result = Item()
|
result = Item()
|
||||||
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
|
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
|
||||||
notificationsCount, muted, blocked, active, position, categoryId)
|
notificationsCount, muted, blocked, active, position, categoryId, highlight)
|
||||||
result.subItems = newSubModel()
|
result.subItems = newSubModel()
|
||||||
|
|
||||||
proc delete*(self: Item) =
|
proc delete*(self: Item) =
|
||||||
|
@ -36,6 +36,7 @@ proc `$`*(self: Item): string =
|
||||||
active: {self.active},
|
active: {self.active},
|
||||||
position: {self.position},
|
position: {self.position},
|
||||||
categoryId: {self.categoryId},
|
categoryId: {self.categoryId},
|
||||||
|
highlight: {self.highlight},
|
||||||
subItems:[
|
subItems:[
|
||||||
{$self.subItems}
|
{$self.subItems}
|
||||||
]"""
|
]"""
|
||||||
|
@ -56,7 +57,8 @@ proc toJsonNode*(self: Item): JsonNode =
|
||||||
"blocked": self.blocked,
|
"blocked": self.blocked,
|
||||||
"active": self.active,
|
"active": self.active,
|
||||||
"position": self.position,
|
"position": self.position,
|
||||||
"categoryId": self.categoryId
|
"categoryId": self.categoryId,
|
||||||
|
"highlight": self.highlight
|
||||||
}
|
}
|
||||||
|
|
||||||
proc appendSubItems*(self: Item, items: seq[SubItem]) =
|
proc appendSubItems*(self: Item, items: seq[SubItem]) =
|
||||||
|
|
|
@ -21,6 +21,7 @@ type
|
||||||
SubItems
|
SubItems
|
||||||
IsCategory
|
IsCategory
|
||||||
CategoryId
|
CategoryId
|
||||||
|
Highlight
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -85,7 +86,8 @@ QtObject:
|
||||||
ModelRole.Position.int:"position",
|
ModelRole.Position.int:"position",
|
||||||
ModelRole.SubItems.int:"subItems",
|
ModelRole.SubItems.int:"subItems",
|
||||||
ModelRole.IsCategory.int:"isCategory",
|
ModelRole.IsCategory.int:"isCategory",
|
||||||
ModelRole.CategoryId.int:"categoryId"
|
ModelRole.CategoryId.int:"categoryId",
|
||||||
|
ModelRole.Highlight.int:"highlight"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
||||||
|
@ -133,6 +135,8 @@ QtObject:
|
||||||
result = newQVariant(item.`type` == ChatType.Unknown.int)
|
result = newQVariant(item.`type` == ChatType.Unknown.int)
|
||||||
of ModelRole.CategoryId:
|
of ModelRole.CategoryId:
|
||||||
result = newQVariant(item.categoryId)
|
result = newQVariant(item.categoryId)
|
||||||
|
of ModelRole.Highlight:
|
||||||
|
result = newQVariant(item.highlight)
|
||||||
|
|
||||||
proc appendItem*(self: Model, item: Item) =
|
proc appendItem*(self: Model, item: Item) =
|
||||||
let parentModelIndex = newQModelIndex()
|
let parentModelIndex = newQModelIndex()
|
||||||
|
@ -182,6 +186,12 @@ QtObject:
|
||||||
|
|
||||||
return self.items[index]
|
return self.items[index]
|
||||||
|
|
||||||
|
proc isItemWithIdAdded*(self: Model, id: string): bool =
|
||||||
|
for it in self.items:
|
||||||
|
if(it.id == id):
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
proc getItemById*(self: Model, id: string): Item =
|
proc getItemById*(self: Model, id: string): Item =
|
||||||
for it in self.items:
|
for it in self.items:
|
||||||
if(it.id == id):
|
if(it.id == id):
|
||||||
|
|
|
@ -385,7 +385,8 @@ method addNewChat*(
|
||||||
communityService: community_service.Service,
|
communityService: community_service.Service,
|
||||||
messageService: message_service.Service,
|
messageService: message_service.Service,
|
||||||
gifService: gif_service.Service,
|
gifService: gif_service.Service,
|
||||||
mailserversService: mailservers_service.Service) =
|
mailserversService: mailservers_service.Service,
|
||||||
|
setChatAsActive: bool = true) =
|
||||||
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
|
||||||
var chatName = chatDto.name
|
var chatName = chatDto.name
|
||||||
|
@ -404,13 +405,14 @@ method addNewChat*(
|
||||||
if chatDto.categoryId == "":
|
if chatDto.categoryId == "":
|
||||||
let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description,
|
let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description,
|
||||||
chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
|
chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
|
||||||
blocked=false, active=false, position = 0, chatDto.categoryId)
|
blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight)
|
||||||
self.addSubmodule(chatDto.id, belongsToCommunity, isUsersListAvailable, events, settingsService, contactService, chatService,
|
self.addSubmodule(chatDto.id, belongsToCommunity, isUsersListAvailable, events, settingsService, contactService, chatService,
|
||||||
communityService, messageService, gifService, mailserversService)
|
communityService, messageService, gifService, mailserversService)
|
||||||
self.chatContentModules[chatDto.id].load()
|
self.chatContentModules[chatDto.id].load()
|
||||||
self.view.chatsModel().appendItem(item)
|
self.view.chatsModel().appendItem(item)
|
||||||
# make new added chat active one
|
# make new added chat active one
|
||||||
self.setActiveItemSubItem(item.id, "")
|
if setChatAsActive:
|
||||||
|
self.setActiveItemSubItem(item.id, "")
|
||||||
else:
|
else:
|
||||||
let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId)
|
let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId)
|
||||||
let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color,
|
let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color,
|
||||||
|
@ -422,6 +424,9 @@ method addNewChat*(
|
||||||
categoryItem.appendSubItem(channelItem)
|
categoryItem.appendSubItem(channelItem)
|
||||||
self.setActiveItemSubItem(categoryItem.id, channelItem.id)
|
self.setActiveItemSubItem(categoryItem.id, channelItem.id)
|
||||||
|
|
||||||
|
method doesChatExist*(self: Module, chatId: string): bool =
|
||||||
|
return self.view.chatsModel().isItemWithIdAdded(chatId)
|
||||||
|
|
||||||
method removeCommunityChat*(self: Module, chatId: string) =
|
method removeCommunityChat*(self: Module, chatId: string) =
|
||||||
if(not self.chatContentModules.contains(chatId)):
|
if(not self.chatContentModules.contains(chatId)):
|
||||||
return
|
return
|
||||||
|
@ -691,3 +696,20 @@ method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, p
|
||||||
|
|
||||||
method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
|
method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
|
||||||
self.view.setLoadingHistoryMessagesInProgress(isLoading)
|
self.view.setLoadingHistoryMessagesInProgress(isLoading)
|
||||||
|
|
||||||
|
method addChatIfDontExist*(self: Module,
|
||||||
|
chats: seq[ChatDto],
|
||||||
|
belongsToCommunity: bool,
|
||||||
|
events: EventEmitter,
|
||||||
|
settingsService: settings_service.ServiceInterface,
|
||||||
|
contactService: contact_service.Service,
|
||||||
|
chatService: chat_service.Service,
|
||||||
|
communityService: community_service.Service,
|
||||||
|
messageService: message_service.Service,
|
||||||
|
gifService: gif_service.Service,
|
||||||
|
mailserversService: mailservers_service.Service,
|
||||||
|
setChatAsActive: bool = true) =
|
||||||
|
for chatDto in chats:
|
||||||
|
if not self.doesChatExist(chatDto.id):
|
||||||
|
self.addNewChat(chatDto, belongsToCommunity, events, settingsService, contactService, chatService,
|
||||||
|
communityService, messageService, gifService, mailserversService, setChatAsActive)
|
||||||
|
|
|
@ -8,7 +8,24 @@ method addNewChat*(self: AccessInterface, chatDto: ChatDto, belongsToCommunity:
|
||||||
settingsService: settings_service.ServiceInterface, contactService: contact_service.Service,
|
settingsService: settings_service.ServiceInterface, contactService: contact_service.Service,
|
||||||
chatService: chat_service.Service, communityService: community_service.Service,
|
chatService: chat_service.Service, communityService: community_service.Service,
|
||||||
messageService: message_service.Service, gifService: gif_service.Service,
|
messageService: message_service.Service, gifService: gif_service.Service,
|
||||||
mailserversService: mailservers_service.Service) {.base.} =
|
mailserversService: mailservers_service.Service, setChatAsActive: bool = true) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method doesChatExist*(self: AccessInterface, chatId: string): bool {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method addChatIfDontExist*(self: AccessInterface,
|
||||||
|
chats: seq[ChatDto],
|
||||||
|
belongsToCommunity: bool,
|
||||||
|
events: EventEmitter,
|
||||||
|
settingsService: settings_service.ServiceInterface,
|
||||||
|
contactService: contact_service.Service,
|
||||||
|
chatService: chat_service.Service,
|
||||||
|
communityService: community_service.Service,
|
||||||
|
messageService: message_service.Service,
|
||||||
|
gifService: gif_service.Service,
|
||||||
|
mailserversService: mailservers_service.Service,
|
||||||
|
setChatAsActive: bool = true) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method onNewMessagesReceived*(self: AccessInterface, chatId: string, unviewedMessagesCount: int,
|
method onNewMessagesReceived*(self: AccessInterface, chatId: string, unviewedMessagesCount: int,
|
||||||
|
|
|
@ -47,6 +47,7 @@ type ChatDto* = object
|
||||||
canPost*: bool
|
canPost*: bool
|
||||||
position*: int
|
position*: int
|
||||||
categoryId*: string
|
categoryId*: string
|
||||||
|
highlight*: bool
|
||||||
|
|
||||||
proc `$`*(self: ChatDto): string =
|
proc `$`*(self: ChatDto): string =
|
||||||
result = fmt"""ChatDto(
|
result = fmt"""ChatDto(
|
||||||
|
@ -72,7 +73,8 @@ proc `$`*(self: ChatDto): string =
|
||||||
syncedTo: {self.syncedTo},
|
syncedTo: {self.syncedTo},
|
||||||
syncedFrom: {self.syncedFrom},
|
syncedFrom: {self.syncedFrom},
|
||||||
categoryId: {self.categoryId},
|
categoryId: {self.categoryId},
|
||||||
position: {self.position}
|
position: {self.position},
|
||||||
|
highlight: {self.highlight}
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
proc toChatMember(jsonObj: JsonNode): ChatMember =
|
proc toChatMember(jsonObj: JsonNode): ChatMember =
|
||||||
|
@ -103,6 +105,7 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto =
|
||||||
discard jsonObj.getProp("joined", result.joined)
|
discard jsonObj.getProp("joined", result.joined)
|
||||||
discard jsonObj.getProp("syncedTo", result.syncedTo)
|
discard jsonObj.getProp("syncedTo", result.syncedTo)
|
||||||
discard jsonObj.getProp("syncedFrom", result.syncedFrom)
|
discard jsonObj.getProp("syncedFrom", result.syncedFrom)
|
||||||
|
discard jsonObj.getProp("highlight", result.highlight)
|
||||||
|
|
||||||
result.chatType = ChatType.Unknown
|
result.chatType = ChatType.Unknown
|
||||||
var chatTypeInt: int
|
var chatTypeInt: int
|
||||||
|
|
|
@ -8,6 +8,7 @@ import ../../../backend/chat as status_chat
|
||||||
import ../../../backend/chatCommands as status_chat_commands
|
import ../../../backend/chatCommands as status_chat_commands
|
||||||
import ../../../app/global/global_singleton
|
import ../../../app/global/global_singleton
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
|
import ../../../app/core/signals/types
|
||||||
import ../../../constants
|
import ../../../constants
|
||||||
|
|
||||||
import ../../common/message as message_common
|
import ../../common/message as message_common
|
||||||
|
@ -94,7 +95,22 @@ QtObject:
|
||||||
result.contactService = contactService
|
result.contactService = contactService
|
||||||
result.chats = initTable[string, ChatDto]()
|
result.chats = initTable[string, ChatDto]()
|
||||||
|
|
||||||
|
# Forward declarations
|
||||||
|
proc updateOrAddChat*(self: Service, chat: ChatDto)
|
||||||
|
|
||||||
|
proc doConnect(self: Service) =
|
||||||
|
self.events.on(SignalType.Message.event) do(e: Args):
|
||||||
|
var receivedData = MessageSignal(e)
|
||||||
|
|
||||||
|
# Handling chat updates
|
||||||
|
if (receivedData.chats.len > 0):
|
||||||
|
for chatDto in receivedData.chats:
|
||||||
|
self.updateOrAddChat(chatDto)
|
||||||
|
self.events.emit(SIGNAL_CHAT_UPDATE, ChatUpdateArgsNew(messages: receivedData.messages, chats: receivedData.chats))
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
|
self.doConnect()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let response = status_chat.getChats()
|
let response = status_chat.getChats()
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5780f183c7b3cf63c3abbc584daa72078241e917
|
Subproject commit ccfe8cc0ff7f32993f0aef996fe45fa6960b1e3e
|
Loading…
Reference in New Issue