Unverified Commit f90f1a32 authored by Alex Junior's avatar Alex Junior Committed by GitHub
Browse files

Chore: Clean MessageErrorActions - TypeScript (#3928)

parent e00580d8
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: [
{
......
......@@ -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';
}
......
......@@ -98,7 +98,7 @@ export interface IMessageEmoji {
export interface IMessageThread {
msg?: string;
tcount?: number;
tcount?: number | null;
theme: string;
tlm?: Date;
isThreadRoom: boolean;
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment