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) {
|
if (!translatedMessage) {
|
||||||
const m = {
|
const m = {
|
||||||
_id: message.id,
|
_id: message.id,
|
||||||
rid: message.subscription.id,
|
rid: message.subscription ? message.subscription.id : '',
|
||||||
u: message.u,
|
u: message.u,
|
||||||
msg: message.msg
|
msg: message.msg
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { MarkdownAST } from '@rocket.chat/message-parser';
|
||||||
|
|
||||||
import { IAttachment } from './IAttachment';
|
import { IAttachment } from './IAttachment';
|
||||||
import { IReaction } from './IReaction';
|
import { IReaction } from './IReaction';
|
||||||
|
import { IUrl } from './IUrl';
|
||||||
|
|
||||||
export type MessageType = 'jitsi_call_started' | 'discussion-created' | 'e2e' | 'load_more' | 'rm' | 'uj';
|
export type MessageType = 'jitsi_call_started' | 'discussion-created' | 'e2e' | 'load_more' | 'rm' | 'uj';
|
||||||
|
|
||||||
|
@ -63,15 +64,15 @@ export interface IMessage {
|
||||||
rid: string;
|
rid: string;
|
||||||
msg?: string;
|
msg?: string;
|
||||||
t?: MessageType;
|
t?: MessageType;
|
||||||
ts: Date;
|
ts: string | Date;
|
||||||
u: IUserMessage;
|
u: IUserMessage;
|
||||||
alias: string;
|
alias?: string;
|
||||||
parseUrls: boolean;
|
parseUrls?: boolean;
|
||||||
groupable?: boolean;
|
groupable?: boolean;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
emoji?: string;
|
emoji?: string;
|
||||||
attachments?: IAttachment[];
|
attachments?: IAttachment[];
|
||||||
urls?: string[];
|
urls?: IUrl[];
|
||||||
_updatedAt: Date;
|
_updatedAt: Date;
|
||||||
status?: number;
|
status?: number;
|
||||||
pinned?: boolean;
|
pinned?: boolean;
|
||||||
|
@ -96,7 +97,7 @@ export interface IMessage {
|
||||||
e2e?: string;
|
e2e?: string;
|
||||||
tshow?: boolean;
|
tshow?: boolean;
|
||||||
md?: MarkdownAST;
|
md?: MarkdownAST;
|
||||||
subscription: { id: string };
|
subscription?: { id: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TMessageModel = IMessage & Model;
|
export type TMessageModel = IMessage & Model;
|
||||||
|
|
|
@ -15,21 +15,21 @@ interface IFileThread {
|
||||||
export interface IThreadResult {
|
export interface IThreadResult {
|
||||||
_id: string;
|
_id: string;
|
||||||
rid: string;
|
rid: string;
|
||||||
ts: string;
|
ts: string | Date;
|
||||||
msg: string;
|
msg?: string;
|
||||||
file?: IFileThread;
|
file?: IFileThread;
|
||||||
files?: IFileThread[];
|
files?: IFileThread[];
|
||||||
groupable?: boolean;
|
groupable?: boolean;
|
||||||
attachments?: IAttachment[];
|
attachments?: IAttachment[];
|
||||||
md?: MarkdownAST;
|
md?: MarkdownAST;
|
||||||
u: IUserMessage;
|
u: IUserMessage;
|
||||||
_updatedAt: string;
|
_updatedAt: Date;
|
||||||
urls: IUrl[];
|
urls?: IUrl[];
|
||||||
mentions: IUserMention[];
|
mentions?: IUserMention[];
|
||||||
channels: IUserChannel[];
|
channels?: IUserChannel[];
|
||||||
replies: string[];
|
replies?: string[];
|
||||||
tcount: number;
|
tcount?: number;
|
||||||
tlm: string;
|
tlm?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IThread {
|
export interface IThread {
|
||||||
|
|
|
@ -3,13 +3,15 @@ import Model from '@nozbe/watermelondb/Model';
|
||||||
import { IAttachment } from './IAttachment';
|
import { IAttachment } from './IAttachment';
|
||||||
import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage, MessageType } from './IMessage';
|
import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage, MessageType } from './IMessage';
|
||||||
import { IReaction } from './IReaction';
|
import { IReaction } from './IReaction';
|
||||||
|
import { IUrl } from './IUrl';
|
||||||
|
|
||||||
export interface IThreadMessage {
|
export interface IThreadMessage {
|
||||||
|
_id: string;
|
||||||
tmsg?: string;
|
tmsg?: string;
|
||||||
msg?: string;
|
msg?: string;
|
||||||
t?: MessageType;
|
t?: MessageType;
|
||||||
rid: string;
|
rid: string;
|
||||||
ts: Date;
|
ts: string | Date;
|
||||||
u: IUserMessage;
|
u: IUserMessage;
|
||||||
alias?: string;
|
alias?: string;
|
||||||
parseUrls?: boolean;
|
parseUrls?: boolean;
|
||||||
|
@ -17,7 +19,7 @@ export interface IThreadMessage {
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
emoji?: string;
|
emoji?: string;
|
||||||
attachments?: IAttachment[];
|
attachments?: IAttachment[];
|
||||||
urls?: string[];
|
urls?: IUrl[];
|
||||||
_updatedAt?: Date;
|
_updatedAt?: Date;
|
||||||
status?: number;
|
status?: number;
|
||||||
pinned?: boolean;
|
pinned?: boolean;
|
||||||
|
@ -38,7 +40,7 @@ export interface IThreadMessage {
|
||||||
autoTranslate?: boolean;
|
autoTranslate?: boolean;
|
||||||
translations?: ITranslations[];
|
translations?: ITranslations[];
|
||||||
e2e?: string;
|
e2e?: string;
|
||||||
subscription: { id: string };
|
subscription?: { id: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TThreadMessageModel = IThreadMessage & Model;
|
export type TThreadMessageModel = IThreadMessage & Model;
|
||||||
|
|
|
@ -252,14 +252,17 @@ class Encryption {
|
||||||
toDecrypt = (await Promise.all(
|
toDecrypt = (await Promise.all(
|
||||||
toDecrypt.map(async message => {
|
toDecrypt.map(async message => {
|
||||||
const { t, msg, tmsg } = message;
|
const { t, msg, tmsg } = message;
|
||||||
const { id: rid } = message.subscription;
|
let newMessage: TMessageModel = {} as TMessageModel;
|
||||||
// WM Object -> Plain Object
|
if (message.subscription) {
|
||||||
const newMessage = await this.decryptMessage({
|
const { id: rid } = message.subscription;
|
||||||
t,
|
// WM Object -> Plain Object
|
||||||
rid,
|
newMessage = await this.decryptMessage({
|
||||||
msg,
|
t,
|
||||||
tmsg
|
rid,
|
||||||
});
|
msg,
|
||||||
|
tmsg
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return message.prepareUpdate(
|
return message.prepareUpdate(
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { IMessage } from '../../../definitions';
|
||||||
import messagesStatus from '../../../constants/messagesStatus';
|
import messagesStatus from '../../../constants/messagesStatus';
|
||||||
import normalizeMessage from './normalizeMessage';
|
import normalizeMessage from './normalizeMessage';
|
||||||
|
|
||||||
export default message => {
|
export default (message: IMessage): IMessage => {
|
||||||
message.status = messagesStatus.SENT;
|
message.status = messagesStatus.SENT;
|
||||||
return normalizeMessage(message);
|
return normalizeMessage(message);
|
||||||
};
|
};
|
|
@ -94,7 +94,9 @@ export default async function updateMessages({
|
||||||
msgCollection.prepareCreate(
|
msgCollection.prepareCreate(
|
||||||
protectedFunction((m: TMessageModel) => {
|
protectedFunction((m: TMessageModel) => {
|
||||||
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
|
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);
|
Object.assign(m, message);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -113,7 +115,9 @@ export default async function updateMessages({
|
||||||
protectedFunction((tm: TThreadMessageModel) => {
|
protectedFunction((tm: TThreadMessageModel) => {
|
||||||
tm._raw = sanitizedRaw({ id: threadMessage._id }, threadMessagesCollection.schema);
|
tm._raw = sanitizedRaw({ id: threadMessage._id }, threadMessagesCollection.schema);
|
||||||
Object.assign(tm, threadMessage);
|
Object.assign(tm, threadMessage);
|
||||||
tm.subscription.id = sub.id;
|
if (tm.subscription) {
|
||||||
|
tm.subscription.id = sub.id;
|
||||||
|
}
|
||||||
if (threadMessage.tmid) {
|
if (threadMessage.tmid) {
|
||||||
tm.rid = threadMessage.tmid;
|
tm.rid = threadMessage.tmid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import isGroupChat from './isGroupChat';
|
||||||
type TRoomType = 'p' | 'c' | 'd';
|
type TRoomType = 'p' | 'c' | 'd';
|
||||||
|
|
||||||
export default async function getPermalinkMessage(message: TMessageModel): Promise<string | null> {
|
export default async function getPermalinkMessage(message: TMessageModel): Promise<string | null> {
|
||||||
|
if (!message.subscription) return null;
|
||||||
let room: TSubscriptionModel;
|
let room: TSubscriptionModel;
|
||||||
try {
|
try {
|
||||||
room = await getRoom(message.subscription.id);
|
room = await getRoom(message.subscription.id);
|
||||||
|
|
Loading…
Reference in New Issue