2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } from 'react';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { View } from 'react-native';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2018-09-11 16:32:52 +00:00
|
|
|
import User from './User';
|
|
|
|
import styles from './styles';
|
2019-05-20 20:43:50 +00:00
|
|
|
import RepliedThread from './RepliedThread';
|
|
|
|
import MessageAvatar from './MessageAvatar';
|
|
|
|
import Attachments from './Attachments';
|
|
|
|
import Urls from './Urls';
|
|
|
|
import Thread from './Thread';
|
2020-02-11 14:01:35 +00:00
|
|
|
import Blocks from './Blocks';
|
2019-05-20 20:43:50 +00:00
|
|
|
import Reactions from './Reactions';
|
|
|
|
import Broadcast from './Broadcast';
|
|
|
|
import Discussion from './Discussion';
|
|
|
|
import Content from './Content';
|
2019-06-10 18:36:31 +00:00
|
|
|
import ReadReceipt from './ReadReceipt';
|
2019-09-18 17:32:12 +00:00
|
|
|
import CallButton from './CallButton';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { IMessage, IMessageInner, IMessageTouchable } from './interfaces';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-05-10 17:40:08 +00:00
|
|
|
import Edited from './Edited';
|
|
|
|
import MessageError from './MessageError';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const MessageInner = React.memo((props: IMessageInner) => {
|
2022-03-21 20:44:06 +00:00
|
|
|
const { attachments } = props;
|
|
|
|
const isCollapsible = attachments ? attachments[0] && attachments[0].collapsed : false;
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (props.type === 'discussion-created') {
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-05-20 20:43:50 +00:00
|
|
|
<User {...props} />
|
|
|
|
<Discussion {...props} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-04-08 12:35:28 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-21 20:44:06 +00:00
|
|
|
|
2019-09-18 17:32:12 +00:00
|
|
|
if (props.type === 'jitsi_call_started') {
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-09-18 17:32:12 +00:00
|
|
|
<User {...props} />
|
|
|
|
<Content {...props} isInfo />
|
|
|
|
<CallButton {...props} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-09-18 17:32:12 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-21 20:44:06 +00:00
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
if (props.blocks && props.blocks.length) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<User {...props} />
|
|
|
|
<Blocks {...props} />
|
|
|
|
<Thread {...props} />
|
|
|
|
<Reactions {...props} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2022-03-21 20:44:06 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-05-20 20:43:50 +00:00
|
|
|
<User {...props} />
|
2022-03-21 20:44:06 +00:00
|
|
|
{isCollapsible ? (
|
|
|
|
<>
|
|
|
|
<Content {...props} />
|
|
|
|
<Attachments {...props} />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Attachments {...props} />
|
|
|
|
<Content {...props} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
<Urls {...props} />
|
|
|
|
<Thread {...props} />
|
|
|
|
<Reactions {...props} />
|
|
|
|
<Broadcast {...props} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
MessageInner.displayName = 'MessageInner';
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Message = React.memo((props: IMessage) => {
|
2020-11-30 20:00:31 +00:00
|
|
|
if (props.isThreadReply || props.isThreadSequential || props.isInfo || props.isIgnored) {
|
2019-10-08 12:36:15 +00:00
|
|
|
const thread = props.isThreadReply ? <RepliedThread {...props} /> : null;
|
2019-04-17 17:01:03 +00:00
|
|
|
return (
|
2019-07-17 14:06:39 +00:00
|
|
|
<View style={[styles.container, props.style]}>
|
2019-05-20 20:43:50 +00:00
|
|
|
{thread}
|
2020-12-01 19:26:03 +00:00
|
|
|
<View style={styles.flex}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageAvatar small {...props} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={[styles.messageContent, props.isHeader && styles.messageContentWithHeader]}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Content {...props} />
|
|
|
|
</View>
|
|
|
|
</View>
|
2019-04-24 18:36:29 +00:00
|
|
|
</View>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
2020-11-30 20:00:31 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-07-17 14:06:39 +00:00
|
|
|
<View style={[styles.container, props.style]}>
|
2019-05-03 13:33:38 +00:00
|
|
|
<View style={styles.flex}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageAvatar {...props} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={[styles.messageContent, props.isHeader && styles.messageContentWithHeader]}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<MessageInner {...props} />
|
2019-05-03 13:33:38 +00:00
|
|
|
</View>
|
2022-05-10 17:40:08 +00:00
|
|
|
{!props.isHeader ? (
|
|
|
|
<>
|
2022-05-26 17:10:24 +00:00
|
|
|
<Edited testID={`${props.msg}-edited`} isEdited={props.isEdited} />
|
2022-05-10 17:40:08 +00:00
|
|
|
<MessageError hasError={props.hasError} />
|
|
|
|
</>
|
|
|
|
) : null}
|
2022-04-01 21:52:38 +00:00
|
|
|
<ReadReceipt isReadReceiptEnabled={props.isReadReceiptEnabled} unread={props.unread || false} />
|
2019-05-03 13:33:38 +00:00
|
|
|
</View>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
Message.displayName = 'Message';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const MessageTouchable = React.memo((props: IMessageTouchable & IMessage) => {
|
2022-04-11 18:01:43 +00:00
|
|
|
const { onPress, onLongPress } = useContext(MessageContext);
|
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (props.hasError) {
|
2018-09-11 16:32:52 +00:00
|
|
|
return (
|
2019-07-17 14:06:39 +00:00
|
|
|
<View>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Message {...props} />
|
2018-11-16 11:06:29 +00:00
|
|
|
</View>
|
2018-09-11 16:32:52 +00:00
|
|
|
);
|
|
|
|
}
|
2022-04-01 21:52:38 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<Touchable
|
2020-04-30 20:05:59 +00:00
|
|
|
onLongPress={onLongPress}
|
|
|
|
onPress={onPress}
|
2022-02-08 12:47:23 +00:00
|
|
|
disabled={(props.isInfo && !props.isThreadReply) || props.archived || props.isTemp || props.type === 'jitsi_call_started'}
|
2022-04-12 16:27:05 +00:00
|
|
|
style={{ backgroundColor: props.highlighted ? themes[theme].headerBackground : undefined }}>
|
2019-05-20 20:43:50 +00:00
|
|
|
<View>
|
|
|
|
<Message {...props} />
|
|
|
|
</View>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
MessageTouchable.displayName = 'MessageTouchable';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
export default MessageTouchable;
|