Added toContentType function

This commit is contained in:
Igor Sirotin 2023-05-02 17:18:52 +03:00 committed by Jonathan Rainville
parent 13bd813d52
commit ac6cebed9f
10 changed files with 45 additions and 34 deletions

View File

@ -111,7 +111,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
message.seen,
timestamp = message.timestamp,
clock = message.clock,
ContentType(message.contentType),
message.contentType,
message.messageType,
message.contactRequestState,
message.sticker.url,

View File

@ -226,7 +226,7 @@ method onSearchMessagesDone*(self: Module, messages: seq[MessageDto]) =
# Add messages
for m in messages:
if (m.contentType.ContentType != ContentType.Message):
if (m.contentType != ContentType.Message):
continue
let chatDto = self.controller.getChatDetails("", m.chatId)

View File

@ -125,7 +125,7 @@ proc createFetchMoreMessagesItem(self: Module): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1,
quotedMessageContentType = ContentType.Unknown,
quotedMessageDeleted = false,
quotedMessageDiscordMessage = DiscordMessage(),
quotedMessageAuthorDetails = ContactDetails(),
@ -184,7 +184,7 @@ proc createChatIdentifierItem(self: Module): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1,
quotedMessageContentType = ContentType.Unknown,
quotedMessageDeleted = false,
quotedMessageDiscordMessage = DiscordMessage(),
quotedMessageAuthorDetails = ContactDetails(),
@ -248,7 +248,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
var renderedMessageText = self.controller.getRenderedText(message.parsedText, communityChats)
# Add image to album if album already exists
if (message.contentType.ContentType == ContentType.Image and len(message.albumId) != 0):
if (message.contentType == ContentType.Image and len(message.albumId) != 0):
if (self.view.model().updateAlbumIfExists(message.albumId, message.image, message.id)):
continue
@ -258,7 +258,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
var transactionContract = message.transactionParameters.contract
var transactionValue = message.transactionParameters.value
var isCurrentUser = sender.isCurrentUser
if(message.contentType.ContentType == ContentType.Transaction):
if(message.contentType == ContentType.Transaction):
(transactionContract, transactionValue) = self.controller.getTransactionDetails(message)
if message.transactionParameters.fromAddress != "":
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
@ -271,7 +271,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
sender.optionalName,
sender.icon,
sender.colorHash,
(isCurrentUser and message.contentType.ContentType != ContentType.DiscordMessage),
(isCurrentUser and message.contentType != ContentType.DiscordMessage),
sender.details.added,
message.outgoingStatus,
renderedMessageText,
@ -282,7 +282,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
message.seen,
timestamp = message.timestamp,
clock = message.clock,
message.contentType.ContentType,
message.contentType,
message.messageType,
message.contactRequestState,
sticker = message.sticker.url,
@ -329,7 +329,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se
if message.editedAt != 0:
item.isEdited = true
if(message.contentType.ContentType == ContentType.Gap):
if(message.contentType == ContentType.Gap):
item.gapFrom = message.gapParameters.`from`
item.gapTo = message.gapParameters.to
@ -374,7 +374,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
var transactionContract = message.transactionParameters.contract
var transactionValue = message.transactionParameters.value
var isCurrentUser = sender.isCurrentUser
if message.contentType.ContentType == ContentType.Transaction:
if message.contentType == ContentType.Transaction:
(transactionContract, transactionValue) = self.controller.getTransactionDetails(message)
if message.transactionParameters.fromAddress != "":
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
@ -389,7 +389,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
continue
# Add image to album if album already exists
if (message.contentType.ContentType == ContentType.Image and len(message.albumId) != 0):
if (message.contentType == ContentType.Image and len(message.albumId) != 0):
if (self.view.model().updateAlbumIfExists(message.albumId, message.image, message.id)):
continue
@ -405,7 +405,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
sender.optionalName,
sender.icon,
sender.colorHash,
(isCurrentUser and message.contentType.ContentType != ContentType.DiscordMessage),
(isCurrentUser and message.contentType != ContentType.DiscordMessage),
sender.details.added,
message.outgoingStatus,
renderedMessageText,
@ -416,7 +416,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) =
message.seen,
timestamp = message.timestamp,
clock = message.clock,
message.contentType.ContentType,
message.contentType,
message.messageType,
message.contactRequestState,
sticker = message.sticker.url,

View File

