diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 88dd7a88d..c26a69d06 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -147,7 +147,10 @@ export interface IMessage extends IMessageFromServer { editedAt?: string | Date; } -export type TMessageModel = IMessage & Model; +export type TMessageModel = IMessage & + Model & { + asPlain?: () => IMessage; + }; export type TAnyMessageModel = TMessageModel | TThreadModel | TThreadMessageModel; export type TTypeMessages = IMessageFromServer | ILoadMoreMessage | IMessage; diff --git a/app/lib/database/model/Message.js b/app/lib/database/model/Message.js index 9592f4e60..5e452b43c 100644 --- a/app/lib/database/model/Message.js +++ b/app/lib/database/model/Message.js @@ -85,4 +85,47 @@ export default class Message extends Model { @json('md', sanitizer) md; @field('comment') comment; + + asPlain() { + return { + id: this.id, + rid: this.subscription.id, + msg: this.msg, + t: this.t, + ts: this.ts, + u: this.u, + alias: this.alias, + parseUrls: this.parseUrls, + groupable: this.groupable, + avatar: this.avatar, + emoji: this.emoji, + attachments: this.attachments, + urls: this.urls, + _updatedAt: this._updatedAt, + status: this.status, + pinned: this.pinned, + starred: this.starred, + editedBy: this.editedBy, + reactions: this.reactions, + role: this.role, + drid: this.drid, + dcount: this.dcount, + dlm: this.dlm, + tmid: this.tmid, + tcount: this.tcount, + tlm: this.tlm, + replies: this.replies, + mentions: this.mentions, + channels: this.channels, + unread: this.unread, + autoTranslate: this.autoTranslate, + translations: this.translations, + tmsg: this.tmsg, + blocks: this.blocks, + e2e: this.e2e, + tshow: this.tshow, + md: this.md, + comment: this.comment + }; + } } diff --git a/app/lib/encryption/helpers/mapMessageFromDB.ts b/app/lib/encryption/helpers/mapMessageFromDB.ts index cb3f24531..827a2c990 100644 --- a/app/lib/encryption/helpers/mapMessageFromDB.ts +++ b/app/lib/encryption/helpers/mapMessageFromDB.ts @@ -1,8 +1,7 @@ import { TMessageModel } from '../../../definitions'; -import { parseModelMessageToMessage } from './parseModelMessageToMessage'; export const mapMessageFromDB = (messageModel: TMessageModel) => { - const parsedMessage = parseModelMessageToMessage(messageModel); + const parsedMessage = messageModel.asPlain!(); return { ...parsedMessage, ts: new Date(parsedMessage.ts), diff --git a/app/lib/encryption/helpers/parseModelMessageToMessage.ts b/app/lib/encryption/helpers/parseModelMessageToMessage.ts deleted file mode 100644 index fdb8bd521..000000000 --- a/app/lib/encryption/helpers/parseModelMessageToMessage.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { IMessage, TMessageModel } from '../../../definitions'; - -export const parseModelMessageToMessage = (messageModel: TMessageModel): IMessage => - ({ - msg: messageModel.msg, - t: messageModel.t, - ts: messageModel.ts, - u: messageModel.u, - subscription: messageModel.subscription, - alias: messageModel.alias, - parseUrls: messageModel.parseUrls, - groupable: messageModel.groupable, - avatar: messageModel.avatar, - emoji: messageModel.emoji, - attachments: messageModel.attachments, - urls: messageModel.urls, - _updatedAt: messageModel._updatedAt, - status: messageModel.status, - pinned: messageModel.pinned, - starred: messageModel.starred, - editedBy: messageModel.editedBy, - reactions: messageModel.reactions, - role: messageModel.role, - drid: messageModel.drid, - dcount: messageModel.dcount, - dlm: messageModel.dlm, - tmid: messageModel.tmid, - tcount: messageModel.tcount, - tlm: messageModel.tlm, - replies: messageModel.replies, - mentions: messageModel.mentions, - channels: messageModel.channels, - unread: messageModel.unread, - autoTranslate: messageModel.autoTranslate, - translations: messageModel.translations, - tmsg: messageModel.tmsg, - blocks: messageModel.blocks, - e2e: messageModel.e2e, - tshow: messageModel.tshow, - md: messageModel.md, - comment: messageModel.comment - } as IMessage);