Chore: Migrate buildMessage to TS (#3732)

* migrate buildMessage to TS

* Fix lint

* minor tweak

* minor tweaks
This commit is contained in:
Gerzon Z 2022-02-16 20:07:24 -04:00 committed by GitHub
parent 88172f0aa9
commit 86cc8a7d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 29 deletions

View File

@ -283,7 +283,7 @@ const MessageActions = React.memo(
if (!translatedMessage) {
const m = {
_id: message.id,
rid: message.subscription.id,
rid: message.subscription ? message.subscription.id : '',
u: message.u,
msg: message.msg
};

View File

@ -3,6 +3,7 @@ import { MarkdownAST } from '@rocket.chat/message-parser';
import { IAttachment } from './IAttachment';
import { IReaction } from './IReaction';
import { IUrl } from './IUrl';
export type MessageType = 'jitsi_call_started' | 'discussion-created' | 'e2e' | 'load_more' | 'rm' | 'uj';
@ -63,15 +64,15 @@ export interface IMessage {
rid: string;
msg?: string;
t?: MessageType;
ts: Date;
ts: string | Date;
u: IUserMessage;
alias: string;
parseUrls: boolean;
alias?: string;
parseUrls?: boolean;
groupable?: boolean;
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
urls?: IUrl[];
_updatedAt: Date;
status?: number;
pinned?: boolean;
@ -96,7 +97,7 @@ export interface IMessage {
e2e?: string;
tshow?: boolean;
md?: MarkdownAST;
subscription: { id: string };
subscription?: { id: string };
}
export type TMessageModel = IMessage & Model;

View File

@ -15,21 +15,21 @@ interface IFileThread {
export interface IThreadResult {
_id: string;
rid: string;
ts: string;
msg: string;
ts: string | Date;
msg?: string;
file?: IFileThread;
files?: IFileThread[];
groupable?: boolean;
attachments?: IAttachment[];
md?: MarkdownAST;
u: IUserMessage;
_updatedAt: string;
urls: IUrl[];
mentions: IUserMention[];
channels: IUserChannel[];
replies: string[];
tcount: number;
tlm: string;
_updatedAt: Date;
urls?: IUrl[];
mentions?: IUserMention[];
channels?: IUserChannel[];
replies?: string[];
tcount?: number;
tlm?: Date;
}
export interface IThread {

View File

@ -3,13 +3,15 @@ import Model from '@nozbe/watermelondb/Model';
import { IAttachment } from './IAttachment';
import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage, MessageType } from './IMessage';
import { IReaction } from './IReaction';
import { IUrl } from './IUrl';
export interface IThreadMessage {
_id: string;
tmsg?: string;
msg?: string;
t?: MessageType;
rid: string;
ts: Date;
ts: string | Date;
u: IUserMessage;
alias?: string;
parseUrls?: boolean;
@ -17,7 +19,7 @@ export interface IThreadMessage {
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
urls?: IUrl[];
_updatedAt?: Date;
status?: number;
pinned?: boolean;
@ -38,7 +40,7 @@ export interface IThreadMessage {
autoTranslate?: boolean;
translations?: ITranslations[];
e2e?: string;
subscription: { id: string };
subscription?: { id: string };
}
export type TThreadMessageModel = IThreadMessage & Model;

View File

@ -252,14 +252,17 @@ class Encryption {
toDecrypt = (await Promise.all(
toDecrypt.map(async message => {
const { t, msg, tmsg } = message;
const { id: rid } = message.subscription;
// WM Object -> Plain Object
const newMessage = await this.decryptMessage({
t,
rid,
msg,
tmsg
});
let newMessage: TMessageModel = {} as TMessageModel;
if (message.subscription) {
const { id: rid } = message.subscription;
// WM Object -> Plain Object
newMessage = await this.decryptMessage({
t,
rid,
msg,
tmsg
});
}
try {
return message.prepareUpdate(

View File

@ -1,7 +1,8 @@
import { IMessage } from '../../../definitions';
import messagesStatus from '../../../constants/messagesStatus';
import normalizeMessage from './normalizeMessage';
export default message => {
export default (message: IMessage): IMessage => {
message.status = messagesStatus.SENT;
return normalizeMessage(message);
};

View File

@ -94,7 +94,9 @@ export default async function updateMessages({
msgCollection.prepareCreate(
protectedFunction((m: TMessageModel) => {
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
m.subscription.id = sub.id;
if (m.subscription) {
m.subscription.id = sub.id;
}
Object.assign(m, message);
})
)
@ -113,7 +115,9 @@ export default async function updateMessages({
protectedFunction((tm: TThreadMessageModel) => {
tm._raw = sanitizedRaw({ id: threadMessage._id }, threadMessagesCollection.schema);
Object.assign(tm, threadMessage);
tm.subscription.id = sub.id;
if (tm.subscription) {
tm.subscription.id = sub.id;
}
if (threadMessage.tmid) {
tm.rid = threadMessage.tmid;
}

View File

@ -7,6 +7,7 @@ import isGroupChat from './isGroupChat';
type TRoomType = 'p' | 'c' | 'd';
export default async function getPermalinkMessage(message: TMessageModel): Promise<string | null> {
if (!message.subscription) return null;
let room: TSubscriptionModel;
try {
room = await getRoom(message.subscription.id);