[IMPROVE] - creating an Message type file

This commit is contained in:
Alex Junior 2021-08-01 23:33:36 -03:00
parent 757347fa29
commit 20d7b6a051
11 changed files with 137 additions and 125 deletions

View File

@ -1,22 +1,16 @@
import React from 'react';
import { dequal } from 'dequal';
import {TMessageAttachments} from "./types";
import Image from './Image';
import Audio from './Audio';
import Video from './Video';
import Reply from './Reply';
export interface IMessageAttachments {
attachments: any;
timeFormat: string;
showAttachment: Function;
getCustomEmoji: Function;
theme: string;
}
const Attachments = React.memo(({
attachments, timeFormat, showAttachment, getCustomEmoji, theme
}: IMessageAttachments) => {
}: TMessageAttachments) => {
if (!attachments || attachments.length === 0) {
return null;
}

View File

@ -1,14 +1,8 @@
import React from 'react';
import { messageBlockWithContext } from '../UIKit/MessageBlock';
import {TMessageBlocks} from "./types";
export interface IMessageBlocks {
blocks: any;
id: string;
rid: string;
blockAction: Function;
}
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: IMessageBlocks) => {
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: TMessageBlocks) => {
if (blocks && blocks.length > 0) {
const appId = blocks[0]?.appId || '';
return React.createElement(

View File

@ -8,16 +8,9 @@ import { BUTTON_HIT_SLOP } from './utils';
import I18n from '../../i18n';
import { themes } from '../../constants/colors';
import MessageContext from './Context';
import {TMessageBroadcast} from "./types";
export interface IMessageBroadcast {
author: {
_id: string
};
broadcast: boolean;
theme: string
}
const Broadcast = React.memo(({ author, broadcast, theme }: IMessageBroadcast) => {
const Broadcast = React.memo(({ author, broadcast, theme }: TMessageBroadcast) => {
const { user, replyBroadcast } = useContext(MessageContext);
const isOwn = author._id === user.id;
if (broadcast && !isOwn) {

View File

@ -7,13 +7,9 @@ import styles from './styles';
import I18n from '../../i18n';
import { CustomIcon } from '../../lib/Icons';
import { themes } from '../../constants/colors';
import {TMessageCallButton} from "./types";
export interface IMessageCallButton {
theme: string;
callJitsi: Function;
}
const CallButton = React.memo(({ theme, callJitsi }: IMessageCallButton) => (
const CallButton = React.memo(({ theme, callJitsi }: TMessageCallButton) => (
<View style={styles.buttonContainer}>
<Touchable
onPress={callJitsi}

View File

@ -11,27 +11,9 @@ import { themes } from '../../constants/colors';
import MessageContext from './Context';
import Encrypted from './Encrypted';
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
import {TChannel} from "../markdown/Hashtag";
import {TMessageContent} from "./types";
export interface IMessageContent {
isTemp: boolean;
isInfo: boolean;
tmid: string;
isThreadRoom: boolean;
msg: string;
theme: string;
isEdited: boolean;
isEncrypted: boolean;
getCustomEmoji: Function;
channels: TChannel[];
mentions: object[];
navToRoomInfo: Function;
useRealName: boolean;
isIgnored: boolean;
type: string;
}
const Content = React.memo((props: IMessageContent) => {
const Content = React.memo((props: TMessageContent) => {
if (props.isInfo) {
// @ts-ignore
const infoMessage = getInfoMessage({ ...props });

View File

@ -10,15 +10,10 @@ import { DISCUSSION } from './constants';
import { themes } from '../../constants/colors';
import MessageContext from './Context';
import { formatDateThreads } from '../../utils/room';
import {TMessageDiscussion} from "./types";
export interface IMessageDiscussion {
msg: string;
dcount: number;
dlm: string;
theme: string;
}
const Discussion = React.memo(({ msg, dcount, dlm, theme }: IMessageDiscussion) => {
const Discussion = React.memo(({ msg, dcount, dlm, theme }: TMessageDiscussion) => {
let time;
if (dlm) {
time = formatDateThreads(dlm);

View File

@ -6,41 +6,20 @@ import MessageContext from './Context';
import User from './User';
import styles from './styles';
import RepliedThread, {IMessageRepliedThread} from './RepliedThread';
import MessageAvatar, {IMessageAvatar} from './MessageAvatar';
import Attachments, {IMessageAttachments} from './Attachments';
import RepliedThread from './RepliedThread';
import MessageAvatar from './MessageAvatar';
import Attachments from './Attachments';
import Urls from './Urls';
import Thread, {IMessageThread} from './Thread';
import Blocks, {IMessageBlocks} from './Blocks';
import Thread from './Thread';
import Blocks from './Blocks';
import Reactions from './Reactions';
import Broadcast, {IMessageBroadcast} from './Broadcast';
import Discussion, {IMessageDiscussion} from './Discussion';
import Content, {IMessageContent} from './Content';
import Broadcast from './Broadcast';
import Discussion from './Discussion';
import Content from './Content';
import ReadReceipt from './ReadReceipt';
import CallButton, {IMessageCallButton} from './CallButton';
import CallButton from './CallButton';
import { themes } from '../../constants/colors';
type TMessageInner = {
type: string;
blocks: [];
} & IMessageDiscussion & IMessageContent & IMessageCallButton & IMessageBlocks
& IMessageThread & IMessageAttachments & IMessageBroadcast;
type TMessage = {
isThreadReply: boolean;
isThreadSequential: boolean;
isInfo: boolean;
isTemp: boolean;
isHeader: boolean;
hasError: boolean;
style: any;
onLongPress: Function;
isReadReceiptEnabled: boolean;
unread: boolean;
theme: string;
isIgnored: boolean;
} & IMessageRepliedThread & IMessageAvatar & IMessageContent & TMessageInner;
import {TMessage, TMessageInner} from "./types";
interface IMessageTouchable {
hasError: boolean;

View File

@ -3,24 +3,11 @@ import React, { useContext } from 'react';
import Avatar from '../Avatar';
import styles from './styles';
import MessageContext from './Context';
export interface IMessageAvatar {
isHeader: boolean;
avatar: string;
emoji: string;
author: {
username: string
_id: string;
};
small?: boolean;
navToRoomInfo: Function;
getCustomEmoji(): void;
theme: string;
}
import {TMessageAvatar} from "./types";
const MessageAvatar = React.memo(({
isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji, theme
}: IMessageAvatar) => {
}: TMessageAvatar) => {
const { user } = useContext(MessageContext);
if (isHeader && author) {
const navParam = {

View File

@ -6,20 +6,12 @@ import styles from './styles';
import { themes } from '../../constants/colors';
import I18n from '../../i18n';
import Markdown from '../markdown';
import {TMessageRepliedThread} from "./types";
export interface IMessageRepliedThread {
tmid: string;
tmsg: string;
id: string;
isHeader: boolean;
theme: string;
fetchThreadName: Function;
isEncrypted: boolean;
}
const RepliedThread = memo(({
tmid, tmsg, isHeader, fetchThreadName, id, isEncrypted, theme
}: IMessageRepliedThread) => {
}: TMessageRepliedThread) => {
if (!tmid || !isHeader) {
return null;
}

View File

@ -6,17 +6,9 @@ import { themes } from '../../constants/colors';
import MessageContext from './Context';
import ThreadDetails from '../ThreadDetails';
import I18n from '../../i18n';
import {TMessageThread} from "./types";
export interface IMessageThread {
msg: string;
tcount: number;
theme: string;
tlm: string;
isThreadRoom: boolean;
id: string;
}
const Thread = React.memo(({ msg, tcount, tlm, isThreadRoom, theme, id }: IMessageThread) => {
const Thread = React.memo(({ msg, tcount, tlm, isThreadRoom, theme, id }: TMessageThread) => {
if (!tlm || isThreadRoom || tcount === 0) {
return null;
}

View File

@ -0,0 +1,108 @@
import {TChannel} from "../markdown/Hashtag";
export type TMessageAttachments = {
attachments: any;
timeFormat: string;
showAttachment: Function;
getCustomEmoji: Function;
theme: string;
}
export type TMessageAvatar = {
isHeader: boolean;
avatar: string;
emoji: string;
author: {
username: string
_id: string;
};
small?: boolean;
navToRoomInfo: Function;
getCustomEmoji(): void;
theme: string;
}
export type TMessageBlocks = {
blocks: any;
id: string;
rid: string;
blockAction: Function;
}
export type TMessageBroadcast = {
author: {
_id: string
};
broadcast: boolean;
theme: string
}
export type TMessageCallButton = {
theme: string;
callJitsi: Function;
}
export type TMessageContent = {
isTemp: boolean;
isInfo: boolean;
tmid: string;
isThreadRoom: boolean;
msg: string;
theme: string;
isEdited: boolean;
isEncrypted: boolean;
getCustomEmoji: Function;
channels: TChannel[];
mentions: object[];
navToRoomInfo: Function;
useRealName: boolean;
isIgnored: boolean;
type: string;
}
export type TMessageDiscussion = {
msg: string;
dcount: number;
dlm: string;
theme: string;
}
export type TMessageThread = {
msg: string;
tcount: number;
theme: string;
tlm: string;
isThreadRoom: boolean;
id: string;
}
export type TMessageRepliedThread = {
tmid: string;
tmsg: string;
id: string;
isHeader: boolean;
theme: string;
fetchThreadName: Function;
isEncrypted: boolean;
}
export type TMessageInner = {
type: string;
blocks: [];
} & TMessageDiscussion & TMessageContent & TMessageCallButton & TMessageBlocks
& TMessageThread & TMessageAttachments & TMessageBroadcast;
export type TMessage = {
isThreadReply: boolean;
isThreadSequential: boolean;
isInfo: boolean;
isTemp: boolean;
isHeader: boolean;
hasError: boolean;
style: any;
onLongPress: Function;
isReadReceiptEnabled: boolean;
unread: boolean;
theme: string;
isIgnored: boolean;
} & TMessageRepliedThread & TMessageAvatar & TMessageContent & TMessageInner;