2019-10-30 14:14:41 +00:00
|
|
|
import React from 'react';
|
2018-07-20 19:54:46 +00:00
|
|
|
import { View, Text, StyleSheet } from 'react-native';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2018-07-20 19:54:46 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2018-09-11 16:32:52 +00:00
|
|
|
flexDirection: 'row',
|
2019-12-04 16:39:53 +00:00
|
|
|
paddingTop: 10
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
messageContainer: {
|
|
|
|
flex: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
marginHorizontal: 10,
|
2018-07-20 19:54:46 +00:00
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 10,
|
2018-09-11 16:32:52 +00:00
|
|
|
borderRadius: 4
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
username: {
|
|
|
|
fontSize: 16,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 16,
|
2019-03-29 19:36:07 +00:00
|
|
|
marginLeft: 6,
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
fontWeight: '300'
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
close: {
|
2018-09-11 16:32:52 +00:00
|
|
|
marginRight: 10
|
2018-07-20 19:54:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-23 04:15:16 +00:00
|
|
|
interface IMessageBoxReplyPreview {
|
|
|
|
replying: boolean;
|
|
|
|
message: {
|
|
|
|
ts: Date;
|
|
|
|
msg: string;
|
|
|
|
u: any;
|
|
|
|
};
|
|
|
|
Message_TimeFormat: string;
|
|
|
|
close(): void;
|
|
|
|
baseUrl: string;
|
|
|
|
username: string;
|
|
|
|
getCustomEmoji(): void;
|
|
|
|
theme: string;
|
|
|
|
useRealName: boolean;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:14:41 +00:00
|
|
|
const ReplyPreview = React.memo(({
|
2021-02-18 18:53:46 +00:00
|
|
|
message, Message_TimeFormat, baseUrl, username, replying, getCustomEmoji, close, theme, useRealName
|
2021-07-23 04:15:16 +00:00
|
|
|
}: IMessageBoxReplyPreview) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
if (!replying) {
|
|
|
|
return null;
|
2018-07-20 19:54:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 14:14:41 +00:00
|
|
|
const time = moment(message.ts).format(Message_TimeFormat);
|
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
{ backgroundColor: themes[theme].messageboxBackground }
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<View style={[styles.messageContainer, { backgroundColor: themes[theme].chatComponentBackground }]}>
|
2019-10-30 14:14:41 +00:00
|
|
|
<View style={styles.header}>
|
2021-02-18 18:53:46 +00:00
|
|
|
<Text style={[styles.username, { color: themes[theme].tintColor }]}>{useRealName ? message.u?.name : message.u?.username}</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
|
2018-07-20 19:54:46 +00:00
|
|
|
</View>
|
2021-07-23 04:15:16 +00:00
|
|
|
{/*@ts-ignore*/}
|
2019-12-04 16:39:53 +00:00
|
|
|
<Markdown
|
|
|
|
msg={message.msg}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
username={username}
|
|
|
|
getCustomEmoji={getCustomEmoji}
|
|
|
|
numberOfLines={1}
|
|
|
|
preview
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2018-07-20 19:54:46 +00:00
|
|
|
</View>
|
2020-07-27 19:53:33 +00:00
|
|
|
<CustomIcon name='close' color={themes[theme].auxiliaryText} size={20} style={styles.close} onPress={close} />
|
2019-10-30 14:14:41 +00:00
|
|
|
</View>
|
|
|
|
);
|
2021-07-23 04:15:16 +00:00
|
|
|
}, (prevProps: any, nextProps: any) => prevProps.replying === nextProps.replying && prevProps.theme === nextProps.theme && prevProps.message.id === nextProps.message.id);
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2021-07-23 04:15:16 +00:00
|
|
|
const mapStateToProps = (state: any) => ({
|
2019-08-07 13:51:34 +00:00
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat,
|
2021-02-18 18:53:46 +00:00
|
|
|
baseUrl: state.server.server,
|
|
|
|
useRealName: state.settings.UI_Use_Real_Name
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ReplyPreview);
|