@ -166,7 +166,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
var transactionContract = message.transactionParameters.contract
var transactionValue = message.transactionParameters.value
var isCurrentUser = contactDetails.isCurrentUser
if(message.contentType.ContentType == ContentType.Transaction):
if(message.contentType == ContentType.Transaction):
(transactionContract, transactionValue) = self.controller.getTransactionDetails(message)
if message.transactionParameters.fromAddress != "":
isCurrentUser = self.currentUserWalletContainsAddress(message.transactionParameters.fromAddress)
@ -190,7 +190,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
message.seen,
timestamp = message.timestamp,
clock = message.clock,
message.contentType.ContentType,
message.contentType,
message.messageType,
message.contactRequestState,
message.sticker.url,

View File

@ -942,7 +942,7 @@ method onNewMessagesReceived*(self: Module, sectionIdMsgBelongsTo: string, chatI
let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats
let renderedMessageText = self.controller.getRenderedText(message.parsedText, communityChats)
var plainText = singletonInstance.utils.plainText(renderedMessageText)
if ContentType(message.contentType) == ContentType.Sticker or (ContentType(message.contentType) == ContentType.Image and len(plainText) == 0):
if message.contentType == ContentType.Sticker or (message.contentType == ContentType.Image and len(plainText) == 0):
plainText = "🖼️"
var notificationTitle = contactDetails.defaultDisplayName

View File

@ -51,7 +51,7 @@ type
quotedMessageFrom: string
quotedMessageText: string
quotedMessageParsedText: string
quotedMessageContentType: int
quotedMessageContentType: ContentType
quotedMessageDeleted: bool
quotedMessageAuthorDisplayName: string
quotedMessageAuthorAvatar: string
@ -97,7 +97,7 @@ proc initItem*(
quotedMessageFrom: string,
quotedMessageText: string,
quotedMessageParsedText: string,
quotedMessageContentType: int,
quotedMessageContentType: ContentType,
quotedMessageDeleted: bool,
quotedMessageDiscordMessage: DiscordMessage,
quotedMessageAuthorDetails: ContactDetails,
@ -156,7 +156,7 @@ proc initItem*(
result.albumMessageIds = albumMessageIds
result.albumImagesCount = albumImagesCount
if quotedMessageContentType == ContentType.DiscordMessage.int:
if quotedMessageContentType == ContentType.DiscordMessage:
result.quotedMessageAuthorDisplayName = quotedMessageDiscordMessage.author.name
result.quotedMessageAuthorAvatar = quotedMessageDiscordMessage.author.localUrl
if result.quotedMessageAuthorAvatar == "":
@ -222,7 +222,7 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
quotedMessageFrom = "",
quotedMessageText = "",
quotedMessageParsedText = "",
quotedMessageContentType = -1,
quotedMessageContentType = ContentType.Unknown,
quotedMessageDeleted = false,
quotedMessageDiscordMessage = DiscordMessage(),
quotedMessageAuthorDetails = ContactDetails(),
@ -250,7 +250,7 @@ proc `$`*(self: Item): string =
parsedText:{$self.parsedText},
messageContainsMentions:{self.messageContainsMentions},
timestamp:{$self.timestamp},
contentType:{$self.contentType.int},
contentType:{$self.contentType},
messageType:{$self.messageType},
contactRequestState:{$self.contactRequestState},
pinned:{$self.pinned},
@ -491,7 +491,7 @@ proc toJsonNode*(self: Item): JsonNode =
"quotedMessageFrom": self.quotedMessageFrom,
"quotedMessageText": self.quotedMessageText,
"quotedMessageParsedText": self.quotedMessageParsedText,
"quotedMessageContentType": self.quotedMessageContentType,
"quotedMessageContentType": self.quotedMessageContentType.int,
"quotedMessageDeleted": self.quotedMessageDeleted,
"quotedMessageAuthorDisplayName": self.quotedMessageAuthorDisplayName,
"quotedMessageAuthorAvatar": self.quotedMessageAuthorAvatar,
@ -546,9 +546,9 @@ proc quotedMessageParsedText*(self: Item): string {.inline.} =
proc `quotedMessageParsedText=`*(self: Item, value: string) {.inline.} =
self.quotedMessageParsedText = value
proc quotedMessageContentType*(self: Item): int {.inline.} =
proc quotedMessageContentType*(self: Item): ContentType {.inline.} =
self.quotedMessageContentType
proc `quotedMessageContentType=`*(self: Item, value: int) {.inline.} =
proc `quotedMessageContentType=`*(self: Item, value: ContentType) {.inline.} =
self.quotedMessageContentType = value
proc quotedMessageDeleted*(self: Item): bool {.inline.} =

View File

@ -42,7 +42,7 @@ QtObject:
QtProperty[string] quotedMessageParsedText:
read = quotedMessageParsedText
proc quotedMessageContentType*(self: MessageItem): int {.slot.} = result = ?.self.messageItem.quotedMessageContentType
proc quotedMessageContentType*(self: MessageItem): int {.slot.} = result = ?.self.messageItem.quotedMessageContentType.int
QtProperty[int] quotedMessageContentType:
read = quotedMessageContentType

View File

@ -243,7 +243,7 @@ QtObject:
of ModelRole.QuotedMessageParsedText:
result = newQVariant(item.quotedMessageParsedText)
of ModelRole.QuotedMessageContentType:
result = newQVariant(item.quotedMessageContentType)
result = newQVariant(item.quotedMessageContentType.int)
of ModelRole.QuotedMessageDeleted:
result = newQVariant(item.quotedMessageDeleted)
of ModelRole.QuotedMessageAuthorName:
@ -360,7 +360,7 @@ QtObject:
oldItem.quotedMessageAuthorAvatar = newItem.senderIcon
oldItem.quotedMessageParsedText = newItem.messageText
oldItem.quotedMessageText = newItem.unparsedText
oldItem.quotedMessageContentType = newItem.contentType.int
oldItem.quotedMessageContentType = newItem.contentType
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, @[
ModelRole.QuotedMessageFrom.int,
@ -603,7 +603,7 @@ QtObject:
updatedMsg: string,
updatedRawMsg: string,
updatedParsedText: seq[ParsedText],
contentType: int,
contentType: ContentType,
mentioned: bool,
messageContainsMentions: bool,
links: seq[string],
@ -755,4 +755,4 @@ QtObject:
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, @[ModelRole.AlbumMessageImages.int])
return true
return false
return false

View File

@ -20,6 +20,12 @@ type
# Local only
SystemMessagePinnedMessage = 14
proc toContentType*(value: int): ContentType =
try:
return ContentType(value)
except RangeDefect:
return ContentType.Unknown
type
StatusType* {.pure.} = enum
Unknown = 0

View File

@ -1,6 +1,7 @@
{.used.}
import json, strutils
import ../../../common/types
include ../../../common/json_utils
@ -59,7 +60,7 @@ type QuotedMessage* = object
`from`*: string
text*: string
parsedText*: seq[ParsedText]
contentType*: int
contentType*: ContentType
deleted*: bool
discordMessage*: DiscordMessage
@ -107,7 +108,7 @@ type MessageDto* = object
albumImagesCount*: int
gapParameters*: GapParameters
timestamp*: int64
contentType*: int
contentType*: ContentType
messageType*: int
contactRequestState*: int
links*: seq[string]
@ -138,7 +139,7 @@ proc toDiscordMessageAuthor*(jsonObj: JsonNode): DiscordMessageAuthor =
discard jsonObj.getProp("localUrl", result.localUrl)
proc toDiscordMessageAttachment*(jsonObj: JsonNOde): DiscordMessageAttachment =
proc toDiscordMessageAttachment*(jsonObj: JsonNode): DiscordMessageAttachment =
result = DiscordMessageAttachment()
discard jsonObj.getProp("id", result.id)
discard jsonObj.getProp("url", result.fileUrl)
@ -166,9 +167,11 @@ proc toDiscordMessage*(jsonObj: JsonNode): DiscordMessage =
proc toQuotedMessage*(jsonObj: JsonNode): QuotedMessage =
result = QuotedMessage()
var contentType: int
discard jsonObj.getProp("from", result.`from`)
discard jsonObj.getProp("text", result.text)
discard jsonObj.getProp("contentType", result.contentType)
discard jsonObj.getProp("contentType", contentType)
result.contentType = toContentType(contentType)
discard jsonObj.getProp("deleted", result.deleted)
var parsedTextArr: JsonNode
@ -204,6 +207,7 @@ proc toTransactionParameters*(jsonObj: JsonNode): TransactionParameters =
proc toMessageDto*(jsonObj: JsonNode): MessageDto =
result = MessageDto()
var contentType: int
discard jsonObj.getProp("id", result.id)
discard jsonObj.getProp("communityId", result.communityId)
discard jsonObj.getProp("from", result.from)
@ -220,7 +224,8 @@ proc toMessageDto*(jsonObj: JsonNode): MessageDto =
discard jsonObj.getProp("responseTo", result.responseTo)
discard jsonObj.getProp("ensName", result.ensName)
discard jsonObj.getProp("timestamp", result.timestamp)
discard jsonObj.getProp("contentType", result.contentType)
discard jsonObj.getProp("contentType", contentType)
result.contentType = toContentType(contentType)
discard jsonObj.getProp("messageType", result.messageType)
discard jsonObj.getProp("contactRequestState", result.contactRequestState)
discard jsonObj.getProp("image", result.image)