chore(chat/messages): extract MessageCursor
This commit is contained in:
parent
9601ab2668
commit
07523d2c85
|
@ -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)
|
|
@ -16,6 +16,7 @@ import ./dto/reaction as reaction_dto
|
||||||
import ../chat/dto/chat as chat_dto
|
import ../chat/dto/chat as chat_dto
|
||||||
import ./dto/pinned_message_update as pinned_msg_update_dto
|
import ./dto/pinned_message_update as pinned_msg_update_dto
|
||||||
import ./dto/removed_message as removed_msg_dto
|
import ./dto/removed_message as removed_msg_dto
|
||||||
|
import ./message_cursor
|
||||||
|
|
||||||
import ../../common/message as message_common
|
import ../../common/message as message_common
|
||||||
import ../../common/conversion as service_conversion
|
import ../../common/conversion as service_conversion
|
||||||
|
@ -115,29 +116,6 @@ type
|
||||||
ReloadMessagesArgs* = ref object of Args
|
ReloadMessagesArgs* = ref object of Args
|
||||||
communityId*: string
|
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:
|
QtObject:
|
||||||
type Service* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
events: EventEmitter
|
events: EventEmitter
|
||||||
|
@ -324,12 +302,12 @@ QtObject:
|
||||||
|
|
||||||
proc getMessageCursor(self: Service, chatId: string): MessageCursor =
|
proc getMessageCursor(self: Service, chatId: string): MessageCursor =
|
||||||
if(not self.msgCursor.hasKey(chatId)):
|
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]
|
return self.msgCursor[chatId]
|
||||||
|
|
||||||
proc getPinnedMessageCursor(self: Service, chatId: string): MessageCursor =
|
proc getPinnedMessageCursor(self: Service, chatId: string): MessageCursor =
|
||||||
if(not self.pinnedMsgCursor.hasKey(chatId)):
|
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]
|
return self.pinnedMsgCursor[chatId]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue