2019-05-10 17:09:07 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { FlatList, Text, View } from 'react-native';
|
2019-05-10 17:09:07 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2021-11-16 16:10:49 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { CompositeNavigationProp, RouteProp } from '@react-navigation/core';
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
|
2020-05-08 17:07:58 +00:00
|
|
|
import Message from '../../containers/message';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2019-05-10 17:09:07 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2022-06-06 14:17:51 +00:00
|
|
|
import getFileUrlFromMessage from './getFileUrlFromMessage';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-06-15 19:35:45 +00:00
|
|
|
import { withActionSheet } from '../../containers/ActionSheet';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2021-05-26 17:24:54 +00:00
|
|
|
import getThreadName from '../../lib/methods/getThreadName';
|
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-04-01 21:52:38 +00:00
|
|
|
import { IRoomInfoParam } from '../SearchMessagesView';
|
2022-05-11 02:22:17 +00:00
|
|
|
import {
|
|
|
|
IApplicationState,
|
|
|
|
TMessageModel,
|
|
|
|
ISubscription,
|
|
|
|
SubscriptionType,
|
|
|
|
IAttachment,
|
|
|
|
IMessage,
|
|
|
|
TAnyMessageModel,
|
2022-10-21 18:27:55 +00:00
|
|
|
IUrl,
|
|
|
|
TGetCustomEmoji,
|
|
|
|
ICustomEmoji
|
2022-05-11 02:22:17 +00:00
|
|
|
} from '../../definitions';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
interface IMessagesViewProps {
|
|
|
|
user: {
|
|
|
|
id: string;
|
2022-01-17 16:10:39 +00:00
|
|
|
username: string;
|
|
|
|
token: string;
|
2021-11-16 16:10:49 +00:00
|
|
|
};
|
|
|
|
baseUrl: string;
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'MessagesView'>,
|
|
|
|
StackNavigationProp<MasterDetailInsideStackParamList>
|
|
|
|
>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'MessagesView'>;
|
2022-10-21 18:27:55 +00:00
|
|
|
customEmojis: { [key: string]: ICustomEmoji };
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-05-11 02:22:17 +00:00
|
|
|
showActionSheet: (params: { options: string[]; hasCancel: boolean }) => void;
|
2021-11-16 16:10:49 +00:00
|
|
|
useRealName: boolean;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IMessagesViewState {
|
|
|
|
loading: boolean;
|
2022-05-11 02:22:17 +00:00
|
|
|
messages: IMessage[];
|
|
|
|
message?: IMessage;
|
2021-11-16 16:10:49 +00:00
|
|
|
fileLoading: boolean;
|
|
|
|
total: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IParams {
|
2021-12-03 19:27:57 +00:00
|
|
|
rid: string;
|
2022-01-11 13:51:48 +00:00
|
|
|
t: SubscriptionType;
|
2021-11-16 16:10:49 +00:00
|
|
|
tmid?: string;
|
2022-04-01 15:32:17 +00:00
|
|
|
message?: TMessageModel;
|
2021-11-16 16:10:49 +00:00
|
|
|
name?: string;
|
2021-12-03 19:27:57 +00:00
|
|
|
fname?: string;
|
|
|
|
prid?: string;
|
2022-05-11 02:22:17 +00:00
|
|
|
room?: ISubscription;
|
2021-12-03 19:27:57 +00:00
|
|
|
jumpToMessageId?: string;
|
|
|
|
jumpToThreadId?: string;
|
|
|
|
roomUserId?: string;
|
2021-11-16 16:10:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
class MessagesView extends React.Component<IMessagesViewProps, IMessagesViewState> {
|
2021-12-03 19:27:57 +00:00
|
|
|
private rid: string;
|
2022-01-11 13:51:48 +00:00
|
|
|
private t: SubscriptionType;
|
2021-11-16 16:10:49 +00:00
|
|
|
private content: any;
|
2022-05-11 02:22:17 +00:00
|
|
|
private room?: ISubscription;
|
2021-11-16 16:10:49 +00:00
|
|
|
|
|
|
|
constructor(props: IMessagesViewProps) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2019-05-10 17:09:07 +00:00
|
|
|
this.state = {
|
|
|
|
loading: false,
|
2019-05-20 20:43:50 +00:00
|
|
|
messages: [],
|
2022-05-11 02:22:17 +00:00
|
|
|
fileLoading: true,
|
2022-05-27 17:22:47 +00:00
|
|
|
total: -1
|
2019-05-10 17:09:07 +00:00
|
|
|
};
|
2020-07-24 19:58:14 +00:00
|
|
|
this.setHeader();
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
|
|
|
this.content = this.defineMessagesViewContent(props.route.params?.name);
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
shouldComponentUpdate(nextProps: IMessagesViewProps, nextState: IMessagesViewState) {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { loading, messages, fileLoading } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextState.messages, messages)) {
|
2019-05-10 17:09:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-26 16:56:39 +00:00
|
|
|
if (fileLoading !== nextState.fileLoading) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-24 19:58:14 +00:00
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { route, navigation } = this.props;
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t(route.params?.name)
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
navToRoomInfo = (navParam: IRoomInfoParam) => {
|
2020-02-17 16:06:46 +00:00
|
|
|
const { navigation, user } = this.props;
|
|
|
|
if (navParam.rid === user.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
navigation.navigate('RoomInfoView', navParam);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-17 16:06:46 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
jumpToMessage = async ({ item }: { item: IMessage }) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
2021-11-16 16:10:49 +00:00
|
|
|
let params: IParams = {
|
2021-05-26 17:24:54 +00:00
|
|
|
rid: this.rid,
|
|
|
|
jumpToMessageId: item._id,
|
|
|
|
t: this.t,
|
|
|
|
room: this.room
|
|
|
|
};
|
|
|
|
if (item.tmid) {
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('DrawerNavigator');
|
|
|
|
} else {
|
|
|
|
navigation.pop(2);
|
|
|
|
}
|
|
|
|
params = {
|
|
|
|
...params,
|
|
|
|
tmid: item.tmid,
|
|
|
|
name: await getThreadName(this.rid, item.tmid, item._id),
|
2022-01-11 13:51:48 +00:00
|
|
|
t: SubscriptionType.THREAD
|
2021-05-26 17:24:54 +00:00
|
|
|
};
|
|
|
|
navigation.push('RoomView', params);
|
|
|
|
} else {
|
|
|
|
navigation.navigate('RoomView', params);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
defineMessagesViewContent = (name: string) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { user, baseUrl, theme, useRealName } = this.props;
|
2022-05-11 02:22:17 +00:00
|
|
|
const renderItemCommonProps = (item: TAnyMessageModel) => ({
|
2020-05-08 17:07:58 +00:00
|
|
|
item,
|
2019-05-10 17:09:07 +00:00
|
|
|
baseUrl,
|
|
|
|
user,
|
|
|
|
author: item.u || item.user,
|
|
|
|
timeFormat: 'MMM Do YYYY, h:mm:ss a',
|
2019-05-20 20:43:50 +00:00
|
|
|
isEdited: !!item.editedAt,
|
|
|
|
isHeader: true,
|
2021-05-26 17:24:54 +00:00
|
|
|
isThreadRoom: true,
|
2019-05-20 20:43:50 +00:00
|
|
|
attachments: item.attachments || [],
|
2020-08-26 14:06:14 +00:00
|
|
|
useRealName,
|
2019-12-18 21:13:11 +00:00
|
|
|
showAttachment: this.showAttachment,
|
2020-02-17 16:06:46 +00:00
|
|
|
getCustomEmoji: this.getCustomEmoji,
|
2021-05-26 17:24:54 +00:00
|
|
|
navToRoomInfo: this.navToRoomInfo,
|
2022-04-01 21:52:38 +00:00
|
|
|
onPress: () => this.jumpToMessage({ item }),
|
|
|
|
rid: this.rid
|
2019-05-10 17:09:07 +00:00
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
return {
|
2019-05-10 17:09:07 +00:00
|
|
|
// Files Messages Screen
|
|
|
|
Files: {
|
|
|
|
name: I18n.t('Files'),
|
2021-09-13 20:41:05 +00:00
|
|
|
fetchFunc: async () => {
|
2020-07-17 18:59:18 +00:00
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getFiles(this.rid, this.t, messages.length);
|
2022-03-10 15:29:33 +00:00
|
|
|
if (result.success) {
|
|
|
|
return { ...result, messages: result.files };
|
|
|
|
}
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
noDataMsg: I18n.t('No_files'),
|
|
|
|
testID: 'room-files-view',
|
2022-03-02 14:18:01 +00:00
|
|
|
renderItem: (item: any) => (
|
2020-05-08 17:07:58 +00:00
|
|
|
<Message
|
|
|
|
{...renderItemCommonProps(item)}
|
2022-04-11 18:01:43 +00:00
|
|
|
theme={theme}
|
2020-05-08 17:07:58 +00:00
|
|
|
item={{
|
|
|
|
...item,
|
|
|
|
u: item.user,
|
2020-08-25 20:09:52 +00:00
|
|
|
ts: item.ts || item.uploadedAt,
|
2021-09-13 20:41:05 +00:00
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
title: item.name,
|
|
|
|
description: item.description,
|
|
|
|
...getFileUrlFromMessage(item)
|
|
|
|
}
|
|
|
|
]
|
2020-05-08 17:07:58 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Mentions Messages Screen
|
|
|
|
Mentions: {
|
|
|
|
name: I18n.t('Mentions'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { 'mentions._id': { $in: [user.id] } }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_mentioned_messages'),
|
|
|
|
testID: 'mentioned-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => <Message {...renderItemCommonProps(item)} msg={item.msg} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Starred Messages Screen
|
|
|
|
Starred: {
|
|
|
|
name: I18n.t('Starred'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { 'starred._id': { $in: [user.id] } }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_starred_messages'),
|
|
|
|
testID: 'starred-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Message {...renderItemCommonProps(item)} msg={item.msg} onLongPress={() => this.onLongPress(item)} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
),
|
2022-05-11 02:22:17 +00:00
|
|
|
action: (message: IMessage) => ({
|
2021-09-13 20:41:05 +00:00
|
|
|
title: I18n.t('Unstar'),
|
|
|
|
icon: message.starred ? 'star-filled' : 'star',
|
|
|
|
onPress: this.handleActionPress
|
|
|
|
}),
|
2022-05-11 02:22:17 +00:00
|
|
|
handleActionPress: (message: IMessage) => Services.toggleStarMessage(message._id, message.starred)
|
2019-05-10 17:09:07 +00:00
|
|
|
},
|
|
|
|
// Pinned Messages Screen
|
|
|
|
Pinned: {
|
|
|
|
name: I18n.t('Pinned'),
|
2020-07-17 18:59:18 +00:00
|
|
|
fetchFunc: () => {
|
|
|
|
const { messages } = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
return Services.getMessages(this.rid, this.t, { pinned: true }, messages.length);
|
2020-07-17 18:59:18 +00:00
|
|
|
},
|
2019-05-10 17:09:07 +00:00
|
|
|
noDataMsg: I18n.t('No_pinned_messages'),
|
|
|
|
testID: 'pinned-messages-view',
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem: (item: TAnyMessageModel) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Message {...renderItemCommonProps(item)} msg={item.msg} onLongPress={() => this.onLongPress(item)} theme={theme} />
|
2019-05-10 17:09:07 +00:00
|
|
|
),
|
2020-06-15 19:35:45 +00:00
|
|
|
action: () => ({ title: I18n.t('Unpin'), icon: 'pin', onPress: this.handleActionPress }),
|
2022-05-11 02:22:17 +00:00
|
|
|
handleActionPress: (message: IMessage) => Services.togglePinMessage(message._id, message.pinned)
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
}[name];
|
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
load = async () => {
|
|
|
|
const { messages, total, loading } = this.state;
|
2019-05-10 17:09:07 +00:00
|
|
|
if (messages.length === total || loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await this.content.fetchFunc();
|
|
|
|
if (result.success) {
|
2022-05-03 19:52:56 +00:00
|
|
|
const urlRenderMessages = result.messages?.map((message: any) => {
|
|
|
|
if (message.urls && message.urls.length > 0) {
|
|
|
|
message.urls = message.urls?.map((url: any, index: any) => {
|
|
|
|
if (url.meta) {
|
|
|
|
return {
|
|
|
|
_id: index,
|
|
|
|
title: url.meta.pageTitle,
|
|
|
|
description: url.meta.ogDescription,
|
|
|
|
image: url.meta.ogImage,
|
|
|
|
url: url.url
|
|
|
|
} as IUrl;
|
|
|
|
}
|
|
|
|
return {} as IUrl;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
});
|
2019-05-10 17:09:07 +00:00
|
|
|
this.setState({
|
2022-05-03 19:52:56 +00:00
|
|
|
messages: [...messages, ...urlRenderMessages],
|
2019-05-10 17:09:07 +00:00
|
|
|
total: result.total,
|
|
|
|
loading: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
console.warn('MessagesView -> catch -> error', error);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
getCustomEmoji: TGetCustomEmoji = name => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { customEmojis } = this.props;
|
|
|
|
const emoji = customEmojis[name];
|
|
|
|
if (emoji) {
|
|
|
|
return emoji;
|
|
|
|
}
|
|
|
|
return null;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
showAttachment = (attachment: IAttachment) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('AttachmentView', { attachment });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
onLongPress = (message: IMessage) => {
|
2020-06-15 19:35:45 +00:00
|
|
|
this.setState({ message }, this.showActionSheet);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
showActionSheet = () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { message } = this.state;
|
|
|
|
const { showActionSheet } = this.props;
|
|
|
|
showActionSheet({ options: [this.content.action(message)], hasCancel: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
handleActionPress = async () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { message } = this.state;
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2020-06-15 19:35:45 +00:00
|
|
|
try {
|
|
|
|
const result = await this.content.handleActionPress(message);
|
|
|
|
if (result.success) {
|
2021-11-16 16:10:49 +00:00
|
|
|
this.setState((prevState: IMessagesViewState) => ({
|
2022-05-11 02:22:17 +00:00
|
|
|
messages: prevState.messages.filter((item: IMessage) => item._id !== message?._id),
|
2020-06-15 19:35:45 +00:00
|
|
|
total: prevState.total - 1
|
|
|
|
}));
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2020-06-15 19:35:45 +00:00
|
|
|
} catch {
|
|
|
|
// Do nothing
|
2019-05-10 17:09:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2021-11-16 16:10:49 +00:00
|
|
|
setFileLoading = (fileLoading: boolean) => {
|
2019-08-26 16:56:39 +00:00
|
|
|
this.setState({ fileLoading });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-26 16:56:39 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderEmpty = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={[styles.listEmptyContainer, { backgroundColor: themes[theme].backgroundColor }]} testID={this.content.testID}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.noDataFound, { color: themes[theme].titleText }]}>{this.content.noDataMsg}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-10 17:09:07 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
renderItem = ({ item }: { item: IMessage }) => this.content.renderItem(item);
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
render() {
|
2019-12-18 21:13:11 +00:00
|
|
|
const { messages, loading } = this.state;
|
|
|
|
const { theme } = this.props;
|
2019-05-10 17:09:07 +00:00
|
|
|
|
|
|
|
if (!loading && messages.length === 0) {
|
|
|
|
return this.renderEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }} testID={this.content.testID}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2019-05-10 17:09:07 +00:00
|
|
|
<FlatList
|
|
|
|
data={messages}
|
|
|
|
renderItem={this.renderItem}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.list, { backgroundColor: themes[theme].backgroundColor }]}
|
2019-05-10 17:09:07 +00:00
|
|
|
keyExtractor={item => item._id}
|
|
|
|
onEndReached={this.load}
|
2022-03-18 02:37:10 +00:00
|
|
|
ListFooterComponent={loading ? <ActivityIndicator /> : null}
|
2019-05-10 17:09:07 +00:00
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server,
|
|
|
|
user: getUserSelector(state),
|
2020-08-26 14:06:14 +00:00
|
|
|
customEmojis: state.customEmojis,
|
2021-05-26 17:24:54 +00:00
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
|
|
|
isMasterDetail: state.app.isMasterDetail
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2020-06-15 19:35:45 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(withActionSheet(MessagesView)));
|