refactor(@chat): mark messages as read

This commit is contained in:
Anthony Laibe 2021-12-08 12:10:34 +01:00 committed by Sale Djenic
parent e5a414a927
commit 8ddda242d8
11 changed files with 53 additions and 11 deletions

View File

@ -42,14 +42,18 @@ method delete*(self: Controller) =
discard
method init*(self: Controller) =
self.events.on(SIGNAL_CHAT_MUTED) do(e:Args):
let args = ChatArgs(e)
self.events.on(chat_service.SIGNAL_CHAT_MUTED) do(e:Args):
let args = chat_service.ChatArgs(e)
self.delegate.onChatMuted(args.chatId)
self.events.on(SIGNAL_CHAT_UNMUTED) do(e:Args):
let args = ChatArgs(e)
self.events.on(chat_service.SIGNAL_CHAT_UNMUTED) do(e:Args):
let args = chat_service.ChatArgs(e)
self.delegate.onChatUnmuted(args.chatId)
self.events.on(message_service.SIGNAL_MESSAGES_MARKED_AS_READ) do(e: Args):
let args = message_service.MessagesMarkedAsReadArgs(e)
self.delegate.onMarkAllMessagesRead(args.chatId)
method getMySectionId*(self: Controller): string =
return self.sectionId
@ -127,4 +131,7 @@ method muteChat*(self: Controller, chatId: string) =
self.chatService.muteChat(chatId)
method unmuteChat*(self: Controller, chatId: string) =
self.chatService.unmuteChat(chatId)
self.chatService.unmuteChat(chatId)
method markAllMessagesRead*(self: Controller, chatId: string) =
self.messageService.markAllMessagesRead(chatId)

View File

@ -58,4 +58,7 @@ method muteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method unmuteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method markAllMessagesRead*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -192,3 +192,12 @@ QtObject:
var found = false
if self.items[i].subItems.muteUnmuteItemById(id, mute):
return
proc setHasUnreadMessage*(self: Model, id: string, value: bool) =
for i in 0 ..< self.items.len:
if(self.items[i].id == id):
let index = self.createIndex(i, 0, nil)
self.items[i].BaseItem.hasUnreadMessages = value
self.dataChanged(index, index, @[ModelRole.HasUnreadMessages.int])
return

View File

@ -286,7 +286,13 @@ method unmuteChat*(self: Module, chatId: string) =
self.controller.unmuteChat(chatId)
method onChatMuted*(self: Module, chatId: string) =
self.view.model().muteUnmuteItemOrSubItemById(chatId, true)
self.view.model().muteUnmuteItemOrSubItemById(chatId, mute=true)
method onChatUnmuted*(self: Module, chatId: string) =
self.view.model().muteUnmuteItemOrSubItemById(chatId, false)
self.view.model().muteUnmuteItemOrSubItemById(chatId, false)
method onMarkAllMessagesRead*(self: Module, chatId: string) =
self.view.model().setHasUnreadMessage(chatId, value=false)
method markAllMessagesRead*(self: Module, chatId: string) =
self.controller.markAllMessagesRead(chatId)

View File

@ -10,4 +10,7 @@ method onChatMuted*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onChatUnmuted*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onMarkAllMessagesRead*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -31,4 +31,7 @@ method muteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method unmuteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method markAllMessagesRead*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -103,4 +103,7 @@ QtObject:
self.delegate.muteChat(chatId)
proc unmuteChat*(self: View, chatId: string) {.slot.} =
self.delegate.unmuteChat(chatId)
self.delegate.unmuteChat(chatId)
proc markAllMessagesRead*(self: View, chatId: string) {.slot.} =
self.delegate.markAllMessagesRead(chatId)

View File

@ -41,7 +41,7 @@ type
chatId*: string
messageId*: string
MessagesMarkedAsReadArgs = ref object of Args
MessagesMarkedAsReadArgs* = ref object of Args
chatId*: string
allMessagesMarked*: bool
messagesIds*: seq[string]

View File

@ -25,7 +25,7 @@ StatusPopupMenu {
signal requestAllHistoricMessages(string id)
signal unmuteChat(string id)
signal muteChat(string id)
signal markAsRead(string id)
signal markAllMessagesRead(string id)
signal clearChatHistory(string id)
signal editChannel(string id)
signal downloadMessages(string file)
@ -112,7 +112,7 @@ StatusPopupMenu {
icon.name: "checkmark-circle"
enabled: root.chatType !== Constants.chatType.privateGroupChat
onTriggered: {
root.markAsRead(root.chatId)
root.markAllMessagesRead(root.chatId)
}
// Will be deleted later

View File

@ -284,6 +284,10 @@ Item {
onUnmuteChat: {
root.communitySectionModule.unmuteChat(id)
}
onMarkAllMessagesRead: {
root.communitySectionModule.markAllMessagesRead(id)
}
}
}

View File

@ -283,6 +283,10 @@ Item {
onUnmuteChat: {
root.chatSectionModule.unmuteChat(id)
}
onMarkAllMessagesRead: {
root.chatSectionModule.markAllMessagesRead(id)
}
}
}