[IMPROVE] - creating an Message type file
This commit is contained in:
parent
757347fa29
commit
20d7b6a051
|
@ -1,22 +1,16 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
|
|
||||||
|
import {TMessageAttachments} from "./types";
|
||||||
|
|
||||||
import Image from './Image';
|
import Image from './Image';
|
||||||
import Audio from './Audio';
|
import Audio from './Audio';
|
||||||
import Video from './Video';
|
import Video from './Video';
|
||||||
import Reply from './Reply';
|
import Reply from './Reply';
|
||||||
|
|
||||||
export interface IMessageAttachments {
|
|
||||||
attachments: any;
|
|
||||||
timeFormat: string;
|
|
||||||
showAttachment: Function;
|
|
||||||
getCustomEmoji: Function;
|
|
||||||
theme: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Attachments = React.memo(({
|
const Attachments = React.memo(({
|
||||||
attachments, timeFormat, showAttachment, getCustomEmoji, theme
|
attachments, timeFormat, showAttachment, getCustomEmoji, theme
|
||||||
}: IMessageAttachments) => {
|
}: TMessageAttachments) => {
|
||||||
if (!attachments || attachments.length === 0) {
|
if (!attachments || attachments.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { messageBlockWithContext } from '../UIKit/MessageBlock';
|
import { messageBlockWithContext } from '../UIKit/MessageBlock';
|
||||||
|
import {TMessageBlocks} from "./types";
|
||||||
|
|
||||||
export interface IMessageBlocks {
|
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: TMessageBlocks) => {
|
||||||
blocks: any;
|
|
||||||
id: string;
|
|
||||||
rid: string;
|
|
||||||
blockAction: Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Blocks = React.memo(({ blocks, id: mid, rid, blockAction }: IMessageBlocks) => {
|
|
||||||
if (blocks && blocks.length > 0) {
|
if (blocks && blocks.length > 0) {
|
||||||
const appId = blocks[0]?.appId || '';
|
const appId = blocks[0]?.appId || '';
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
|
|
|
@ -8,16 +8,9 @@ import { BUTTON_HIT_SLOP } from './utils';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
|
import {TMessageBroadcast} from "./types";
|
||||||
|
|
||||||
export interface IMessageBroadcast {
|
const Broadcast = React.memo(({ author, broadcast, theme }: TMessageBroadcast) => {
|
||||||
author: {
|
|
||||||
_id: string
|
|
||||||
};
|
|
||||||
broadcast: boolean;
|
|
||||||
theme: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const Broadcast = React.memo(({ author, broadcast, theme }: IMessageBroadcast) => {
|
|
||||||
const { user, replyBroadcast } = useContext(MessageContext);
|
const { user, replyBroadcast } = useContext(MessageContext);
|
||||||
const isOwn = author._id === user.id;
|
const isOwn = author._id === user.id;
|
||||||
if (broadcast && !isOwn) {
|
if (broadcast && !isOwn) {
|
||||||
|
|
|
@ -7,13 +7,9 @@ import styles from './styles';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { CustomIcon } from '../../lib/Icons';
|
import { CustomIcon } from '../../lib/Icons';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
|
import {TMessageCallButton} from "./types";
|
||||||
|
|
||||||
export interface IMessageCallButton {
|
const CallButton = React.memo(({ theme, callJitsi }: TMessageCallButton) => (
|
||||||
theme: string;
|
|
||||||
callJitsi: Function;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CallButton = React.memo(({ theme, callJitsi }: IMessageCallButton) => (
|
|
||||||
<View style={styles.buttonContainer}>
|
<View style={styles.buttonContainer}>
|
||||||
<Touchable
|
<Touchable
|
||||||
onPress={callJitsi}
|
onPress={callJitsi}
|
||||||
|
|
|
@ -11,27 +11,9 @@ import { themes } from '../../constants/colors';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
import Encrypted from './Encrypted';
|
import Encrypted from './Encrypted';
|
||||||
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
|
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
|
||||||
import {TChannel} from "../markdown/Hashtag";
|
import {TMessageContent} from "./types";
|
||||||
|
|
||||||
export interface IMessageContent {
|
const Content = React.memo((props: 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Content = React.memo((props: IMessageContent) => {
|
|
||||||
if (props.isInfo) {
|
if (props.isInfo) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const infoMessage = getInfoMessage({ ...props });
|
const infoMessage = getInfoMessage({ ...props });
|
||||||
|
|
|
@ -10,15 +10,10 @@ import { DISCUSSION } from './constants';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
import { formatDateThreads } from '../../utils/room';
|
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;
|
let time;
|
||||||
if (dlm) {
|
if (dlm) {
|
||||||
time = formatDateThreads(dlm);
|
time = formatDateThreads(dlm);
|
||||||
|
|
|
@ -6,41 +6,20 @@ import MessageContext from './Context';
|
||||||
|
|
||||||
import User from './User';
|
import User from './User';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import RepliedThread, {IMessageRepliedThread} from './RepliedThread';
|
import RepliedThread from './RepliedThread';
|
||||||
import MessageAvatar, {IMessageAvatar} from './MessageAvatar';
|
import MessageAvatar from './MessageAvatar';
|
||||||
import Attachments, {IMessageAttachments} from './Attachments';
|
import Attachments from './Attachments';
|
||||||
import Urls from './Urls';
|
import Urls from './Urls';
|
||||||
import Thread, {IMessageThread} from './Thread';
|
import Thread from './Thread';
|
||||||
import Blocks, {IMessageBlocks} from './Blocks';
|
import Blocks from './Blocks';
|
||||||
import Reactions from './Reactions';
|
import Reactions from './Reactions';
|
||||||
import Broadcast, {IMessageBroadcast} from './Broadcast';
|
import Broadcast from './Broadcast';
|
||||||
import Discussion, {IMessageDiscussion} from './Discussion';
|
import Discussion from './Discussion';
|
||||||
import Content, {IMessageContent} from './Content';
|
import Content from './Content';
|
||||||
import ReadReceipt from './ReadReceipt';
|
import ReadReceipt from './ReadReceipt';
|
||||||
import CallButton, {IMessageCallButton} from './CallButton';
|
import CallButton from './CallButton';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
|
import {TMessage, TMessageInner} from "./types";
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
interface IMessageTouchable {
|
interface IMessageTouchable {
|
||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
|
|
|
@ -3,24 +3,11 @@ import React, { useContext } from 'react';
|
||||||
import Avatar from '../Avatar';
|
import Avatar from '../Avatar';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
|
import {TMessageAvatar} from "./types";
|
||||||
export interface IMessageAvatar {
|
|
||||||
isHeader: boolean;
|
|
||||||
avatar: string;
|
|
||||||
emoji: string;
|
|
||||||
author: {
|
|
||||||
username: string
|
|
||||||
_id: string;
|
|
||||||
};
|
|
||||||
small?: boolean;
|
|
||||||
navToRoomInfo: Function;
|
|
||||||
getCustomEmoji(): void;
|
|
||||||
theme: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MessageAvatar = React.memo(({
|
const MessageAvatar = React.memo(({
|
||||||
isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji, theme
|
isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji, theme
|
||||||
}: IMessageAvatar) => {
|
}: TMessageAvatar) => {
|
||||||
const { user } = useContext(MessageContext);
|
const { user } = useContext(MessageContext);
|
||||||
if (isHeader && author) {
|
if (isHeader && author) {
|
||||||
const navParam = {
|
const navParam = {
|
||||||
|
|
|
@ -6,20 +6,12 @@ import styles from './styles';
|
||||||
import { themes } from '../../constants/colors';
|
import { themes } from '../../constants/colors';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import Markdown from '../markdown';
|
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(({
|
const RepliedThread = memo(({
|
||||||
tmid, tmsg, isHeader, fetchThreadName, id, isEncrypted, theme
|
tmid, tmsg, isHeader, fetchThreadName, id, isEncrypted, theme
|
||||||
}: IMessageRepliedThread) => {
|
}: TMessageRepliedThread) => {
|
||||||
if (!tmid || !isHeader) {
|
if (!tmid || !isHeader) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,9 @@ import { themes } from '../../constants/colors';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
import ThreadDetails from '../ThreadDetails';
|
import ThreadDetails from '../ThreadDetails';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
|
import {TMessageThread} from "./types";
|
||||||
|
|
||||||
export interface IMessageThread {
|
const Thread = React.memo(({ msg, tcount, tlm, isThreadRoom, theme, id }: TMessageThread) => {
|
||||||
msg: string;
|
|
||||||
tcount: number;
|
|
||||||
theme: string;
|
|
||||||
tlm: string;
|
|
||||||
isThreadRoom: boolean;
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Thread = React.memo(({ msg, tcount, tlm, isThreadRoom, theme, id }: IMessageThread) => {
|
|
||||||
if (!tlm || isThreadRoom || tcount === 0) {
|
if (!tlm || isThreadRoom || tcount === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue