chore(chat/messages): extract MessageCursor

This commit is contained in:
Patryk Osmaczko 2022-12-06 18:30:00 +01:00 committed by osmaczko
parent 9601ab2668
commit 07523d2c85
2 changed files with 29 additions and 25 deletions

View File

@ -0,0 +1,26 @@
type
MessageCursor* = ref object
value: string
pending: bool
mostRecent: bool
proc initMessageCursor*(value: string, pending: bool,
mostRecent: bool): MessageCursor =
MessageCursor(value: value, pending: pending, mostRecent: mostRecent)
proc getValue*(self: MessageCursor): string =
self.value
proc setValue*(self: MessageCursor, value: string) =
if value == "" or value == self.value:
self.mostRecent = true
else:
self.value = value
self.pending = false
proc setPending*(self: MessageCursor) =
self.pending = true
proc isFetchable*(self: MessageCursor): bool =
return not (self.pending or self.mostRecent)

View File

@ -16,6 +16,7 @@ import ./dto/reaction as reaction_dto
import ../chat/dto/chat as chat_dto
import ./dto/pinned_message_update as pinned_msg_update_dto
import ./dto/removed_message as removed_msg_dto
import ./message_cursor
import ../../common/message as message_common
import ../../common/conversion as service_conversion
@ -115,29 +116,6 @@ type
ReloadMessagesArgs* = ref object of Args
communityId*: string
type
MessageCursor = ref object
value: string
pending: bool
mostRecent: bool
proc getValue*(self: MessageCursor): string =
self.value
proc setValue*(self: MessageCursor, value: string) =
if value == "" or value == self.value:
self.mostRecent = true
else:
self.value = value
self.pending = false
proc setPending*(self: MessageCursor) =
self.pending = true
proc isFetchable*(self: MessageCursor): bool =
return not (self.pending or self.mostRecent)
QtObject:
type Service* = ref object of QObject
events: EventEmitter
@ -324,12 +302,12 @@ QtObject:
proc getMessageCursor(self: Service, chatId: string): MessageCursor =
if(not self.msgCursor.hasKey(chatId)):
self.msgCursor[chatId] = MessageCursor(value: "", pending: false, mostRecent: false)
self.msgCursor[chatId] = initMessageCursor(value="", pending=false, mostRecent=false)
return self.msgCursor[chatId]
proc getPinnedMessageCursor(self: Service, chatId: string): MessageCursor =
if(not self.pinnedMsgCursor.hasKey(chatId)):
self.pinnedMsgCursor[chatId] = MessageCursor(value: "", pending: false, mostRecent: false)
self.pinnedMsgCursor[chatId] = initMessageCursor(value="", pending=false, mostRecent=false)
return self.pinnedMsgCursor[chatId]