Chore: Clean MessageErrorActions - TypeScript (#3928)

This commit is contained in:
Alex Junior 2022-03-22 11:29:45 -03:00 committed by GitHub
parent e00580d84e
commit f90f1a326f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 12 deletions

View File

@ -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: [
{

View File

@ -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';
}

View File

@ -98,7 +98,7 @@ export interface IMessageEmoji {
export interface IMessageThread {
msg?: string;
tcount?: number;
tcount?: number | null;
theme: string;
tlm?: Date;
isThreadRoom: boolean;

View File

@ -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;