Chore: Migrate buildMessage to TS (#3732)
* migrate buildMessage to TS * Fix lint * minor tweak * minor tweaks
This commit is contained in:
parent
88172f0aa9
commit
86cc8a7d16
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue