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 { forwardRef, useImperativeHandle } from 'react';
import Model from '@nozbe/watermelondb/Model';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import database from '../lib/database'; import database from '../lib/database';
@ -6,18 +7,20 @@ import protectedFunction from '../lib/methods/helpers/protectedFunction';
import { useActionSheet } from './ActionSheet'; import { useActionSheet } from './ActionSheet';
import I18n from '../i18n'; import I18n from '../i18n';
import log from '../utils/log'; 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 { showActionSheet }: any = useActionSheet();
const handleResend = protectedFunction(async (message: any) => { const handleResend = protectedFunction(async (message: TMessageModel) => {
await RocketChat.resendMessage(message, tmid); await RocketChat.resendMessage(message, tmid);
}); });
const handleDelete = async (message: any) => { const handleDelete = async (message: TMessageModel) => {
try { try {
const db = database.active; const db = database.active;
const deleteBatch: any = []; const deleteBatch: Model[] = [];
const msgCollection = db.get('messages'); const msgCollection = db.get('messages');
const threadCollection = db.get('threads'); const threadCollection = db.get('threads');
@ -38,7 +41,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => {
const msg = await msgCollection.find(tmid); const msg = await msgCollection.find(tmid);
if (msg?.tcount && msg.tcount <= 1) { if (msg?.tcount && msg.tcount <= 1) {
deleteBatch.push( deleteBatch.push(
msg.prepareUpdate((m: any) => { msg.prepareUpdate(m => {
m.tcount = null; m.tcount = null;
m.tlm = null; m.tlm = null;
}) })
@ -53,8 +56,10 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => {
} }
} else { } else {
deleteBatch.push( deleteBatch.push(
msg.prepareUpdate((m: any) => { msg.prepareUpdate(m => {
if (m.tcount) {
m.tcount -= 1; m.tcount -= 1;
}
}) })
); );
} }
@ -70,7 +75,7 @@ const MessageErrorActions = forwardRef(({ tmid }: any, ref): any => {
} }
}; };
const showMessageErrorActions = (message: any) => { const showMessageErrorActions = (message: TMessageModel) => {
showActionSheet({ showActionSheet({
options: [ options: [
{ {

View File

@ -52,7 +52,7 @@ interface IThreadDetails {
const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style }: IThreadDetails): JSX.Element => { const ThreadDetails = ({ item, user, badgeColor, toggleFollowThread, style }: IThreadDetails): JSX.Element => {
const { theme } = useTheme(); const { theme } = useTheme();
let count: string | number | undefined = item.tcount; let count: string | number | undefined | null = item.tcount;
if (count && count >= 1000) { if (count && count >= 1000) {
count = '+999'; count = '+999';
} }

View File

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

View File

@ -130,8 +130,8 @@ export interface IMessage extends IMessageFromServer {
dcount?: number; dcount?: number;
dlm?: string | Date; dlm?: string | Date;
tmid?: string; tmid?: string;
tcount?: number; tcount?: number | null;
tlm?: string | Date; tlm?: string | Date | null;
replies?: string[]; replies?: string[];
unread?: boolean; unread?: boolean;
autoTranslate?: boolean; autoTranslate?: boolean;