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 discard
method init*(self: Controller) = method init*(self: Controller) =
self.events.on(SIGNAL_CHAT_MUTED) do(e:Args): self.events.on(chat_service.SIGNAL_CHAT_MUTED) do(e:Args):
let args = ChatArgs(e) let args = chat_service.ChatArgs(e)
self.delegate.onChatMuted(args.chatId) self.delegate.onChatMuted(args.chatId)
self.events.on(SIGNAL_CHAT_UNMUTED) do(e:Args): self.events.on(chat_service.SIGNAL_CHAT_UNMUTED) do(e:Args):
let args = ChatArgs(e) let args = chat_service.ChatArgs(e)
self.delegate.onChatUnmuted(args.chatId) 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 = method getMySectionId*(self: Controller): string =
return self.sectionId return self.sectionId
@ -128,3 +132,6 @@ method muteChat*(self: Controller, chatId: string) =
method unmuteChat*(self: Controller, chatId: string) = 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

@ -59,3 +59,6 @@ method muteChat*(self: AccessInterface, chatId: string) {.base.} =
method unmuteChat*(self: AccessInterface, chatId: string) {.base.} = method unmuteChat*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available") 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 var found = false
if self.items[i].subItems.muteUnmuteItemById(id, mute): if self.items[i].subItems.muteUnmuteItemById(id, mute):
return 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) self.controller.unmuteChat(chatId)
method onChatMuted*(self: Module, chatId: string) = 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) = 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

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

View File

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

View File

@ -104,3 +104,6 @@ QtObject:
proc unmuteChat*(self: View, chatId: string) {.slot.} = 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 chatId*: string
messageId*: string messageId*: string
MessagesMarkedAsReadArgs = ref object of Args MessagesMarkedAsReadArgs* = ref object of Args
chatId*: string chatId*: string
allMessagesMarked*: bool allMessagesMarked*: bool
messagesIds*: seq[string] messagesIds*: seq[string]

View File

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

View File

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

View File

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