From f90f1a326fb9e11af3dce653ce9eb286169ebc14 Mon Sep 17 00:00:00 2001 From: Alex Junior Date: Tue, 22 Mar 2022 11:29:45 -0300 Subject: [PATCH] Chore: Clean MessageErrorActions - TypeScript (#3928) --- app/containers/MessageErrorActions.tsx | 21 +++++++++++++-------- app/containers/ThreadDetails.tsx | 2 +- app/containers/message/interfaces.ts | 2 +- app/definitions/IMessage.ts | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/containers/MessageErrorActions.tsx b/app/containers/MessageErrorActions.tsx index 40b57536e..b277adac6 100644 --- a/app/containers/MessageErrorActions.tsx +++ b/app/containers/MessageErrorActions.tsx @@ -1,4 +1,5 @@ import { forwardRef, useImperativeHandle } from 'react'; +import Model from '@nozbe/watermelondb/Model'; import RocketChat from '../lib/rocketchat'; import database from '../lib/database'; @@ -6,18 +7,20 @@ import protectedFunction from '../lib/methods/helpers/protectedFunction'; import { useActionSheet } from './ActionSheet'; import I18n from '../i18n'; import log from '../utils/log'; +import { TMessageModel } from '../definitions'; -const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => { +const MessageErrorActions = forwardRef(({ tmid }: { tmid: string }, ref) => { + // TODO - remove this any after merge ActionSheet evaluate const { showActionSheet }: any = useActionSheet(); - const handleResend = protectedFunction(async (message: any) => { + const handleResend = protectedFunction(async (message: TMessageModel) => { await RocketChat.resendMessage(message, tmid); }); - const handleDelete = async (message: any) => { + const handleDelete = async (message: TMessageModel) => { try { const db = database.active; - const deleteBatch: any = []; + const deleteBatch: Model[] = []; const msgCollection = db.get('messages'); const threadCollection = db.get('threads'); @@ -38,7 +41,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => { const msg = await msgCollection.find(tmid); if (msg?.tcount && msg.tcount <= 1) { deleteBatch.push( - msg.prepareUpdate((m: any) => { + msg.prepareUpdate(m => { m.tcount = null; m.tlm = null; }) @@ -53,8 +56,10 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => { } } else { deleteBatch.push( - msg.prepareUpdate((m: any) => { - m.tcount -= 1; + msg.prepareUpdate(m => { + if (m.tcount) { + m.tcount -= 1; + } }) ); } @@ -70,7 +75,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => { } }; - const showMessageErrorActions = (message: any) => { + const showMessageErrorActions = (message: TMessageModel) => { showActionSheet({ options: [ { diff --git a/app/containers/ThreadDetails.tsx b/app/containers/ThreadDetails.tsx index 92f2aa9c2..081397ef0 100644 --- a/app/containers/ThreadDetails.tsx +++ b/app/containers/ThreadDetails.tsx @@ -52,7 +52,7 @@ interface IThreadDetails { const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style }: IThreadDetails): JSX.Element => { const { theme } = useTheme(); - let count: string | number | undefined = item.tcount; + let count: string | number | undefined | null = item.tcount; if (count && count >= 1000) { count = '+999'; } diff --git a/app/containers/message/interfaces.ts b/app/containers/message/interfaces.ts index 6930905db..8dae235ba 100644 --- a/app/containers/message/interfaces.ts +++ b/app/containers/message/interfaces.ts @@ -98,7 +98,7 @@ export interface IMessageEmoji { export interface IMessageThread { msg?: string; - tcount?: number; + tcount?: number | null; theme: string; tlm?: Date; isThreadRoom: boolean; diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 25b6385d8..4765b2ca1 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -130,8 +130,8 @@ export interface IMessage extends IMessageFromServer { dcount?: number; dlm?: string | Date; tmid?: string; - tcount?: number; - tlm?: string | Date; + tcount?: number | null; + tlm?: string | Date | null; replies?: string[]; unread?: boolean; autoTranslate?: boolean;