2017-08-03 18:23:43 +00:00
|
|
|
import React from 'react';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { BackHandler, FlatList, Keyboard, NativeEventSubscription, RefreshControl, Text, View } from 'react-native';
|
2021-09-23 14:17:53 +00:00
|
|
|
import { batch, connect } from 'react-redux';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2019-03-12 16:23:06 +00:00
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { withSafeAreaInsets } from 'react-native-safe-area-context';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
2022-07-06 13:23:02 +00:00
|
|
|
import { Header } from '@react-navigation/elements';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { CompositeNavigationProp, RouteProp } from '@react-navigation/native';
|
|
|
|
import { Dispatch } from 'redux';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2022-04-20 21:37:54 +00:00
|
|
|
import RoomItem, { ROW_HEIGHT, ROW_HEIGHT_CONDENSED } from '../../containers/RoomItem';
|
2022-06-06 14:17:51 +00:00
|
|
|
import log, { logEvent, events } from '../../lib/methods/helpers/log';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-01-14 22:06:55 +00:00
|
|
|
import { closeSearchHeader, closeServerDropdown, openSearchHeader, roomsRequest } from '../../actions/rooms';
|
2022-02-02 18:27:10 +00:00
|
|
|
import { appStart } from '../../actions/app';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../../containers/ActivityIndicator';
|
2022-02-02 18:27:10 +00:00
|
|
|
import { serverInitAdd } from '../../actions/server';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { animateNextTransition } from '../../lib/methods/helpers/layoutAnimation';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
2022-07-06 13:23:02 +00:00
|
|
|
import { themedHeader } from '../../lib/methods/helpers/navigation';
|
2019-11-25 20:01:17 +00:00
|
|
|
import {
|
|
|
|
KEY_COMMAND,
|
2021-09-13 20:41:05 +00:00
|
|
|
handleCommandAddNewServer,
|
|
|
|
handleCommandNextRoom,
|
|
|
|
handleCommandPreviousRoom,
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommandSearching,
|
|
|
|
handleCommandSelectRoom,
|
|
|
|
handleCommandShowNewMessage,
|
2022-02-25 18:59:39 +00:00
|
|
|
handleCommandShowPreferences,
|
|
|
|
IKeyCommandEvent
|
2019-11-25 20:01:17 +00:00
|
|
|
} from '../../commands';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { goRoom } from '../../lib/methods/helpers/goRoom';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-06-17 17:35:58 +00:00
|
|
|
import { withDimensions } from '../../dimensions';
|
2020-08-28 19:41:08 +00:00
|
|
|
import { getInquiryQueueSelector } from '../../ee/omnichannel/selectors/inquiry';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { IApplicationState, ISubscription, IUser, RootEnum, SubscriptionType, TSubscriptionModel } from '../../definitions';
|
2021-10-06 20:30:10 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import ServerDropdown from './ServerDropdown';
|
2022-02-25 18:59:39 +00:00
|
|
|
import ListHeader, { TEncryptionBanner } from './ListHeader';
|
2021-09-13 20:41:05 +00:00
|
|
|
import RoomsListHeaderView from './Header';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { ChatsStackParamList, DrawerParamList } from '../../stacks/types';
|
2022-06-27 18:23:43 +00:00
|
|
|
import { RoomTypes, search } from '../../lib/methods';
|
2022-04-28 20:37:25 +00:00
|
|
|
import {
|
|
|
|
getRoomAvatar,
|
|
|
|
getRoomTitle,
|
|
|
|
getUidDirectMessage,
|
|
|
|
hasPermission,
|
|
|
|
isRead,
|
2022-06-06 14:17:51 +00:00
|
|
|
debounce,
|
|
|
|
isIOS,
|
|
|
|
isTablet
|
|
|
|
} from '../../lib/methods/helpers';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { E2E_BANNER_TYPE, DisplayMode, SortBy, MAX_SIDEBAR_WIDTH, themes } from '../../lib/constants';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2022-02-25 18:59:39 +00:00
|
|
|
|
2022-11-25 13:21:56 +00:00
|
|
|
type TNavigation = CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'RoomsListView'>,
|
|
|
|
CompositeNavigationProp<StackNavigationProp<ChatsStackParamList>, StackNavigationProp<DrawerParamList>>
|
|
|
|
>;
|
|
|
|
|
|
|
|
interface IRoomsListViewProps {
|
|
|
|
navigation: TNavigation;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'RoomsListView'>;
|
|
|
|
theme: TSupportedThemes;
|
|
|
|
dispatch: Dispatch;
|
2022-05-16 18:14:04 +00:00
|
|
|
[key: string]: IUser | string | boolean | ISubscription[] | number | object | TEncryptionBanner;
|
2022-02-25 18:59:39 +00:00
|
|
|
user: IUser;
|
|
|
|
server: string;
|
|
|
|
searchText: string;
|
|
|
|
changingServer: boolean;
|
|
|
|
loadingServer: boolean;
|
|
|
|
showServerDropdown: boolean;
|
|
|
|
sortBy: string;
|
|
|
|
groupByType: boolean;
|
|
|
|
showFavorites: boolean;
|
|
|
|
showUnread: boolean;
|
|
|
|
refreshing: boolean;
|
|
|
|
StoreLastMessage: boolean;
|
|
|
|
useRealName: boolean;
|
|
|
|
isMasterDetail: boolean;
|
2023-02-14 13:47:56 +00:00
|
|
|
notificationPresenceCap: boolean;
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: string;
|
2022-02-25 18:59:39 +00:00
|
|
|
width: number;
|
|
|
|
insets: {
|
|
|
|
left: number;
|
|
|
|
right: number;
|
|
|
|
};
|
|
|
|
queueSize: number;
|
|
|
|
inquiryEnabled: boolean;
|
|
|
|
encryptionBanner: TEncryptionBanner;
|
|
|
|
showAvatar: boolean;
|
|
|
|
displayMode: string;
|
|
|
|
createTeamPermission: [];
|
|
|
|
createDirectMessagePermission: [];
|
|
|
|
createPublicChannelPermission: [];
|
|
|
|
createPrivateChannelPermission: [];
|
|
|
|
createDiscussionPermission: [];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IRoomsListViewState {
|
2022-05-16 18:14:04 +00:00
|
|
|
searching?: boolean;
|
|
|
|
search?: IRoomItem[];
|
|
|
|
loading?: boolean;
|
|
|
|
chatsUpdate?: string[] | { rid: string; alert?: boolean }[];
|
|
|
|
omnichannelsUpdate?: string[];
|
|
|
|
chats?: IRoomItem[];
|
|
|
|
item?: ISubscription;
|
|
|
|
canCreateRoom?: boolean;
|
2022-02-25 18:59:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IRoomItem extends ISubscription {
|
|
|
|
search?: boolean;
|
|
|
|
outside?: boolean;
|
|
|
|
}
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
|
|
|
|
const CHATS_HEADER = 'Chats';
|
|
|
|
const UNREAD_HEADER = 'Unread';
|
|
|
|
const FAVORITES_HEADER = 'Favorites';
|
|
|
|
const DISCUSSIONS_HEADER = 'Discussions';
|
2021-04-07 18:31:25 +00:00
|
|
|
const TEAMS_HEADER = 'Teams';
|
2019-11-25 20:01:17 +00:00
|
|
|
const CHANNELS_HEADER = 'Channels';
|
|
|
|
const DM_HEADER = 'Direct_Messages';
|
2022-04-20 20:53:11 +00:00
|
|
|
const OMNICHANNEL_HEADER_IN_PROGRESS = 'Open_Livechats';
|
|
|
|
const OMNICHANNEL_HEADER_ON_HOLD = 'On_hold_Livechats';
|
2020-07-20 16:44:54 +00:00
|
|
|
const QUERY_SIZE = 20;
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
const filterIsUnread = (s: TSubscriptionModel) => (s.unread > 0 || s.tunread?.length > 0 || s.alert) && !s.hideUnreadStatus;
|
|
|
|
const filterIsFavorite = (s: TSubscriptionModel) => s.f;
|
|
|
|
const filterIsOmnichannel = (s: TSubscriptionModel) => s.t === 'l';
|
|
|
|
const filterIsTeam = (s: TSubscriptionModel) => s.teamMain;
|
|
|
|
const filterIsDiscussion = (s: TSubscriptionModel) => s.prid;
|
2019-12-03 12:32:02 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const shouldUpdateProps = [
|
|
|
|
'searchText',
|
|
|
|
'loadingServer',
|
|
|
|
'showServerDropdown',
|
|
|
|
'useRealName',
|
|
|
|
'StoreLastMessage',
|
2019-12-04 16:39:53 +00:00
|
|
|
'theme',
|
2020-06-15 14:00:46 +00:00
|
|
|
'isMasterDetail',
|
2023-02-14 13:47:56 +00:00
|
|
|
'notificationPresenceCap',
|
2020-07-31 18:22:30 +00:00
|
|
|
'refreshing',
|
|
|
|
'queueSize',
|
2020-09-11 14:31:38 +00:00
|
|
|
'inquiryEnabled',
|
2021-10-05 13:59:40 +00:00
|
|
|
'encryptionBanner',
|
|
|
|
'createTeamPermission',
|
|
|
|
'createDirectMessagePermission',
|
|
|
|
'createPublicChannelPermission',
|
|
|
|
'createPrivateChannelPermission',
|
|
|
|
'createDiscussionPermission'
|
2019-09-16 20:26:32 +00:00
|
|
|
];
|
2021-10-06 20:30:10 +00:00
|
|
|
|
|
|
|
const sortPreferencesShouldUpdate = ['sortBy', 'groupByType', 'showFavorites', 'showUnread'];
|
|
|
|
|
|
|
|
const displayPropsShouldUpdate = ['showAvatar', 'displayMode'];
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
const getItemLayout = (data: ISubscription[] | null | undefined, index: number, height: number) => ({
|
2021-10-06 20:30:10 +00:00
|
|
|
length: height,
|
|
|
|
offset: height * index,
|
2019-09-16 20:26:32 +00:00
|
|
|
index
|
|
|
|
});
|
2022-02-25 18:59:39 +00:00
|
|
|
const keyExtractor = (item: ISubscription) => item.rid;
|
|
|
|
|
|
|
|
class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewState> {
|
|
|
|
private animated: boolean;
|
|
|
|
private mounted: boolean;
|
|
|
|
private count: number;
|
|
|
|
private unsubscribeFocus?: () => void;
|
|
|
|
private unsubscribeBlur?: () => void;
|
|
|
|
private sortPreferencesChanged?: boolean;
|
|
|
|
private shouldUpdate?: boolean;
|
|
|
|
private backHandler?: NativeEventSubscription;
|
|
|
|
private querySubscription?: Subscription;
|
|
|
|
private scroll?: FlatList;
|
|
|
|
private useRealName?: boolean;
|
|
|
|
|
|
|
|
constructor(props: IRoomsListViewProps) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2021-09-13 20:41:05 +00:00
|
|
|
console.time(`${this.constructor.name} init`);
|
|
|
|
console.time(`${this.constructor.name} mount`);
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = false;
|
2021-01-13 14:16:00 +00:00
|
|
|
this.mounted = false;
|
2020-07-20 16:44:54 +00:00
|
|
|
this.count = 0;
|
2017-08-10 16:16:32 +00:00
|
|
|
this.state = {
|
2018-11-27 19:40:53 +00:00
|
|
|
searching: false,
|
2018-05-24 20:17:00 +00:00
|
|
|
search: [],
|
2018-08-31 16:46:33 +00:00
|
|
|
loading: true,
|
2022-05-16 18:14:04 +00:00
|
|
|
chatsUpdate: [] as TSubscriptionModel[],
|
2022-04-20 20:53:11 +00:00
|
|
|
omnichannelsUpdate: [],
|
2018-08-31 16:46:33 +00:00
|
|
|
chats: [],
|
2022-02-25 18:59:39 +00:00
|
|
|
item: {} as ISubscription,
|
2021-10-05 13:59:40 +00:00
|
|
|
canCreateRoom: false
|
2017-08-10 16:16:32 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2021-01-13 14:16:00 +00:00
|
|
|
this.getSubscriptions();
|
2017-08-13 01:35:09 +00:00
|
|
|
}
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-07-18 20:34:59 +00:00
|
|
|
componentDidMount() {
|
2022-01-14 22:06:55 +00:00
|
|
|
const { navigation, dispatch } = this.props;
|
2021-10-05 13:59:40 +00:00
|
|
|
this.handleHasPermission();
|
2021-01-13 14:16:00 +00:00
|
|
|
this.mounted = true;
|
2020-07-02 17:14:12 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
2020-05-08 17:04:37 +00:00
|
|
|
Orientation.unlockAllOrientations();
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = true;
|
2021-10-06 20:30:10 +00:00
|
|
|
// Check if there were changes with sort preference, then call getSubscription to remount the list
|
|
|
|
if (this.sortPreferencesChanged) {
|
|
|
|
this.getSubscriptions();
|
|
|
|
this.sortPreferencesChanged = false;
|
|
|
|
}
|
2020-04-30 17:38:57 +00:00
|
|
|
// Check if there were changes while not focused (it's set on sCU)
|
|
|
|
if (this.shouldUpdate) {
|
|
|
|
this.forceUpdate();
|
|
|
|
this.shouldUpdate = false;
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
|
|
|
});
|
2020-06-15 14:00:46 +00:00
|
|
|
this.unsubscribeBlur = navigation.addListener('blur', () => {
|
2020-02-17 19:06:18 +00:00
|
|
|
this.animated = false;
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(closeServerDropdown());
|
2020-06-15 14:00:46 +00:00
|
|
|
this.cancelSearch();
|
2019-11-27 20:53:46 +00:00
|
|
|
if (this.backHandler && this.backHandler.remove) {
|
|
|
|
this.backHandler.remove();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
console.timeEnd(`${this.constructor.name} mount`);
|
2018-07-18 20:34:59 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps: IRoomsListViewProps) {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { loadingServer, searchText, server, changingServer } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2021-01-13 14:16:00 +00:00
|
|
|
// when the server is changed
|
|
|
|
if (server !== nextProps.server && loadingServer !== nextProps.loadingServer && nextProps.loadingServer) {
|
|
|
|
this.setState({ loading: true });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-01-13 14:16:00 +00:00
|
|
|
// when the server is changing and stopped loading
|
|
|
|
if (changingServer && loadingServer !== nextProps.loadingServer && !nextProps.loadingServer) {
|
|
|
|
this.getSubscriptions();
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
if (searchText !== nextProps.searchText) {
|
2022-04-28 20:37:25 +00:00
|
|
|
this.handleSearch(nextProps.searchText);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
shouldComponentUpdate(nextProps: IRoomsListViewProps, nextState: IRoomsListViewState) {
|
2022-04-20 20:53:11 +00:00
|
|
|
const { chatsUpdate, searching, item, canCreateRoom, omnichannelsUpdate } = this.state;
|
2018-12-21 10:55:35 +00:00
|
|
|
const propsUpdated = shouldUpdateProps.some(key => nextProps[key] !== this.props[key]);
|
|
|
|
if (propsUpdated) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-06 20:30:10 +00:00
|
|
|
// check if some display props are changed to force update when focus this view again
|
|
|
|
const displayUpdated = displayPropsShouldUpdate.some(key => nextProps[key] !== this.props[key]);
|
|
|
|
if (displayUpdated) {
|
|
|
|
this.shouldUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if some sort preferences are changed to getSubscription() when focus this view again
|
|
|
|
const sortPreferencesUpdate = sortPreferencesShouldUpdate.some(key => nextProps[key] !== this.props[key]);
|
|
|
|
if (sortPreferencesUpdate) {
|
|
|
|
this.sortPreferencesChanged = true;
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:19:33 +00:00
|
|
|
// Compare changes only once
|
2021-02-26 16:01:45 +00:00
|
|
|
const chatsNotEqual = !dequal(nextState.chatsUpdate, chatsUpdate);
|
2019-09-24 18:19:33 +00:00
|
|
|
|
|
|
|
// If they aren't equal, set to update if focused
|
|
|
|
if (chatsNotEqual) {
|
|
|
|
this.shouldUpdate = true;
|
|
|
|
}
|
|
|
|
|
2022-04-20 20:53:11 +00:00
|
|
|
const omnichannelsNotEqual = !dequal(nextState.omnichannelsUpdate, omnichannelsUpdate);
|
|
|
|
|
|
|
|
if (omnichannelsNotEqual) {
|
|
|
|
this.shouldUpdate = true;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
if (nextState.searching !== searching) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-05 13:59:40 +00:00
|
|
|
if (nextState.canCreateRoom !== canCreateRoom) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
if (nextState.item?.rid !== item?.rid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:19:33 +00:00
|
|
|
// Abort if it's not focused
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!nextProps.navigation.isFocused()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const { loading, search } = this.state;
|
2022-11-25 13:21:56 +00:00
|
|
|
const { width, insets, subscribedRoom } = this.props;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-17 17:35:58 +00:00
|
|
|
if (nextProps.width !== width) {
|
2019-07-04 16:15:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextState.search, search)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-11-25 13:21:56 +00:00
|
|
|
if (nextProps.subscribedRoom !== subscribedRoom) {
|
2020-06-15 14:00:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.insets, insets)) {
|
2020-07-06 20:56:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-09-24 18:19:33 +00:00
|
|
|
// If it's focused and there are changes, update
|
2022-04-20 20:53:11 +00:00
|
|
|
if (chatsNotEqual || omnichannelsNotEqual) {
|
2019-09-24 18:19:33 +00:00
|
|
|
this.shouldUpdate = false;
|
2019-09-16 20:26:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
componentDidUpdate(prevProps: IRoomsListViewProps) {
|
2021-10-05 13:59:40 +00:00
|
|
|
const {
|
|
|
|
sortBy,
|
|
|
|
groupByType,
|
|
|
|
showFavorites,
|
|
|
|
showUnread,
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom,
|
2021-10-05 13:59:40 +00:00
|
|
|
isMasterDetail,
|
2023-02-14 13:47:56 +00:00
|
|
|
notificationPresenceCap,
|
2021-10-05 13:59:40 +00:00
|
|
|
insets,
|
|
|
|
createTeamPermission,
|
|
|
|
createPublicChannelPermission,
|
|
|
|
createPrivateChannelPermission,
|
|
|
|
createDirectMessagePermission,
|
2021-10-06 20:30:10 +00:00
|
|
|
createDiscussionPermission,
|
|
|
|
showAvatar,
|
|
|
|
displayMode
|
2021-10-05 13:59:40 +00:00
|
|
|
} = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (
|
|
|
|
!(
|
2021-09-13 20:41:05 +00:00
|
|
|
prevProps.sortBy === sortBy &&
|
|
|
|
prevProps.groupByType === groupByType &&
|
|
|
|
prevProps.showFavorites === showFavorites &&
|
2021-10-06 20:30:10 +00:00
|
|
|
prevProps.showUnread === showUnread &&
|
|
|
|
prevProps.showAvatar === showAvatar &&
|
|
|
|
prevProps.displayMode === displayMode
|
2019-09-16 20:26:32 +00:00
|
|
|
)
|
|
|
|
) {
|
2020-07-20 16:44:54 +00:00
|
|
|
this.getSubscriptions();
|
2017-11-07 20:25:04 +00:00
|
|
|
}
|
2022-11-25 13:21:56 +00:00
|
|
|
// Update current item in case of another action triggers an update on room subscribed reducer
|
|
|
|
if (isMasterDetail && item?.rid !== subscribedRoom && subscribedRoom !== prevProps.subscribedRoom) {
|
|
|
|
this.setState({ item: { rid: subscribedRoom } as ISubscription });
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2023-02-14 13:47:56 +00:00
|
|
|
if (
|
|
|
|
insets.left !== prevProps.insets.left ||
|
|
|
|
insets.right !== prevProps.insets.right ||
|
|
|
|
notificationPresenceCap !== prevProps.notificationPresenceCap
|
|
|
|
) {
|
2020-07-06 20:56:28 +00:00
|
|
|
this.setHeader();
|
|
|
|
}
|
2021-10-05 13:59:40 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
!dequal(createTeamPermission, prevProps.createTeamPermission) ||
|
|
|
|
!dequal(createPublicChannelPermission, prevProps.createPublicChannelPermission) ||
|
|
|
|
!dequal(createPrivateChannelPermission, prevProps.createPrivateChannelPermission) ||
|
|
|
|
!dequal(createDirectMessagePermission, prevProps.createDirectMessagePermission) ||
|
|
|
|
!dequal(createDiscussionPermission, prevProps.createDiscussionPermission)
|
|
|
|
) {
|
|
|
|
this.handleHasPermission();
|
|
|
|
this.setHeader();
|
|
|
|
}
|
2017-11-07 20:25:04 +00:00
|
|
|
}
|
2018-03-02 21:31:44 +00:00
|
|
|
|
2017-08-09 16:19:17 +00:00
|
|
|
componentWillUnmount() {
|
2020-07-20 16:44:54 +00:00
|
|
|
this.unsubscribeQuery();
|
2020-06-15 14:00:46 +00:00
|
|
|
if (this.unsubscribeFocus) {
|
|
|
|
this.unsubscribeFocus();
|
2019-09-24 18:19:33 +00:00
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
if (this.unsubscribeBlur) {
|
|
|
|
this.unsubscribeBlur();
|
2019-05-03 14:54:57 +00:00
|
|
|
}
|
2021-03-05 16:10:21 +00:00
|
|
|
if (this.backHandler && this.backHandler.remove) {
|
|
|
|
this.backHandler.remove();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
console.countReset(`${this.constructor.name}.render calls`);
|
2017-08-12 20:52:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 13:59:40 +00:00
|
|
|
handleHasPermission = async () => {
|
|
|
|
const {
|
|
|
|
createTeamPermission,
|
|
|
|
createDirectMessagePermission,
|
|
|
|
createPublicChannelPermission,
|
|
|
|
createPrivateChannelPermission,
|
|
|
|
createDiscussionPermission
|
|
|
|
} = this.props;
|
|
|
|
const permissions = [
|
|
|
|
createPublicChannelPermission,
|
|
|
|
createPrivateChannelPermission,
|
|
|
|
createTeamPermission,
|
|
|
|
createDirectMessagePermission,
|
|
|
|
createDiscussionPermission
|
|
|
|
];
|
2022-04-28 20:37:25 +00:00
|
|
|
const permissionsToCreate = await hasPermission(permissions);
|
2022-02-25 18:59:39 +00:00
|
|
|
const canCreateRoom = permissionsToCreate.filter((r: boolean) => r === true).length > 0;
|
2021-10-05 13:59:40 +00:00
|
|
|
this.setState({ canCreateRoom }, () => this.setHeader());
|
|
|
|
};
|
|
|
|
|
2022-07-06 13:23:02 +00:00
|
|
|
getHeader = (): StackNavigationOptions => {
|
2021-10-05 13:59:40 +00:00
|
|
|
const { searching, canCreateRoom } = this.state;
|
2023-02-14 13:47:56 +00:00
|
|
|
const { navigation, isMasterDetail, notificationPresenceCap } = this.props;
|
2022-07-06 13:23:02 +00:00
|
|
|
if (searching) {
|
|
|
|
return {
|
|
|
|
headerTitleAlign: 'left',
|
|
|
|
headerTitleContainerStyle: { flex: 1, marginHorizontal: 0, marginRight: 15, maxWidth: undefined },
|
|
|
|
headerRightContainerStyle: { flexGrow: 0 },
|
|
|
|
headerLeft: () => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<HeaderButton.Container left>
|
|
|
|
<HeaderButton.Item iconName='close' onPress={this.cancelSearch} />
|
|
|
|
</HeaderButton.Container>
|
|
|
|
),
|
2022-07-06 13:23:02 +00:00
|
|
|
headerTitle: () => <RoomsListHeaderView />,
|
|
|
|
headerRight: () => null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
headerTitleAlign: 'left',
|
|
|
|
headerTitleContainerStyle: { flex: 1, marginHorizontal: 4, maxWidth: undefined },
|
|
|
|
headerRightContainerStyle: { flexGrow: undefined, flexBasis: undefined },
|
|
|
|
headerLeft: () => (
|
|
|
|
<HeaderButton.Drawer
|
|
|
|
navigation={navigation}
|
|
|
|
testID='rooms-list-view-sidebar'
|
|
|
|
onPress={
|
|
|
|
isMasterDetail
|
|
|
|
? () => navigation.navigate('ModalStackNavigator', { screen: 'SettingsView' })
|
|
|
|
: // @ts-ignore
|
|
|
|
() => navigation.toggleDrawer()
|
|
|
|
}
|
2023-02-14 13:47:56 +00:00
|
|
|
badge={() => (notificationPresenceCap ? <HeaderButton.BadgeWarn /> : null)}
|
2022-07-06 13:23:02 +00:00
|
|
|
/>
|
|
|
|
),
|
|
|
|
headerTitle: () => <RoomsListHeaderView />,
|
|
|
|
headerRight: () => (
|
|
|
|
<HeaderButton.Container>
|
|
|
|
{canCreateRoom ? (
|
|
|
|
<HeaderButton.Item iconName='create' onPress={this.goToNewMessage} testID='rooms-list-view-create-channel' />
|
|
|
|
) : null}
|
|
|
|
<HeaderButton.Item iconName='search' onPress={this.initSearching} testID='rooms-list-view-search' />
|
|
|
|
<HeaderButton.Item iconName='directory' onPress={this.goDirectory} testID='rooms-list-view-directory' />
|
|
|
|
</HeaderButton.Container>
|
|
|
|
)
|
2020-06-15 14:00:46 +00:00
|
|
|
};
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
setHeader = () => {
|
|
|
|
const { navigation } = this.props;
|
2022-07-06 13:23:02 +00:00
|
|
|
const options = this.getHeader();
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.setOptions(options);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-05-16 18:14:04 +00:00
|
|
|
internalSetState = (
|
|
|
|
state:
|
|
|
|
| ((
|
|
|
|
prevState: Readonly<IRoomsListViewState>,
|
|
|
|
props: Readonly<IRoomsListViewProps>
|
|
|
|
) => Pick<IRoomsListViewState, keyof IRoomsListViewState> | IRoomsListViewState | null)
|
|
|
|
| (Pick<IRoomsListViewState, keyof IRoomsListViewState> | IRoomsListViewState | null),
|
|
|
|
callback?: () => void
|
|
|
|
) => {
|
2020-02-17 19:06:18 +00:00
|
|
|
if (this.animated) {
|
2019-09-19 13:32:24 +00:00
|
|
|
animateNextTransition();
|
2018-10-29 13:54:23 +00:00
|
|
|
}
|
2022-05-16 18:14:04 +00:00
|
|
|
this.setState(state, callback);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
addRoomsGroup = (data: TSubscriptionModel[], header: string, allData: TSubscriptionModel[]) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (data.length > 0) {
|
|
|
|
if (header) {
|
2022-02-25 18:59:39 +00:00
|
|
|
allData.push({ rid: header, separator: true } as TSubscriptionModel);
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
allData = allData.concat(data);
|
|
|
|
}
|
|
|
|
return allData;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getSubscriptions = async () => {
|
2020-07-20 16:44:54 +00:00
|
|
|
this.unsubscribeQuery();
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const { sortBy, showUnread, showFavorites, groupByType, user } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2020-07-20 16:44:54 +00:00
|
|
|
let observable;
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
const defaultWhereClause = [Q.where('archived', false), Q.where('open', true)] as (Q.WhereDescription | Q.SortBy)[];
|
2020-07-20 16:44:54 +00:00
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
if (sortBy === SortBy.Alphabetical) {
|
2021-09-13 20:41:05 +00:00
|
|
|
defaultWhereClause.push(Q.experimentalSortBy(`${this.useRealName ? 'fname' : 'name'}`, Q.asc));
|
2020-07-20 16:44:54 +00:00
|
|
|
} else {
|
|
|
|
defaultWhereClause.push(Q.experimentalSortBy('room_updated_at', Q.desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we're grouping by something
|
|
|
|
if (this.isGrouping) {
|
2022-02-01 13:39:09 +00:00
|
|
|
observable = await db
|
2020-07-20 16:44:54 +00:00
|
|
|
.get('subscriptions')
|
|
|
|
.query(...defaultWhereClause)
|
2022-04-20 20:53:11 +00:00
|
|
|
.observeWithColumns(['alert', 'on_hold']);
|
2021-09-13 20:41:05 +00:00
|
|
|
// When we're NOT grouping
|
2020-07-20 16:44:54 +00:00
|
|
|
} else {
|
|
|
|
this.count += QUERY_SIZE;
|
2022-02-01 13:39:09 +00:00
|
|
|
observable = await db
|
2020-07-20 16:44:54 +00:00
|
|
|
.get('subscriptions')
|
2021-09-13 20:41:05 +00:00
|
|
|
.query(...defaultWhereClause, Q.experimentalSkip(0), Q.experimentalTake(this.count))
|
2022-04-20 20:53:11 +00:00
|
|
|
.observeWithColumns(['on_hold']);
|
2020-07-20 16:44:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
this.querySubscription = observable.subscribe(data => {
|
2022-02-25 18:59:39 +00:00
|
|
|
let tempChats = [] as TSubscriptionModel[];
|
2020-07-20 16:44:54 +00:00
|
|
|
let chats = data;
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-04-20 20:53:11 +00:00
|
|
|
let omnichannelsUpdate: string[] = [];
|
2020-08-25 12:10:15 +00:00
|
|
|
const isOmnichannelAgent = user?.roles?.includes('livechat-agent');
|
|
|
|
if (isOmnichannelAgent) {
|
|
|
|
const omnichannel = chats.filter(s => filterIsOmnichannel(s));
|
2022-04-20 20:53:11 +00:00
|
|
|
const omnichannelInProgress = omnichannel.filter(s => !s.onHold);
|
|
|
|
const omnichannelOnHold = omnichannel.filter(s => s.onHold);
|
2020-08-25 12:10:15 +00:00
|
|
|
chats = chats.filter(s => !filterIsOmnichannel(s));
|
2022-04-20 20:53:11 +00:00
|
|
|
omnichannelsUpdate = omnichannelInProgress.map(s => s.rid);
|
|
|
|
tempChats = this.addRoomsGroup(omnichannelInProgress, OMNICHANNEL_HEADER_IN_PROGRESS, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(omnichannelOnHold, OMNICHANNEL_HEADER_ON_HOLD, tempChats);
|
2020-08-25 12:10:15 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// unread
|
2018-09-25 19:28:42 +00:00
|
|
|
if (showUnread) {
|
2019-12-03 12:32:02 +00:00
|
|
|
const unread = chats.filter(s => filterIsUnread(s));
|
|
|
|
chats = chats.filter(s => !filterIsUnread(s));
|
2019-11-25 20:01:17 +00:00
|
|
|
tempChats = this.addRoomsGroup(unread, UNREAD_HEADER, tempChats);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// favorites
|
2018-09-25 19:28:42 +00:00
|
|
|
if (showFavorites) {
|
2019-12-03 12:32:02 +00:00
|
|
|
const favorites = chats.filter(s => filterIsFavorite(s));
|
|
|
|
chats = chats.filter(s => !filterIsFavorite(s));
|
|
|
|
tempChats = this.addRoomsGroup(favorites, FAVORITES_HEADER, tempChats);
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
// type
|
2018-09-25 19:28:42 +00:00
|
|
|
if (groupByType) {
|
2021-04-07 18:31:25 +00:00
|
|
|
const teams = chats.filter(s => filterIsTeam(s));
|
|
|
|
const discussions = chats.filter(s => filterIsDiscussion(s));
|
2021-07-13 19:35:21 +00:00
|
|
|
const channels = chats.filter(s => (s.t === 'c' || s.t === 'p') && !filterIsDiscussion(s) && !filterIsTeam(s));
|
2021-04-07 18:31:25 +00:00
|
|
|
const direct = chats.filter(s => s.t === 'd' && !filterIsDiscussion(s) && !filterIsTeam(s));
|
|
|
|
tempChats = this.addRoomsGroup(teams, TEAMS_HEADER, tempChats);
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = this.addRoomsGroup(discussions, DISCUSSIONS_HEADER, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(channels, CHANNELS_HEADER, tempChats);
|
|
|
|
tempChats = this.addRoomsGroup(direct, DM_HEADER, tempChats);
|
2020-08-25 12:10:15 +00:00
|
|
|
} else if (showUnread || showFavorites || isOmnichannelAgent) {
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = this.addRoomsGroup(chats, CHATS_HEADER, tempChats);
|
2019-11-25 20:01:17 +00:00
|
|
|
} else {
|
2019-12-03 12:32:02 +00:00
|
|
|
tempChats = chats;
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 16:42:10 +00:00
|
|
|
const chatsUpdate = tempChats.map(item => item.rid);
|
|
|
|
|
2022-05-16 18:14:04 +00:00
|
|
|
this.internalSetState({
|
|
|
|
chats: tempChats,
|
|
|
|
chatsUpdate,
|
|
|
|
omnichannelsUpdate,
|
|
|
|
loading: false
|
|
|
|
});
|
2019-04-17 18:57:46 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-10-18 17:56:49 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
unsubscribeQuery = () => {
|
|
|
|
if (this.querySubscription && this.querySubscription.unsubscribe) {
|
|
|
|
this.querySubscription.unsubscribe();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-20 16:44:54 +00:00
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
initSearching = () => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_SEARCH);
|
2023-01-06 15:36:23 +00:00
|
|
|
const { dispatch, showServerDropdown } = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
this.internalSetState({ searching: true }, () => {
|
2023-01-06 15:36:23 +00:00
|
|
|
if (showServerDropdown) {
|
|
|
|
dispatch(closeServerDropdown());
|
|
|
|
}
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(openSearchHeader());
|
2022-04-28 20:37:25 +00:00
|
|
|
this.handleSearch('');
|
2020-07-06 20:56:28 +00:00
|
|
|
this.setHeader();
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
cancelSearch = () => {
|
|
|
|
const { searching } = this.state;
|
2022-01-14 22:06:55 +00:00
|
|
|
const { dispatch } = this.props;
|
2020-02-13 19:24:39 +00:00
|
|
|
|
|
|
|
if (!searching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
Keyboard.dismiss();
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
this.setState({ searching: false, search: [] }, () => {
|
2020-07-06 20:56:28 +00:00
|
|
|
this.setHeader();
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(closeSearchHeader());
|
2020-02-13 19:24:39 +00:00
|
|
|
setTimeout(() => {
|
2020-07-08 16:36:37 +00:00
|
|
|
this.scrollToTop();
|
2020-02-13 19:24:39 +00:00
|
|
|
}, 200);
|
|
|
|
});
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
handleBackPress = () => {
|
2018-11-27 19:40:53 +00:00
|
|
|
const { searching } = this.state;
|
|
|
|
if (searching) {
|
2020-02-13 19:24:39 +00:00
|
|
|
this.cancelSearch();
|
2018-11-27 19:40:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-02-16 18:34:25 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2022-04-28 20:37:25 +00:00
|
|
|
handleSearch = debounce(async (text: string) => {
|
|
|
|
const result = await search({ text });
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
// if the search was cancelled before the promise is resolved
|
2020-06-15 14:00:46 +00:00
|
|
|
const { searching } = this.state;
|
2020-02-13 19:24:39 +00:00
|
|
|
if (!searching) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
this.internalSetState({
|
2022-05-16 18:14:04 +00:00
|
|
|
search: result as IRoomItem[],
|
2020-02-13 19:24:39 +00:00
|
|
|
searching: true
|
2018-08-31 18:13:30 +00:00
|
|
|
});
|
2020-07-08 16:36:37 +00:00
|
|
|
this.scrollToTop();
|
2019-09-16 20:26:32 +00:00
|
|
|
}, 300);
|
2017-08-10 16:16:32 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
isSwipeEnabled = (item: IRoomItem) => !(item?.search || item?.joinCodeRequired || item?.outside);
|
2021-10-20 16:34:38 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
get isGrouping() {
|
|
|
|
const { showUnread, showFavorites, groupByType } = this.props;
|
|
|
|
return showUnread || showFavorites || groupByType;
|
|
|
|
}
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
onPressItem = (item = {} as ISubscription) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
2020-04-30 16:03:07 +00:00
|
|
|
if (!navigation.isFocused()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-13 19:02:57 +00:00
|
|
|
|
|
|
|
this.cancelSearch();
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item, isMasterDetail });
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2020-07-08 16:36:37 +00:00
|
|
|
scrollToTop = () => {
|
|
|
|
if (this.scroll?.scrollToOffset) {
|
|
|
|
this.scroll.scrollToOffset({ offset: 0 });
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-08 16:36:37 +00:00
|
|
|
|
2022-06-27 18:23:43 +00:00
|
|
|
toggleFav = async (rid: string, favorite: boolean): Promise<void> => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(favorite ? events.RL_UNFAVORITE_CHANNEL : events.RL_FAVORITE_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.toggleFavorite(rid, !favorite);
|
2019-07-15 16:54:28 +00:00
|
|
|
if (result.success) {
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
2022-02-25 18:59:39 +00:00
|
|
|
await db.write(async () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
2021-09-13 20:41:05 +00:00
|
|
|
await subRecord.update(sub => {
|
2019-09-16 20:26:32 +00:00
|
|
|
sub.f = !favorite;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-07-15 16:54:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2022-02-25 18:59:39 +00:00
|
|
|
logEvent(events.RL_TOGGLE_FAVORITE_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
toggleRead = async (rid: string, tIsRead: boolean) => {
|
|
|
|
logEvent(tIsRead ? events.RL_UNREAD_CHANNEL : events.RL_READ_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.toggleRead(tIsRead, rid);
|
2021-08-27 16:33:29 +00:00
|
|
|
|
2019-07-04 16:15:30 +00:00
|
|
|
if (result.success) {
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
2022-02-25 18:59:39 +00:00
|
|
|
await db.write(async () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
2021-09-13 20:41:05 +00:00
|
|
|
await subRecord.update(sub => {
|
2022-04-28 20:37:25 +00:00
|
|
|
sub.alert = tIsRead;
|
2021-08-27 16:33:29 +00:00
|
|
|
sub.unread = 0;
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-07-04 16:15:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_TOGGLE_READ_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
2022-06-27 18:23:43 +00:00
|
|
|
hideChannel = async (rid: string, type: SubscriptionType) => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_HIDE_CHANNEL);
|
2019-07-01 14:20:38 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2022-06-27 18:23:43 +00:00
|
|
|
const result = await Services.hideRoom(rid, type as RoomTypes);
|
2019-07-04 16:15:30 +00:00
|
|
|
if (result.success) {
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
2022-02-25 18:59:39 +00:00
|
|
|
await db.write(async () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const subRecord = await subCollection.find(rid);
|
|
|
|
await subRecord.destroyPermanently();
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2019-07-04 16:15:30 +00:00
|
|
|
});
|
|
|
|
}
|
2019-07-01 14:20:38 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_HIDE_CHANNEL_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-01 14:20:38 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-07-01 14:20:38 +00:00
|
|
|
|
2019-06-10 16:22:35 +00:00
|
|
|
goDirectory = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_DIRECTORY);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'DirectoryView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('DirectoryView');
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
goQueue = () => {
|
|
|
|
logEvent(events.RL_GO_QUEUE);
|
2022-04-15 03:11:36 +00:00
|
|
|
const { navigation, isMasterDetail, inquiryEnabled } = this.props;
|
2020-08-21 13:38:50 +00:00
|
|
|
|
|
|
|
if (!inquiryEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-15 03:11:36 +00:00
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'QueueListView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('QueueListView');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
goRoom = ({ item, isMasterDetail }: { item: ISubscription; isMasterDetail: boolean }) => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_ROOM);
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item: currentItem } = this.state;
|
2022-11-25 13:21:56 +00:00
|
|
|
const { subscribedRoom } = this.props;
|
|
|
|
|
|
|
|
if (currentItem?.rid === item.rid || subscribedRoom === item.rid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only mark room as focused when in master detail layout
|
|
|
|
if (isMasterDetail) {
|
|
|
|
this.setState({ item });
|
|
|
|
}
|
|
|
|
goRoom({ item, isMasterDetail });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
goRoomByIndex = (index: number) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
2022-05-16 18:14:04 +00:00
|
|
|
const filteredChats = chats ? chats.filter(c => !c.separator) : [];
|
2019-11-25 20:01:17 +00:00
|
|
|
const room = filteredChats[index - 1];
|
|
|
|
if (room) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item: room, isMasterDetail });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
findOtherRoom = (index: number, sign: number): ISubscription | void => {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { chats } = this.state;
|
|
|
|
const otherIndex = index + sign;
|
2022-05-16 18:14:04 +00:00
|
|
|
const otherRoom = chats?.length ? chats[otherIndex] : ({} as IRoomItem);
|
2019-11-25 20:01:17 +00:00
|
|
|
if (!otherRoom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (otherRoom.separator) {
|
|
|
|
return this.findOtherRoom(otherIndex, sign);
|
|
|
|
}
|
2022-02-25 18:59:39 +00:00
|
|
|
return otherRoom;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
|
|
|
// Go to previous or next room based on sign (-1 or 1)
|
|
|
|
// It's used by iPad key commands
|
2022-02-25 18:59:39 +00:00
|
|
|
goOtherRoom = (sign: number) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { item } = this.state;
|
|
|
|
if (!item) {
|
2019-11-25 20:01:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
// Don't run during search
|
|
|
|
const { search } = this.state;
|
2022-05-16 18:14:04 +00:00
|
|
|
if (search && search?.length > 0) {
|
2019-11-25 20:01:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { chats } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
2022-05-16 18:14:04 +00:00
|
|
|
|
|
|
|
if (!chats?.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
const index = chats.findIndex(c => c.rid === item.rid);
|
2019-11-25 20:01:17 +00:00
|
|
|
const otherRoom = this.findOtherRoom(index, sign);
|
|
|
|
if (otherRoom) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoom({ item: otherRoom, isMasterDetail });
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2020-07-30 13:26:17 +00:00
|
|
|
goToNewMessage = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RL_GO_NEW_MSG);
|
2020-07-30 13:26:17 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'NewMessageView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('NewMessageStackNavigator');
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-30 13:26:17 +00:00
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
goEncryption = () => {
|
|
|
|
logEvent(events.RL_GO_E2E_SAVE_PASSWORD);
|
|
|
|
const { navigation, isMasterDetail, encryptionBanner } = this.props;
|
|
|
|
|
|
|
|
const isSavePassword = encryptionBanner === E2E_BANNER_TYPE.SAVE_PASSWORD;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
const screen = isSavePassword ? 'E2ESaveYourPasswordView' : 'E2EEnterYourPasswordView';
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen });
|
|
|
|
} else {
|
|
|
|
const screen = isSavePassword ? 'E2ESaveYourPasswordStackNavigator' : 'E2EEnterYourPasswordStackNavigator';
|
|
|
|
navigation.navigate(screen);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
handleCommands = ({ event }: { event: IKeyCommandEvent }) => {
|
2022-02-02 18:27:10 +00:00
|
|
|
const { navigation, server, isMasterDetail, dispatch } = this.props;
|
2019-11-25 20:01:17 +00:00
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandShowPreferences(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('SettingsView');
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSearching(event)) {
|
2020-07-06 20:56:28 +00:00
|
|
|
this.initSearching();
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSelectRoom(event)) {
|
|
|
|
this.goRoomByIndex(input);
|
|
|
|
} else if (handleCommandPreviousRoom(event)) {
|
|
|
|
this.goOtherRoom(-1);
|
|
|
|
} else if (handleCommandNextRoom(event)) {
|
|
|
|
this.goOtherRoom(1);
|
|
|
|
} else if (handleCommandShowNewMessage(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'NewMessageView' });
|
|
|
|
} else {
|
|
|
|
navigation.navigate('NewMessageStack');
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandAddNewServer(event)) {
|
2021-09-23 14:17:53 +00:00
|
|
|
batch(() => {
|
2022-02-02 18:27:10 +00:00
|
|
|
dispatch(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
|
|
|
dispatch(serverInitAdd(server));
|
2021-09-23 14:17:53 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-11 20:13:44 +00:00
|
|
|
onRefresh = () => {
|
2020-02-13 19:24:39 +00:00
|
|
|
const { searching } = this.state;
|
2022-01-14 22:06:55 +00:00
|
|
|
const { dispatch } = this.props;
|
2020-02-13 19:24:39 +00:00
|
|
|
if (searching) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(roomsRequest({ allData: true }));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-11 20:13:44 +00:00
|
|
|
|
2020-07-20 16:44:54 +00:00
|
|
|
onEndReached = () => {
|
|
|
|
// Run only when we're not grouping by anything
|
|
|
|
if (!this.isGrouping) {
|
|
|
|
this.getSubscriptions();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-20 16:44:54 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
getScrollRef = (ref: FlatList) => (this.scroll = ref);
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2019-04-17 18:57:46 +00:00
|
|
|
renderListHeader = () => {
|
2020-02-13 19:24:39 +00:00
|
|
|
const { searching } = this.state;
|
2022-03-17 19:25:31 +00:00
|
|
|
const { queueSize, inquiryEnabled, encryptionBanner, user } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
return (
|
2019-04-17 18:57:46 +00:00
|
|
|
<ListHeader
|
2022-05-16 18:14:04 +00:00
|
|
|
searching={searching as boolean}
|
2020-09-11 14:31:38 +00:00
|
|
|
goEncryption={this.goEncryption}
|
2020-07-31 18:22:30 +00:00
|
|
|
goQueue={this.goQueue}
|
|
|
|
queueSize={queueSize}
|
|
|
|
inquiryEnabled={inquiryEnabled}
|
2020-09-11 14:31:38 +00:00
|
|
|
encryptionBanner={encryptionBanner}
|
2020-08-21 13:38:50 +00:00
|
|
|
user={user}
|
2019-04-17 18:57:46 +00:00
|
|
|
/>
|
2018-09-25 19:28:42 +00:00
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
renderHeader = () => {
|
2022-07-06 13:23:02 +00:00
|
|
|
const { isMasterDetail, theme } = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
if (!isMasterDetail) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-17 19:25:31 +00:00
|
|
|
const options = this.getHeader();
|
2022-07-06 13:23:02 +00:00
|
|
|
return <Header title='' {...themedHeader(theme)} {...options} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-05-16 18:14:04 +00:00
|
|
|
renderItem = ({ item }: { item: IRoomItem }) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (item.separator) {
|
|
|
|
return this.renderSectionHeader(item.rid);
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:35:58 +00:00
|
|
|
const { item: currentItem } = this.state;
|
2019-03-29 19:36:07 +00:00
|
|
|
const {
|
2020-11-04 16:53:44 +00:00
|
|
|
user: { username },
|
2019-11-25 20:01:17 +00:00
|
|
|
StoreLastMessage,
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName,
|
2020-06-17 17:35:58 +00:00
|
|
|
isMasterDetail,
|
2021-10-06 20:30:10 +00:00
|
|
|
width,
|
|
|
|
showAvatar,
|
|
|
|
displayMode
|
2019-03-29 19:36:07 +00:00
|
|
|
} = this.props;
|
2022-04-28 20:37:25 +00:00
|
|
|
const id = getUidDirectMessage(item);
|
2021-10-20 16:34:38 +00:00
|
|
|
const swipeEnabled = this.isSwipeEnabled(item);
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
return (
|
|
|
|
<RoomItem
|
2020-07-20 16:44:54 +00:00
|
|
|
item={item}
|
2019-09-16 20:26:32 +00:00
|
|
|
id={id}
|
|
|
|
username={username}
|
|
|
|
showLastMessage={StoreLastMessage}
|
2020-07-20 16:44:54 +00:00
|
|
|
onPress={this.onPressItem}
|
2020-06-15 14:00:46 +00:00
|
|
|
width={isMasterDetail ? MAX_SIDEBAR_WIDTH : width}
|
2019-09-16 20:26:32 +00:00
|
|
|
toggleFav={this.toggleFav}
|
|
|
|
toggleRead={this.toggleRead}
|
|
|
|
hideChannel={this.hideChannel}
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName={useRealName}
|
2022-04-28 20:37:25 +00:00
|
|
|
getRoomTitle={getRoomTitle}
|
|
|
|
getRoomAvatar={getRoomAvatar}
|
|
|
|
getIsRead={isRead}
|
2020-06-15 14:00:46 +00:00
|
|
|
isFocused={currentItem?.rid === item.rid}
|
2021-10-20 16:34:38 +00:00
|
|
|
swipeEnabled={swipeEnabled}
|
2021-10-06 20:30:10 +00:00
|
|
|
showAvatar={showAvatar}
|
|
|
|
displayMode={displayMode}
|
2019-09-16 20:26:32 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
renderSectionHeader = (header: string) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<View style={[styles.groupTitleContainer, { backgroundColor: themes[theme].backgroundColor }]}>
|
|
|
|
<Text style={[styles.groupTitle, { color: themes[theme].controlText }]}>{I18n.t(header)}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
renderScroll = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { loading, chats, search, searching } = this.state;
|
2021-10-06 20:30:10 +00:00
|
|
|
const { theme, refreshing, displayMode } = this.props;
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const height = displayMode === DisplayMode.Condensed ? ROW_HEIGHT_CONDENSED : ROW_HEIGHT;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
if (loading) {
|
2022-03-18 02:37:10 +00:00
|
|
|
return <ActivityIndicator />;
|
2018-08-01 19:35:06 +00:00
|
|
|
}
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2018-08-01 19:35:06 +00:00
|
|
|
return (
|
2019-11-25 20:01:17 +00:00
|
|
|
<FlatList
|
2018-09-26 13:56:36 +00:00
|
|
|
ref={this.getScrollRef}
|
2020-02-13 19:24:39 +00:00
|
|
|
data={searching ? search : chats}
|
|
|
|
extraData={searching ? search : chats}
|
2019-11-25 20:01:17 +00:00
|
|
|
keyExtractor={keyExtractor}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.list, { backgroundColor: themes[theme].backgroundColor }]}
|
2019-11-25 20:01:17 +00:00
|
|
|
renderItem={this.renderItem}
|
|
|
|
ListHeaderComponent={this.renderListHeader}
|
2021-10-06 20:30:10 +00:00
|
|
|
getItemLayout={(data, index) => getItemLayout(data, index, height)}
|
2019-11-25 20:01:17 +00:00
|
|
|
removeClippedSubviews={isIOS}
|
2018-08-01 19:35:06 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
2019-11-25 20:01:17 +00:00
|
|
|
initialNumToRender={INITIAL_NUM_TO_RENDER}
|
2021-09-13 20:41:05 +00:00
|
|
|
refreshControl={
|
|
|
|
<RefreshControl refreshing={refreshing} onRefresh={this.onRefresh} tintColor={themes[theme].auxiliaryText} />
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
windowSize={9}
|
2020-07-20 16:44:54 +00:00
|
|
|
onEndReached={this.onEndReached}
|
|
|
|
onEndReachedThreshold={0.5}
|
2019-11-25 20:01:17 +00:00
|
|
|
/>
|
2018-08-01 19:35:06 +00:00
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-09-21 17:08:00 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
render = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
console.count(`${this.constructor.name}.render calls`);
|
2021-10-06 20:30:10 +00:00
|
|
|
const { showServerDropdown, theme, navigation } = this.props;
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
return (
|
2020-10-30 13:59:44 +00:00
|
|
|
<SafeAreaView testID='rooms-list-view' style={{ backgroundColor: themes[theme].backgroundColor }}>
|
|
|
|
<StatusBar />
|
2020-06-15 14:00:46 +00:00
|
|
|
{this.renderHeader()}
|
2018-08-31 16:46:33 +00:00
|
|
|
{this.renderScroll()}
|
2022-02-25 18:59:39 +00:00
|
|
|
{/* TODO - this ts-ignore is here because the route props, on IBaseScreen*/}
|
|
|
|
{/* @ts-ignore*/}
|
|
|
|
{showServerDropdown ? <ServerDropdown navigation={navigation} theme={theme} /> : null}
|
2018-08-31 16:46:33 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
2017-08-03 18:23:43 +00:00
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
2023-02-14 13:47:56 +00:00
|
|
|
notificationPresenceCap: state.app.notificationPresenceCap,
|
2019-08-07 13:51:34 +00:00
|
|
|
server: state.server.server,
|
2021-01-13 14:16:00 +00:00
|
|
|
changingServer: state.server.changingServer,
|
2019-08-07 13:51:34 +00:00
|
|
|
searchText: state.rooms.searchText,
|
|
|
|
loadingServer: state.server.loading,
|
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
2020-02-11 20:13:44 +00:00
|
|
|
refreshing: state.rooms.refreshing,
|
2019-08-07 13:51:34 +00:00
|
|
|
sortBy: state.sortPreferences.sortBy,
|
|
|
|
groupByType: state.sortPreferences.groupByType,
|
|
|
|
showFavorites: state.sortPreferences.showFavorites,
|
|
|
|
showUnread: state.sortPreferences.showUnread,
|
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
2020-06-15 14:00:46 +00:00
|
|
|
StoreLastMessage: state.settings.Store_Last_Message,
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: state.room.subscribedRoom,
|
2020-07-31 18:22:30 +00:00
|
|
|
queueSize: getInquiryQueueSelector(state).length,
|
2020-09-11 14:31:38 +00:00
|
|
|
inquiryEnabled: state.inquiry.enabled,
|
2021-10-05 13:59:40 +00:00
|
|
|
encryptionBanner: state.encryption.banner,
|
2021-10-06 20:30:10 +00:00
|
|
|
showAvatar: state.sortPreferences.showAvatar,
|
|
|
|
displayMode: state.sortPreferences.displayMode,
|
2021-10-05 13:59:40 +00:00
|
|
|
createTeamPermission: state.permissions['create-team'],
|
|
|
|
createDirectMessagePermission: state.permissions['create-d'],
|
|
|
|
createPublicChannelPermission: state.permissions['create-c'],
|
|
|
|
createPrivateChannelPermission: state.permissions['create-p'],
|
|
|
|
createDiscussionPermission: state.permissions['start-discussion']
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2022-01-14 22:06:55 +00:00
|
|
|
export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomsListView))));
|