2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { StyleSheet, Text, View } from 'react-native';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
import { MarkdownPreview } from '../markdown';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../CustomIcon';
|
2021-09-13 20:41:05 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { IMessage } from '../../definitions/IMessage';
|
2022-03-31 22:39:24 +00:00
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
import { IApplicationState } from '../../definitions';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingTop: 10
|
|
|
|
},
|
|
|
|
messageContainer: {
|
|
|
|
flex: 1,
|
|
|
|
marginHorizontal: 10,
|
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 10,
|
|
|
|
borderRadius: 4
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
fontSize: 16,
|
|
|
|
...sharedStyles.textMedium
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 16,
|
|
|
|
marginLeft: 6,
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
fontWeight: '300'
|
|
|
|
},
|
|
|
|
close: {
|
|
|
|
marginRight: 10
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IMessageBoxReplyPreview {
|
|
|
|
replying: boolean;
|
2022-02-17 15:27:01 +00:00
|
|
|
message: IMessage;
|
2021-09-13 20:41:05 +00:00
|
|
|
Message_TimeFormat: string;
|
|
|
|
close(): void;
|
|
|
|
baseUrl: string;
|
|
|
|
username: string;
|
|
|
|
getCustomEmoji: Function;
|
|
|
|
useRealName: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ReplyPreview = React.memo(
|
2022-03-31 22:39:24 +00:00
|
|
|
({ message, Message_TimeFormat, replying, close, useRealName }: IMessageBoxReplyPreview) => {
|
2022-04-11 18:01:43 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!replying) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-11 18:01:43 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const time = moment(message.ts).format(Message_TimeFormat);
|
|
|
|
return (
|
|
|
|
<View style={[styles.container, { backgroundColor: themes[theme].messageboxBackground }]}>
|
|
|
|
<View style={[styles.messageContainer, { backgroundColor: themes[theme].chatComponentBackground }]}>
|
|
|
|
<View style={styles.header}>
|
|
|
|
<Text style={[styles.username, { color: themes[theme].tintColor }]}>
|
|
|
|
{useRealName ? message.u?.name : message.u?.username}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
|
|
|
</View>
|
2022-02-17 15:27:01 +00:00
|
|
|
<MarkdownPreview msg={message.msg} />
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
|
|
|
<CustomIcon name='close' color={themes[theme].auxiliaryText} size={20} style={styles.close} onPress={close} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
2022-03-31 22:39:24 +00:00
|
|
|
(prevProps: IMessageBoxReplyPreview, nextProps: IMessageBoxReplyPreview) =>
|
|
|
|
prevProps.replying === nextProps.replying && prevProps.message.id === nextProps.message.id
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
|
|
|
|
2022-03-31 22:39:24 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat as string,
|
2021-09-13 20:41:05 +00:00
|
|
|
baseUrl: state.server.server,
|
2022-03-31 22:39:24 +00:00
|
|
|
useRealName: state.settings.UI_Use_Real_Name as boolean
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ReplyPreview);
|