2019-06-10 18:36:31 +00:00
|
|
|
import React from 'react';
|
2021-10-20 17:02:55 +00:00
|
|
|
import { FlatList, Text, View, RefreshControl } from 'react-native';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2019-06-10 18:36:31 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
2021-11-10 17:43:20 +00:00
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { RouteProp } from '@react-navigation/core';
|
2019-06-10 18:36:31 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
import * as List from '../../containers/List';
|
2019-06-10 18:36:31 +00:00
|
|
|
import Avatar from '../../containers/Avatar';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2019-06-10 18:36:31 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2022-05-02 14:17:55 +00:00
|
|
|
import { IApplicationState, IReadReceipts } from '../../definitions';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2021-11-10 17:43:20 +00:00
|
|
|
|
|
|
|
interface IReadReceiptViewState {
|
|
|
|
loading: boolean;
|
2022-03-14 13:32:22 +00:00
|
|
|
receipts: IReadReceipts[];
|
2021-11-10 17:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface INavigationOption {
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: StackNavigationProp<ChatsStackParamList, 'ReadReceiptsView'>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'ReadReceiptsView'>;
|
2021-11-10 17:43:20 +00:00
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IReadReceiptViewProps extends INavigationOption {
|
|
|
|
Message_TimeAndDateFormat: string;
|
2023-08-18 17:48:33 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-11-10 17:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ReadReceiptView extends React.Component<IReadReceiptViewProps, IReadReceiptViewState> {
|
|
|
|
private messageId: string;
|
|
|
|
|
|
|
|
static navigationOptions = ({ navigation, isMasterDetail }: INavigationOption) => {
|
|
|
|
const options: StackNavigationOptions = {
|
2020-07-17 17:13:44 +00:00
|
|
|
title: I18n.t('Read_Receipt')
|
|
|
|
};
|
|
|
|
if (isMasterDetail) {
|
2020-10-30 16:15:58 +00:00
|
|
|
options.headerLeft = () => <HeaderButton.CloseModal navigation={navigation} testID='read-receipt-view-close' />;
|
2020-07-17 17:13:44 +00:00
|
|
|
}
|
|
|
|
return options;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-10 18:36:31 +00:00
|
|
|
|
2021-11-10 17:43:20 +00:00
|
|
|
constructor(props: IReadReceiptViewProps) {
|
2019-06-10 18:36:31 +00:00
|
|
|
super(props);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.messageId = props.route.params?.messageId;
|
2019-06-10 18:36:31 +00:00
|
|
|
this.state = {
|
|
|
|
loading: false,
|
|
|
|
receipts: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
2021-11-10 17:43:20 +00:00
|
|
|
shouldComponentUpdate(nextProps: IReadReceiptViewProps, nextState: IReadReceiptViewState) {
|
2019-06-10 18:36:31 +00:00
|
|
|
const { loading, receipts } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-10 18:36:31 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextState.receipts, receipts)) {
|
2019-06-10 18:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
load = async () => {
|
2019-06-10 18:36:31 +00:00
|
|
|
const { loading } = this.state;
|
|
|
|
if (loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getReadReceipts(this.messageId);
|
2019-06-10 18:36:31 +00:00
|
|
|
if (result.success) {
|
|
|
|
this.setState({
|
|
|
|
receipts: result.receipts,
|
|
|
|
loading: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
console.log('err_fetch_read_receipts', error);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-10 18:36:31 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmpty = () => {
|
2021-10-20 17:02:55 +00:00
|
|
|
const { loading } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2021-10-20 17:02:55 +00:00
|
|
|
if (loading) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<View
|
2024-04-18 10:19:54 +00:00
|
|
|
style={[styles.listEmptyContainer, { backgroundColor: themes[theme].surfaceTint }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
testID='read-receipt-view'
|
|
|
|
>
|
2024-04-18 10:19:54 +00:00
|
|
|
<Text style={[styles.emptyText, { color: themes[theme].fontHint }]}>{I18n.t('No_Read_Receipts')}</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-10 18:36:31 +00:00
|
|
|
|
2022-03-14 13:32:22 +00:00
|
|
|
renderItem = ({ item }: { item: IReadReceipts }) => {
|
2021-05-26 20:40:46 +00:00
|
|
|
const { theme, Message_TimeAndDateFormat } = this.props;
|
|
|
|
const time = moment(item.ts).format(Message_TimeAndDateFormat);
|
2020-09-15 13:09:23 +00:00
|
|
|
if (!item?.user?.username) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-06-10 18:36:31 +00:00
|
|
|
return (
|
2024-04-18 10:19:54 +00:00
|
|
|
<View style={[styles.itemContainer, { backgroundColor: themes[theme].surfaceRoom }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Avatar text={item.user.username} size={40} />
|
2019-06-10 18:36:31 +00:00
|
|
|
<View style={styles.infoContainer}>
|
|
|
|
<View style={styles.item}>
|
2024-04-18 10:19:54 +00:00
|
|
|
<Text style={[styles.name, { color: themes[theme].fontTitlesLabels }]}>{item?.user?.name}</Text>
|
|
|
|
<Text style={[styles.time, { color: themes[theme].fontSecondaryInfo }]}>{time}</Text>
|
2019-06-10 18:36:31 +00:00
|
|
|
</View>
|
2021-10-20 17:02:55 +00:00
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.username,
|
|
|
|
{
|
2024-04-18 10:19:54 +00:00
|
|
|
color: themes[theme].fontSecondaryInfo
|
2021-10-20 17:02:55 +00:00
|
|
|
}
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>{`@${item.user.username}`}</Text>
|
2019-06-10 18:36:31 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-10 18:36:31 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { receipts, loading } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2019-06-10 18:36:31 +00:00
|
|
|
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView testID='read-receipt-view'>
|
|
|
|
<StatusBar />
|
2021-10-20 17:02:55 +00:00
|
|
|
<FlatList
|
|
|
|
data={receipts}
|
|
|
|
renderItem={this.renderItem}
|
|
|
|
ItemSeparatorComponent={List.Separator}
|
|
|
|
ListEmptyComponent={this.renderEmpty}
|
|
|
|
contentContainerStyle={List.styles.contentContainerStyleFlatList}
|
|
|
|
style={[
|
|
|
|
styles.list,
|
|
|
|
{
|
2024-04-18 10:19:54 +00:00
|
|
|
backgroundColor: themes[theme].surfaceTint,
|
|
|
|
borderColor: themes[theme].strokeLight
|
2021-10-20 17:02:55 +00:00
|
|
|
}
|
|
|
|
]}
|
2024-04-18 10:19:54 +00:00
|
|
|
refreshControl={<RefreshControl refreshing={loading} onRefresh={this.load} tintColor={themes[theme].fontSecondaryInfo} />}
|
2021-10-20 17:02:55 +00:00
|
|
|
keyExtractor={item => item._id}
|
|
|
|
/>
|
2019-06-10 18:36:31 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-05-02 14:17:55 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
|
|
|
Message_TimeAndDateFormat: state.settings.Message_TimeAndDateFormat as string
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(ReadReceiptView));
|