2017-08-04 00:34:37 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { InteractionManager, Text, View } from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-05-26 17:24:54 +00:00
|
|
|
import parse from 'url-parse';
|
2019-03-27 20:06:57 +00:00
|
|
|
import moment from 'moment';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
import { Subscription } from 'rxjs';
|
2017-08-13 01:35:09 +00:00
|
|
|
|
2022-06-09 14:42:12 +00:00
|
|
|
import { getRoutingConfig } from '../../lib/services/restApi';
|
2022-08-17 13:32:21 +00:00
|
|
|
import Touch from '../../containers/Touch';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { replyBroadcast } from '../../actions/messages';
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2017-12-08 19:13:21 +00:00
|
|
|
import Message from '../../containers/message';
|
2022-03-02 14:18:01 +00:00
|
|
|
import MessageActions, { IMessageActions } from '../../containers/MessageActions';
|
2022-05-02 22:58:23 +00:00
|
|
|
import MessageErrorActions, { IMessageErrorActions } from '../../containers/MessageErrorActions';
|
|
|
|
import MessageBox, { MessageBoxType } from '../../containers/MessageBox';
|
2022-06-06 14:17:51 +00:00
|
|
|
import log, { events, logEvent } from '../../lib/methods/helpers/log';
|
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2021-04-07 18:31:25 +00:00
|
|
|
import RoomHeader from '../../containers/RoomHeader';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2022-08-03 16:32:16 +00:00
|
|
|
import ReactionsList from '../../containers/ReactionsList';
|
2019-07-23 14:02:57 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
2022-07-06 13:23:02 +00:00
|
|
|
import { getBadgeColor, isBlocked, makeThreadName } from '../../lib/methods/helpers/room';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { isReadOnly } from '../../lib/methods/helpers/isReadOnly';
|
|
|
|
import { showErrorAlert } from '../../lib/methods/helpers/info';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import {
|
|
|
|
KEY_COMMAND,
|
2021-09-13 20:41:05 +00:00
|
|
|
handleCommandReplyLatest,
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommandRoomActions,
|
2021-09-13 20:41:05 +00:00
|
|
|
handleCommandScroll,
|
2022-03-02 14:18:01 +00:00
|
|
|
handleCommandSearchMessages,
|
|
|
|
IKeyCommandEvent
|
2019-11-25 20:01:17 +00:00
|
|
|
} from '../../commands';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { Review } from '../../lib/methods/helpers/review';
|
2020-02-05 13:34:53 +00:00
|
|
|
import RoomClass from '../../lib/methods/subscriptions/room';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from '../../lib/navigation/appNavigation';
|
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';
|
2022-04-20 20:53:11 +00:00
|
|
|
import { takeInquiry, takeResume } from '../../ee/omnichannel/lib';
|
2022-08-19 21:14:37 +00:00
|
|
|
import { sendLoadingEvent } from '../../containers/Loading';
|
2021-05-26 17:24:54 +00:00
|
|
|
import getThreadName from '../../lib/methods/getThreadName';
|
|
|
|
import getRoomInfo from '../../lib/methods/getRoomInfo';
|
2022-03-16 19:07:49 +00:00
|
|
|
import { ContainerTypes } from '../../containers/UIKit/interfaces';
|
2021-09-13 20:41:05 +00:00
|
|
|
import RoomServices from './services';
|
|
|
|
import LoadMore from './LoadMore';
|
|
|
|
import Banner from './Banner';
|
|
|
|
import Separator from './Separator';
|
|
|
|
import RightButtons from './RightButtons';
|
|
|
|
import LeftButtons from './LeftButtons';
|
|
|
|
import styles from './styles';
|
2022-05-02 22:58:23 +00:00
|
|
|
import JoinCode, { IJoinCode } from './JoinCode';
|
2021-09-13 20:41:05 +00:00
|
|
|
import UploadProgress from './UploadProgress';
|
|
|
|
import ReactionPicker from './ReactionPicker';
|
2022-05-02 22:58:23 +00:00
|
|
|
import List, { ListContainerType } from './List';
|
2022-03-02 14:18:01 +00:00
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
|
|
|
import {
|
|
|
|
IApplicationState,
|
|
|
|
IAttachment,
|
|
|
|
IBaseScreen,
|
2022-06-09 14:42:12 +00:00
|
|
|
ILastMessage,
|
2022-03-02 14:18:01 +00:00
|
|
|
ILoggedUser,
|
|
|
|
IMessage,
|
2022-04-15 02:27:36 +00:00
|
|
|
IOmnichannelSource,
|
2022-03-02 14:18:01 +00:00
|
|
|
ISubscription,
|
|
|
|
IVisitor,
|
|
|
|
SubscriptionType,
|
|
|
|
TAnyMessageModel,
|
2022-04-01 15:32:17 +00:00
|
|
|
TMessageModel,
|
2022-03-02 14:18:01 +00:00
|
|
|
TSubscriptionModel,
|
2022-05-07 01:06:08 +00:00
|
|
|
TThreadModel,
|
2022-10-21 18:27:55 +00:00
|
|
|
ICustomEmojis,
|
2022-05-07 01:06:08 +00:00
|
|
|
IEmoji,
|
2023-01-13 19:32:52 +00:00
|
|
|
TGetCustomEmoji,
|
|
|
|
RoomType
|
2022-03-02 14:18:01 +00:00
|
|
|
} from '../../definitions';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { E2E_MESSAGE_TYPE, E2E_STATUS, MESSAGE_TYPE_ANY_LOAD, MessageTypeLoad, themes } from '../../lib/constants';
|
2022-05-02 22:58:23 +00:00
|
|
|
import { TListRef } from './List/List';
|
|
|
|
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
|
2022-04-28 20:37:25 +00:00
|
|
|
import {
|
|
|
|
callJitsi,
|
|
|
|
loadSurroundingMessages,
|
|
|
|
loadThreadMessages,
|
|
|
|
readMessages,
|
|
|
|
sendMessage,
|
|
|
|
triggerBlockAction
|
|
|
|
} from '../../lib/methods';
|
2022-06-06 14:17:51 +00:00
|
|
|
import {
|
|
|
|
isGroupChat,
|
|
|
|
getUidDirectMessage,
|
|
|
|
getRoomTitle,
|
|
|
|
canAutoTranslate as canAutoTranslateMethod,
|
|
|
|
debounce,
|
|
|
|
isIOS,
|
2022-06-09 14:42:12 +00:00
|
|
|
isTablet,
|
|
|
|
hasPermission
|
2022-06-06 14:17:51 +00:00
|
|
|
} from '../../lib/methods/helpers';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2022-08-08 18:38:01 +00:00
|
|
|
import { withActionSheet, IActionSheetProvider } from '../../containers/ActionSheet';
|
2022-11-25 13:21:56 +00:00
|
|
|
import { goRoom, TGoRoomItem } from '../../lib/methods/helpers/goRoom';
|
2020-08-28 19:41:08 +00:00
|
|
|
|
2022-05-02 22:58:23 +00:00
|
|
|
type TStateAttrsUpdate = keyof IRoomViewState;
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const stateAttrsUpdate = [
|
|
|
|
'joined',
|
|
|
|
'lastOpen',
|
|
|
|
'reactionsModalVisible',
|
|
|
|
'canAutoTranslate',
|
2020-06-15 19:35:45 +00:00
|
|
|
'selectedMessage',
|
2019-09-16 20:26:32 +00:00
|
|
|
'loading',
|
|
|
|
'editing',
|
|
|
|
'replying',
|
2020-04-13 12:51:16 +00:00
|
|
|
'readOnly',
|
2021-05-26 17:24:54 +00:00
|
|
|
'member',
|
2022-06-09 14:42:12 +00:00
|
|
|
'canForwardGuest',
|
|
|
|
'canReturnQueue',
|
|
|
|
'canViewCannedResponse'
|
2022-05-02 22:58:23 +00:00
|
|
|
] as TStateAttrsUpdate[];
|
|
|
|
|
|
|
|
type TRoomUpdate = keyof TSubscriptionModel;
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const roomAttrsUpdate = [
|
|
|
|
'f',
|
|
|
|
'ro',
|
|
|
|
'blocked',
|
|
|
|
'blocker',
|
|
|
|
'archived',
|
|
|
|
'tunread',
|
|
|
|
'muted',
|
|
|
|
'ignored',
|
|
|
|
'jitsiTimeout',
|
|
|
|
'announcement',
|
|
|
|
'sysMes',
|
|
|
|
'topic',
|
|
|
|
'name',
|
|
|
|
'fname',
|
|
|
|
'roles',
|
|
|
|
'bannerClosed',
|
|
|
|
'visitor',
|
|
|
|
'joinCodeRequired',
|
|
|
|
'teamMain',
|
2022-04-20 20:53:11 +00:00
|
|
|
'teamId',
|
2022-06-09 14:42:12 +00:00
|
|
|
'status',
|
|
|
|
'lastMessage',
|
2022-07-06 20:08:50 +00:00
|
|
|
'onHold',
|
|
|
|
't'
|
2022-05-02 22:58:23 +00:00
|
|
|
] as TRoomUpdate[];
|
2022-03-02 14:18:01 +00:00
|
|
|
|
2022-08-08 18:38:01 +00:00
|
|
|
interface IRoomViewProps extends IActionSheetProvider, IBaseScreen<ChatsStackParamList, 'RoomView'> {
|
2022-03-02 14:18:01 +00:00
|
|
|
user: Pick<ILoggedUser, 'id' | 'username' | 'token' | 'showMessageInMainThread'>;
|
|
|
|
appState: string;
|
|
|
|
useRealName?: boolean;
|
|
|
|
isAuthenticated: boolean;
|
|
|
|
Message_GroupingPeriod?: number;
|
|
|
|
Message_TimeFormat?: string;
|
|
|
|
Message_Read_Receipt_Enabled?: boolean;
|
|
|
|
Hide_System_Messages?: string[];
|
|
|
|
baseUrl: string;
|
|
|
|
serverVersion: string | null;
|
|
|
|
customEmojis: ICustomEmojis;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
replyBroadcast: Function;
|
|
|
|
width: number;
|
|
|
|
insets: EdgeInsets;
|
2022-06-09 14:42:12 +00:00
|
|
|
transferLivechatGuestPermission?: string[]; // TODO: Check if its the correct type
|
|
|
|
viewCannedResponsesPermission?: string[]; // TODO: Check if its the correct type
|
|
|
|
livechatAllowManualOnHold?: boolean;
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IRoomViewState {
|
|
|
|
[key: string]: any;
|
|
|
|
joined: boolean;
|
2022-05-03 14:27:20 +00:00
|
|
|
room:
|
2023-01-13 19:32:52 +00:00
|
|
|
| TSubscriptionModel
|
|
|
|
| {
|
|
|
|
rid: string;
|
|
|
|
t: string;
|
|
|
|
name?: string;
|
|
|
|
fname?: string;
|
|
|
|
prid?: string;
|
|
|
|
joinCodeRequired?: boolean;
|
|
|
|
status?: string;
|
|
|
|
lastMessage?: ILastMessage;
|
|
|
|
sysMes?: boolean;
|
|
|
|
onHold?: boolean;
|
2022-06-09 14:42:12 +00:00
|
|
|
};
|
2022-03-02 14:18:01 +00:00
|
|
|
roomUpdate: {
|
2022-05-02 22:58:23 +00:00
|
|
|
[K in TRoomUpdate]?: any;
|
2017-09-25 13:15:28 +00:00
|
|
|
};
|
2022-03-02 14:18:01 +00:00
|
|
|
member: any;
|
|
|
|
lastOpen: Date | null;
|
|
|
|
reactionsModalVisible: boolean;
|
2022-04-01 15:32:17 +00:00
|
|
|
selectedMessage?: TAnyMessageModel;
|
2022-03-02 14:18:01 +00:00
|
|
|
canAutoTranslate: boolean;
|
|
|
|
loading: boolean;
|
|
|
|
editing: boolean;
|
|
|
|
replying: boolean;
|
|
|
|
replyWithMention: boolean;
|
|
|
|
readOnly: boolean;
|
|
|
|
unreadsCount: number | null;
|
|
|
|
roomUserId?: string | null;
|
|
|
|
}
|
2017-08-05 18:16:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|
|
|
private rid?: string;
|
|
|
|
private t?: string;
|
|
|
|
private tmid?: string;
|
|
|
|
private jumpToMessageId?: string;
|
|
|
|
private jumpToThreadId?: string;
|
2022-05-02 22:58:23 +00:00
|
|
|
private messagebox: React.RefObject<MessageBoxType>;
|
|
|
|
private list: React.RefObject<ListContainerType>;
|
|
|
|
private joinCode: React.RefObject<IJoinCode>;
|
|
|
|
private flatList: TListRef;
|
2022-03-02 14:18:01 +00:00
|
|
|
private mounted: boolean;
|
|
|
|
private offset = 0;
|
2022-06-09 14:42:12 +00:00
|
|
|
private subObserveQuery?: Subscription;
|
2022-03-02 14:18:01 +00:00
|
|
|
private subSubscription?: Subscription;
|
|
|
|
private queryUnreads?: Subscription;
|
|
|
|
private retryInit = 0;
|
2022-06-06 13:23:49 +00:00
|
|
|
private retryInitTimeout?: ReturnType<typeof setTimeout>;
|
2022-03-02 14:18:01 +00:00
|
|
|
private retryFindCount = 0;
|
2022-06-06 13:23:49 +00:00
|
|
|
private retryFindTimeout?: ReturnType<typeof setTimeout>;
|
2022-05-02 22:58:23 +00:00
|
|
|
private messageErrorActions?: IMessageErrorActions | null;
|
|
|
|
private messageActions?: IMessageActions | null;
|
2022-11-04 17:09:58 +00:00
|
|
|
private replyInDM?: TAnyMessageModel;
|
2022-05-02 22:58:23 +00:00
|
|
|
// Type of InteractionManager.runAfterInteractions
|
|
|
|
private didMountInteraction?: {
|
|
|
|
then: (onfulfilled?: (() => any) | undefined, onrejected?: (() => any) | undefined) => Promise<any>;
|
|
|
|
done: (...args: any[]) => any;
|
|
|
|
cancel: () => void;
|
|
|
|
};
|
|
|
|
private sub?: RoomClass;
|
2022-03-02 14:18:01 +00:00
|
|
|
|
|
|
|
constructor(props: IRoomViewProps) {
|
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`);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
2022-03-02 14:18:01 +00:00
|
|
|
/**
|
|
|
|
* On threads, we don't have a subscription.
|
|
|
|
* `this.state.room` is going to have only a few properties sent during navigation.
|
|
|
|
* Use `this.tmid` as thread id.
|
|
|
|
*/
|
2020-06-15 14:00:46 +00:00
|
|
|
this.tmid = props.route.params?.tmid;
|
|
|
|
const selectedMessage = props.route.params?.message;
|
|
|
|
const name = props.route.params?.name;
|
|
|
|
const fname = props.route.params?.fname;
|
|
|
|
const prid = props.route.params?.prid;
|
2020-10-30 17:35:07 +00:00
|
|
|
const room = props.route.params?.room ?? {
|
2022-03-02 14:18:01 +00:00
|
|
|
rid: this.rid as string,
|
|
|
|
t: this.t as string,
|
2021-09-13 20:41:05 +00:00
|
|
|
name,
|
|
|
|
fname,
|
|
|
|
prid
|
2020-10-30 17:35:07 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
this.jumpToMessageId = props.route.params?.jumpToMessageId;
|
2021-10-26 16:11:50 +00:00
|
|
|
this.jumpToThreadId = props.route.params?.jumpToThreadId;
|
2022-04-28 20:37:25 +00:00
|
|
|
const roomUserId = props.route.params?.roomUserId ?? getUidDirectMessage(room);
|
2022-11-04 17:09:58 +00:00
|
|
|
this.replyInDM = props.route.params?.replyInDM;
|
2017-08-07 18:42:02 +00:00
|
|
|
this.state = {
|
2019-09-16 20:26:32 +00:00
|
|
|
joined: true,
|
2020-10-30 17:35:07 +00:00
|
|
|
room,
|
2019-09-16 20:26:32 +00:00
|
|
|
roomUpdate: {},
|
2020-03-30 20:19:01 +00:00
|
|
|
member: {},
|
2019-05-20 20:43:50 +00:00
|
|
|
lastOpen: null,
|
|
|
|
reactionsModalVisible: false,
|
2022-03-02 14:18:01 +00:00
|
|
|
selectedMessage,
|
2019-09-16 20:26:32 +00:00
|
|
|
canAutoTranslate: false,
|
|
|
|
loading: true,
|
|
|
|
editing: false,
|
|
|
|
replying: !!selectedMessage,
|
|
|
|
replyWithMention: false,
|
2020-06-15 14:00:46 +00:00
|
|
|
readOnly: false,
|
|
|
|
unreadsCount: null,
|
2022-06-09 14:42:12 +00:00
|
|
|
roomUserId,
|
|
|
|
canViewCannedResponse: false,
|
|
|
|
canForwardGuest: false,
|
|
|
|
canReturnQueue: false,
|
|
|
|
canPlaceLivechatOnHold: false,
|
|
|
|
isOnHold: false
|
2017-08-07 18:42:02 +00:00
|
|
|
};
|
2022-06-09 14:42:12 +00:00
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room) {
|
|
|
|
// @ts-ignore TODO: type guard isn't helping here :(
|
2019-09-16 20:26:32 +00:00
|
|
|
this.observeRoom(room);
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (this.rid) {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.findAndObserveRoom(this.rid);
|
|
|
|
}
|
|
|
|
|
2020-04-13 12:51:16 +00:00
|
|
|
this.setReadOnly();
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
this.messagebox = React.createRef();
|
2019-11-07 19:53:39 +00:00
|
|
|
this.list = React.createRef();
|
2020-12-01 17:30:39 +00:00
|
|
|
this.joinCode = React.createRef();
|
2021-05-26 17:24:54 +00:00
|
|
|
this.flatList = React.createRef();
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
2021-02-11 21:42:50 +00:00
|
|
|
|
2022-06-09 14:42:12 +00:00
|
|
|
if (this.t === 'l') {
|
|
|
|
this.updateOmnichannel();
|
|
|
|
}
|
|
|
|
|
2021-02-11 21:42:50 +00:00
|
|
|
// we don't need to subscribe to threads
|
|
|
|
if (this.rid && !this.tmid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.sub = new RoomClass(this.rid);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
console.timeEnd(`${this.constructor.name} init`);
|
2017-08-07 00:34:35 +00:00
|
|
|
}
|
2017-08-04 00:34:37 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
componentDidMount() {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.mounted = true;
|
2019-04-17 17:01:03 +00:00
|
|
|
this.didMountInteraction = InteractionManager.runAfterInteractions(() => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isAuthenticated } = this.props;
|
|
|
|
this.setHeader();
|
2020-04-03 18:03:53 +00:00
|
|
|
if (this.rid) {
|
2021-02-11 21:42:50 +00:00
|
|
|
this.sub?.subscribe?.();
|
2020-04-03 18:03:53 +00:00
|
|
|
if (isAuthenticated) {
|
|
|
|
this.init();
|
|
|
|
} else {
|
|
|
|
EventEmitter.addEventListener('connected', this.handleConnected);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
if (this.jumpToMessageId) {
|
|
|
|
this.jumpToMessage(this.jumpToMessageId);
|
|
|
|
}
|
2021-10-26 16:11:50 +00:00
|
|
|
if (this.jumpToThreadId && !this.jumpToMessageId) {
|
|
|
|
this.navToThread({ tmid: this.jumpToThreadId });
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isIOS && this.rid) {
|
2019-09-16 21:19:14 +00:00
|
|
|
this.updateUnreadCount();
|
|
|
|
}
|
2022-11-04 17:09:58 +00:00
|
|
|
if (this.replyInDM) {
|
|
|
|
this.onReplyInit(this.replyInDM, false);
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-03-06 13:13:24 +00:00
|
|
|
EventEmitter.addEventListener('ROOM_REMOVED', this.handleRoomRemoved);
|
2021-09-13 20:41:05 +00:00
|
|
|
console.timeEnd(`${this.constructor.name} mount`);
|
2018-02-08 14:08:50 +00:00
|
|
|
}
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
shouldComponentUpdate(nextProps: IRoomViewProps, nextState: IRoomViewState) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { state } = this;
|
2022-06-09 14:42:12 +00:00
|
|
|
const { roomUpdate, member, isOnHold } = state;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { appState, theme, insets, route } = this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
if (theme !== nextProps.theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (appState !== nextProps.appState) {
|
2018-12-05 20:52:08 +00:00
|
|
|
return true;
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2020-03-30 20:19:01 +00:00
|
|
|
if (member.statusText !== nextState.member.statusText) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-09 14:42:12 +00:00
|
|
|
if (isOnHold !== nextState.isOnHold) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
const stateUpdated = stateAttrsUpdate.some(key => nextState[key] !== state[key]);
|
|
|
|
if (stateUpdated) {
|
2019-02-07 15:48:10 +00:00
|
|
|
return true;
|
2018-09-26 13:56:36 +00:00
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.insets, insets)) {
|
2020-07-06 20:56:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!dequal(nextProps.route?.params, route?.params)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
return roomAttrsUpdate.some(key => !dequal(nextState.roomUpdate[key], roomUpdate[key]));
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
componentDidUpdate(prevProps: IRoomViewProps, prevState: IRoomViewState) {
|
2022-06-09 14:42:12 +00:00
|
|
|
const { roomUpdate, joined } = this.state;
|
2021-05-26 17:24:54 +00:00
|
|
|
const { appState, insets, route } = this.props;
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if (route?.params?.jumpToMessageId && route?.params?.jumpToMessageId !== prevProps.route?.params?.jumpToMessageId) {
|
2021-05-26 17:24:54 +00:00
|
|
|
this.jumpToMessage(route?.params?.jumpToMessageId);
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if (route?.params?.jumpToThreadId && route?.params?.jumpToThreadId !== prevProps.route?.params?.jumpToThreadId) {
|
2021-10-26 16:11:50 +00:00
|
|
|
this.navToThread({ tmid: route?.params?.jumpToThreadId });
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (appState === 'foreground' && appState !== prevProps.appState && this.rid) {
|
2020-07-20 16:44:54 +00:00
|
|
|
// Fire List.query() just to keep observables working
|
2023-01-09 18:32:16 +00:00
|
|
|
if (this.list && this.list.current && !isIOS) {
|
2022-05-02 22:58:23 +00:00
|
|
|
this.list.current?.query();
|
2020-07-20 16:44:54 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2020-05-08 17:36:10 +00:00
|
|
|
// If it's a livechat room
|
|
|
|
if (this.t === 'l') {
|
2022-06-09 14:42:12 +00:00
|
|
|
if (
|
|
|
|
!dequal(prevState.roomUpdate.lastMessage?.token, roomUpdate.lastMessage?.token) ||
|
|
|
|
!dequal(prevState.roomUpdate.visitor, roomUpdate.visitor) ||
|
|
|
|
!dequal(prevState.roomUpdate.status, roomUpdate.status) ||
|
|
|
|
prevState.joined !== joined
|
|
|
|
) {
|
|
|
|
this.updateOmnichannel();
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-06 20:08:50 +00:00
|
|
|
if (roomAttrsUpdate.some(key => !dequal(prevState.roomUpdate[key], roomUpdate[key]))) this.setHeader();
|
2020-07-06 20:56:28 +00:00
|
|
|
if (insets.left !== prevProps.insets.left || insets.right !== prevProps.insets.right) {
|
|
|
|
this.setHeader();
|
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
this.setReadOnly();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 14:42:12 +00:00
|
|
|
updateOmnichannel = async () => {
|
|
|
|
const canForwardGuest = await this.canForwardGuest();
|
|
|
|
const canPlaceLivechatOnHold = this.canPlaceLivechatOnHold();
|
|
|
|
const canReturnQueue = await this.canReturnQueue();
|
|
|
|
const canViewCannedResponse = await this.canViewCannedResponse();
|
|
|
|
this.setState({ canForwardGuest, canReturnQueue, canViewCannedResponse, canPlaceLivechatOnHold });
|
|
|
|
if (this.mounted) {
|
|
|
|
this.setHeader();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
async componentWillUnmount() {
|
|
|
|
const { editing, room } = this.state;
|
|
|
|
const db = database.active;
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
2019-06-08 11:31:29 +00:00
|
|
|
if (!editing && this.messagebox && this.messagebox.current) {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { text } = this.messagebox.current;
|
2022-03-02 14:18:01 +00:00
|
|
|
let obj: TSubscriptionModel | TThreadModel | null = null;
|
2019-04-24 18:36:29 +00:00
|
|
|
if (this.tmid) {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2021-02-26 16:25:51 +00:00
|
|
|
const threadsCollection = db.get('threads');
|
2019-09-16 20:26:32 +00:00
|
|
|
obj = await threadsCollection.find(this.tmid);
|
|
|
|
} catch (e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
} else {
|
2022-03-02 14:18:01 +00:00
|
|
|
obj = room as TSubscriptionModel;
|
2019-04-24 18:36:29 +00:00
|
|
|
}
|
|
|
|
if (obj) {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2022-05-02 22:58:23 +00:00
|
|
|
const object = obj;
|
2022-03-02 14:18:01 +00:00
|
|
|
await db.write(async () => {
|
2022-05-02 22:58:23 +00:00
|
|
|
await object.update(r => {
|
2019-09-16 20:26:32 +00:00
|
|
|
r.draftMessage = text;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
2020-02-05 13:34:53 +00:00
|
|
|
this.unsubscribe();
|
2019-04-08 12:35:28 +00:00
|
|
|
if (this.didMountInteraction && this.didMountInteraction.cancel) {
|
|
|
|
this.didMountInteraction.cancel();
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.subSubscription && this.subSubscription.unsubscribe) {
|
|
|
|
this.subSubscription.unsubscribe();
|
|
|
|
}
|
2022-06-09 14:42:12 +00:00
|
|
|
|
|
|
|
if (this.subObserveQuery && this.subObserveQuery.unsubscribe) {
|
|
|
|
this.subObserveQuery.unsubscribe();
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.queryUnreads && this.queryUnreads.unsubscribe) {
|
|
|
|
this.queryUnreads.unsubscribe();
|
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
if (this.retryInitTimeout) {
|
|
|
|
clearTimeout(this.retryInitTimeout);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-03-06 13:13:24 +00:00
|
|
|
EventEmitter.removeListener('ROOM_REMOVED', this.handleRoomRemoved);
|
2021-09-13 20:41:05 +00:00
|
|
|
console.countReset(`${this.constructor.name}.render calls`);
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 14:42:12 +00:00
|
|
|
canForwardGuest = async () => {
|
|
|
|
const { transferLivechatGuestPermission } = this.props;
|
|
|
|
const permissions = await hasPermission([transferLivechatGuestPermission], this.rid);
|
|
|
|
return permissions[0] as boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
canPlaceLivechatOnHold = () => {
|
|
|
|
const { livechatAllowManualOnHold } = this.props;
|
|
|
|
const { room } = this.state;
|
|
|
|
return !!(livechatAllowManualOnHold && !room?.lastMessage?.token && room?.lastMessage?.u && !room.onHold);
|
|
|
|
};
|
|
|
|
|
|
|
|
canViewCannedResponse = async () => {
|
|
|
|
const { viewCannedResponsesPermission } = this.props;
|
|
|
|
const permissions = await hasPermission([viewCannedResponsesPermission], this.rid);
|
|
|
|
return permissions[0] as boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
canReturnQueue = async () => {
|
|
|
|
try {
|
|
|
|
const { returnQueue } = await getRoutingConfig();
|
|
|
|
return returnQueue;
|
|
|
|
} catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
observeSubscriptions = () => {
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
|
|
|
const observeSubCollection = db
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(Q.where('rid', this.rid as string))
|
|
|
|
.observe();
|
|
|
|
this.subObserveQuery = observeSubCollection.subscribe(data => {
|
|
|
|
if (data[0]) {
|
|
|
|
if (this.subObserveQuery && this.subObserveQuery.unsubscribe) {
|
|
|
|
this.observeRoom(data[0]);
|
2023-03-16 15:49:18 +00:00
|
|
|
this.setState({ room: data[0], joined: true });
|
2022-06-09 14:42:12 +00:00
|
|
|
this.subObserveQuery.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.log("observeSubscriptions: Can't find subscription to observe");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
get isOmnichannel() {
|
|
|
|
const { room } = this.state;
|
|
|
|
return room.t === 'l';
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
setHeader = () => {
|
2022-06-09 14:42:12 +00:00
|
|
|
const { room, unreadsCount, roomUserId, joined, canForwardGuest, canReturnQueue, canPlaceLivechatOnHold } = this.state;
|
2022-06-01 19:46:37 +00:00
|
|
|
const { navigation, isMasterDetail, theme, baseUrl, user, route } = this.props;
|
2020-10-30 17:35:07 +00:00
|
|
|
const { rid, tmid } = this;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!room.rid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
const prid = room?.prid;
|
2022-04-28 20:37:25 +00:00
|
|
|
const isGroupChatConst = isGroupChat(room as ISubscription);
|
2020-06-15 14:00:46 +00:00
|
|
|
let title = route.params?.name;
|
2022-03-02 14:18:01 +00:00
|
|
|
let parentTitle = '';
|
|
|
|
// TODO: I think it's safe to remove this, but we need to test tablet without rooms
|
|
|
|
if (!tmid) {
|
2022-04-28 20:37:25 +00:00
|
|
|
title = getRoomTitle(room);
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2020-10-30 17:35:07 +00:00
|
|
|
if (tmid) {
|
2022-04-28 20:37:25 +00:00
|
|
|
parentTitle = getRoomTitle(room);
|
2020-10-30 17:35:07 +00:00
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
let subtitle: string | undefined;
|
|
|
|
let teamId: string | undefined;
|
|
|
|
let encrypted: boolean | undefined;
|
|
|
|
let userId: string | undefined;
|
|
|
|
let token: string | undefined;
|
|
|
|
let avatar: string | undefined;
|
|
|
|
let visitor: IVisitor | undefined;
|
2022-04-15 02:27:36 +00:00
|
|
|
let sourceType: IOmnichannelSource | undefined;
|
2022-07-15 20:06:27 +00:00
|
|
|
let departmentId: string | undefined;
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room) {
|
|
|
|
subtitle = room.topic;
|
|
|
|
teamId = room.teamId;
|
|
|
|
encrypted = room.encrypted;
|
|
|
|
({ id: userId, token } = user);
|
|
|
|
avatar = room.name;
|
|
|
|
visitor = room.visitor;
|
2022-07-15 20:06:27 +00:00
|
|
|
departmentId = room.departmentId;
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2021-04-07 18:31:25 +00:00
|
|
|
|
2022-04-15 02:27:36 +00:00
|
|
|
if ('source' in room) {
|
|
|
|
sourceType = room.source;
|
|
|
|
visitor = room.visitor;
|
|
|
|
}
|
|
|
|
|
2022-08-11 18:29:24 +00:00
|
|
|
const t = room?.t;
|
|
|
|
const teamMain = 'teamMain' in room ? room?.teamMain : false;
|
2022-06-09 14:42:12 +00:00
|
|
|
const omnichannelPermissions = { canForwardGuest, canReturnQueue, canPlaceLivechatOnHold };
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.setOptions({
|
|
|
|
headerShown: true,
|
|
|
|
headerTitleAlign: 'left',
|
2022-07-06 13:23:02 +00:00
|
|
|
headerTitleContainerStyle: {
|
|
|
|
flex: 1,
|
|
|
|
marginLeft: 0,
|
|
|
|
marginRight: 4,
|
|
|
|
maxWidth: undefined
|
|
|
|
},
|
|
|
|
headerRightContainerStyle: { flexGrow: undefined, flexBasis: undefined },
|
2020-07-06 20:56:28 +00:00
|
|
|
headerLeft: () => (
|
|
|
|
<LeftButtons
|
|
|
|
tmid={tmid}
|
|
|
|
unreadsCount={unreadsCount}
|
|
|
|
navigation={navigation}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={userId}
|
|
|
|
token={token}
|
|
|
|
title={avatar}
|
|
|
|
theme={theme}
|
|
|
|
t={t}
|
|
|
|
goRoomActionsView={this.goRoomActionsView}
|
|
|
|
isMasterDetail={isMasterDetail}
|
|
|
|
/>
|
|
|
|
),
|
2020-06-15 14:00:46 +00:00
|
|
|
headerTitle: () => (
|
2021-04-07 18:31:25 +00:00
|
|
|
<RoomHeader
|
2020-06-15 14:00:46 +00:00
|
|
|
prid={prid}
|
|
|
|
tmid={tmid}
|
|
|
|
title={title}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain={teamMain}
|
2020-10-30 17:35:07 +00:00
|
|
|
parentTitle={parentTitle}
|
2020-06-15 14:00:46 +00:00
|
|
|
subtitle={subtitle}
|
|
|
|
type={t}
|
|
|
|
roomUserId={roomUserId}
|
|
|
|
visitor={visitor}
|
2022-04-28 20:37:25 +00:00
|
|
|
isGroupChat={isGroupChatConst}
|
2021-04-07 18:31:25 +00:00
|
|
|
onPress={this.goRoomActionsView}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`room-view-title-${title}`}
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType={sourceType}
|
2020-06-15 14:00:46 +00:00
|
|
|
/>
|
|
|
|
),
|
|
|
|
headerRight: () => (
|
|
|
|
<RightButtons
|
|
|
|
rid={rid}
|
|
|
|
tmid={tmid}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamId={teamId}
|
2021-05-12 19:01:29 +00:00
|
|
|
joined={joined}
|
2022-06-09 14:42:12 +00:00
|
|
|
status={room.status}
|
|
|
|
omnichannelPermissions={omnichannelPermissions}
|
2023-03-01 18:26:56 +00:00
|
|
|
t={(this.t || t) as SubscriptionType}
|
2021-10-05 13:58:21 +00:00
|
|
|
encrypted={encrypted}
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation={navigation}
|
|
|
|
toggleFollowThread={this.toggleFollowThread}
|
2022-08-08 18:38:01 +00:00
|
|
|
showActionSheet={this.showActionSheet}
|
2022-07-15 20:06:27 +00:00
|
|
|
departmentId={departmentId}
|
2020-06-15 14:00:46 +00:00
|
|
|
/>
|
|
|
|
)
|
2020-03-30 20:19:01 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-05-02 22:58:23 +00:00
|
|
|
goRoomActionsView = (screen?: keyof ModalStackParamList) => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.ROOM_GO_RA);
|
2022-06-09 14:42:12 +00:00
|
|
|
const { room, member, joined, canForwardGuest, canReturnQueue, canViewCannedResponse, canPlaceLivechatOnHold } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
if (isMasterDetail) {
|
2022-05-02 22:58:23 +00:00
|
|
|
// @ts-ignore
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('ModalStackNavigator', {
|
|
|
|
screen: screen ?? 'RoomActionsView',
|
|
|
|
params: {
|
2022-03-02 14:18:01 +00:00
|
|
|
rid: this.rid as string,
|
|
|
|
t: this.t as SubscriptionType,
|
2022-05-02 22:58:23 +00:00
|
|
|
room: room as ISubscription,
|
2021-09-17 20:22:02 +00:00
|
|
|
member,
|
2021-09-28 19:33:25 +00:00
|
|
|
showCloseModal: !!screen,
|
2022-06-09 14:42:12 +00:00
|
|
|
joined,
|
|
|
|
omnichannelPermissions: { canForwardGuest, canReturnQueue, canViewCannedResponse, canPlaceLivechatOnHold }
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
|
|
|
});
|
2022-03-02 14:18:01 +00:00
|
|
|
} else if (this.rid && this.t) {
|
2021-07-22 15:24:24 +00:00
|
|
|
navigation.push('RoomActionsView', {
|
2021-09-17 20:22:02 +00:00
|
|
|
rid: this.rid,
|
2022-03-02 14:18:01 +00:00
|
|
|
t: this.t as SubscriptionType,
|
2022-03-02 14:49:43 +00:00
|
|
|
room: room as TSubscriptionModel,
|
2021-09-28 19:33:25 +00:00
|
|
|
member,
|
2022-06-09 14:42:12 +00:00
|
|
|
joined,
|
|
|
|
omnichannelPermissions: { canForwardGuest, canReturnQueue, canViewCannedResponse, canPlaceLivechatOnHold }
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
setReadOnly = async () => {
|
2020-04-13 12:51:16 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { user } = this.props;
|
2022-03-02 14:18:01 +00:00
|
|
|
const readOnly = await isReadOnly(room as ISubscription, user.username as string);
|
2020-04-13 12:51:16 +00:00
|
|
|
this.setState({ readOnly });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-04-13 12:51:16 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
init = async () => {
|
2019-04-17 17:01:03 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ loading: true });
|
2019-12-13 16:23:20 +00:00
|
|
|
const { room, joined } = this.state;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!this.rid) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-13 16:23:20 +00:00
|
|
|
if (this.tmid) {
|
2022-04-28 20:37:25 +00:00
|
|
|
await loadThreadMessages({ tmid: this.tmid, rid: this.rid });
|
2019-12-13 16:23:20 +00:00
|
|
|
} else {
|
|
|
|
const newLastOpen = new Date();
|
2023-01-13 19:32:52 +00:00
|
|
|
await RoomServices.getMessages({
|
|
|
|
rid: room.rid,
|
2023-01-16 16:43:27 +00:00
|
|
|
t: room.t as RoomType,
|
|
|
|
...('lastOpen' in room && room.lastOpen ? { lastOpen: room.lastOpen } : {})
|
2023-01-13 19:32:52 +00:00
|
|
|
});
|
2019-12-13 16:23:20 +00:00
|
|
|
|
|
|
|
// if room is joined
|
2022-03-02 14:18:01 +00:00
|
|
|
if (joined && 'id' in room) {
|
2019-12-13 16:23:20 +00:00
|
|
|
if (room.alert || room.unread || room.userMentions) {
|
|
|
|
this.setLastOpen(room.ls);
|
|
|
|
} else {
|
|
|
|
this.setLastOpen(null);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2022-04-28 20:37:25 +00:00
|
|
|
readMessages(room.rid, newLastOpen, true).catch(e => console.log(e));
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-12-13 16:23:20 +00:00
|
|
|
}
|
2019-06-28 17:02:30 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
const canAutoTranslate = canAutoTranslateMethod();
|
2020-03-30 20:19:01 +00:00
|
|
|
const member = await this.getRoomMember();
|
|
|
|
|
|
|
|
this.setState({ canAutoTranslate, member, loading: false });
|
2019-04-17 17:01:03 +00:00
|
|
|
} catch (e) {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ loading: false });
|
2022-03-02 14:18:01 +00:00
|
|
|
this.retryInit += 1;
|
2019-12-13 16:23:20 +00:00
|
|
|
if (this.retryInit <= 1) {
|
|
|
|
this.retryInitTimeout = setTimeout(() => {
|
|
|
|
this.init();
|
|
|
|
}, 300);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getRoomMember = async () => {
|
2020-03-30 20:19:01 +00:00
|
|
|
const { room } = this.state;
|
2020-04-01 12:28:54 +00:00
|
|
|
const { t } = room;
|
2020-03-30 20:19:01 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
if ('id' in room && t === 'd' && !isGroupChat(room)) {
|
2020-03-30 20:19:01 +00:00
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const roomUserId = getUidDirectMessage(room);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setState({ roomUserId }, () => this.setHeader());
|
2020-04-01 12:28:54 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getUserInfo(roomUserId);
|
2020-03-30 20:19:01 +00:00
|
|
|
if (result.success) {
|
|
|
|
return result.user;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 20:19:01 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
findAndObserveRoom = async (rid: string) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const db = database.active;
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = await db.get('subscriptions');
|
2019-09-16 20:26:32 +00:00
|
|
|
const room = await subCollection.find(rid);
|
|
|
|
this.setState({ room });
|
2020-02-28 17:39:17 +00:00
|
|
|
if (!this.tmid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-02-28 17:39:17 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
this.observeRoom(room);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.t !== 'd') {
|
|
|
|
console.log('Room not found');
|
|
|
|
this.internalSetState({ joined: false });
|
2020-02-21 15:59:13 +00:00
|
|
|
}
|
|
|
|
if (this.rid) {
|
2022-06-09 14:42:12 +00:00
|
|
|
this.observeSubscriptions();
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
unsubscribe = async () => {
|
2020-02-05 13:34:53 +00:00
|
|
|
if (this.sub && this.sub.unsubscribe) {
|
|
|
|
await this.sub.unsubscribe();
|
2019-09-27 20:29:25 +00:00
|
|
|
}
|
2020-02-05 13:34:53 +00:00
|
|
|
delete this.sub;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-27 20:29:25 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
observeRoom = (room: TSubscriptionModel) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const observable = room.observe();
|
2021-09-13 20:41:05 +00:00
|
|
|
this.subSubscription = observable.subscribe(changes => {
|
2022-03-02 14:18:01 +00:00
|
|
|
const roomUpdate = roomAttrsUpdate.reduce((ret: any, attr) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
ret[attr] = changes[attr];
|
|
|
|
return ret;
|
|
|
|
}, {});
|
|
|
|
if (this.mounted) {
|
2022-06-09 14:42:12 +00:00
|
|
|
this.internalSetState({ room: changes, roomUpdate, isOnHold: !!changes?.onHold });
|
2021-09-13 20:41:05 +00:00
|
|
|
} else {
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2021-09-13 20:41:05 +00:00
|
|
|
this.state.room = changes;
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2021-09-13 20:41:05 +00:00
|
|
|
this.state.roomUpdate = roomUpdate;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2023-02-24 14:37:56 +00:00
|
|
|
handleCloseEmoji = (action?: Function, params?: any) => {
|
|
|
|
if (this.messagebox?.current) {
|
|
|
|
return this.messagebox?.current.closeEmojiAndAction(action, params);
|
|
|
|
}
|
|
|
|
if (action) {
|
|
|
|
return action(params);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
errorActionsShow = (message: TAnyMessageModel) => {
|
2023-02-24 14:37:56 +00:00
|
|
|
this.handleCloseEmoji(this.messageErrorActions?.showMessageErrorActions, message);
|
2022-08-08 18:38:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
showActionSheet = (options: any) => {
|
|
|
|
const { showActionSheet } = this.props;
|
2023-02-24 14:37:56 +00:00
|
|
|
this.handleCloseEmoji(showActionSheet, options);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onEditInit = (message: TAnyMessageModel) => {
|
2021-02-23 17:24:05 +00:00
|
|
|
const newMessage = {
|
|
|
|
id: message.id,
|
|
|
|
subscription: {
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore TODO: we can remove this after we merge a PR separating IMessage vs IMessageFromServer
|
2021-02-23 17:24:05 +00:00
|
|
|
id: message.subscription.id
|
|
|
|
},
|
|
|
|
msg: message?.attachments?.[0]?.description || message.msg
|
2022-04-01 15:32:17 +00:00
|
|
|
} as TMessageModel;
|
2021-02-23 17:24:05 +00:00
|
|
|
this.setState({ selectedMessage: newMessage, editing: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onEditCancel = () => {
|
2022-03-02 14:18:01 +00:00
|
|
|
this.setState({ selectedMessage: undefined, editing: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onEditRequest = async (message: TAnyMessageModel) => {
|
|
|
|
this.setState({ selectedMessage: undefined, editing: false });
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.editMessage(message);
|
2019-09-16 20:26:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onReplyInit = (message: TAnyMessageModel, mention: boolean) => {
|
2022-08-25 19:53:19 +00:00
|
|
|
// If there's a thread already, we redirect to it
|
|
|
|
if (mention && !!message.tlm) {
|
|
|
|
return this.onThreadPress(message);
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({
|
2021-09-13 20:41:05 +00:00
|
|
|
selectedMessage: message,
|
|
|
|
replying: true,
|
|
|
|
replyWithMention: mention
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onReplyCancel = () => {
|
2022-03-02 14:18:01 +00:00
|
|
|
this.setState({ selectedMessage: undefined, replying: false, replyWithMention: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
showReactionPicker = () => {
|
|
|
|
const { showActionSheet } = this.props;
|
|
|
|
const { selectedMessage } = this.state;
|
2022-12-08 18:38:16 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
showActionSheet({
|
|
|
|
children: (
|
|
|
|
<ReactionPicker message={selectedMessage} onEmojiSelected={this.onReactionPress} reactionClose={this.onReactionClose} />
|
|
|
|
),
|
|
|
|
snaps: [400],
|
|
|
|
enableContentPanningGesture: false
|
|
|
|
});
|
|
|
|
}, 100);
|
2022-10-21 18:27:55 +00:00
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onReactionInit = (message: TAnyMessageModel) => {
|
2023-02-24 14:37:56 +00:00
|
|
|
this.handleCloseEmoji(() => {
|
2022-10-21 18:27:55 +00:00
|
|
|
this.setState({ selectedMessage: message }, this.showReactionPicker);
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onReactionClose = () => {
|
2022-10-21 18:27:55 +00:00
|
|
|
const { hideActionSheet } = this.props;
|
|
|
|
this.setState({ selectedMessage: undefined }, hideActionSheet);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onMessageLongPress = (message: TAnyMessageModel) => {
|
2022-08-25 19:53:19 +00:00
|
|
|
// if it's a thread message on main room, we disable the long press
|
|
|
|
if (message.tmid && !this.tmid) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-24 14:37:56 +00:00
|
|
|
this.handleCloseEmoji(this.messageActions?.showMessageActions, message);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-02-19 21:19:39 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
showAttachment = (attachment: IAttachment) => {
|
2019-12-18 21:13:11 +00:00
|
|
|
const { navigation } = this.props;
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2019-12-18 21:13:11 +00:00
|
|
|
navigation.navigate('AttachmentView', { attachment });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2022-10-21 18:27:55 +00:00
|
|
|
onReactionPress = async (emoji: IEmoji, messageId: string) => {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2022-10-21 18:27:55 +00:00
|
|
|
let shortname = '';
|
|
|
|
if (typeof emoji === 'string') {
|
|
|
|
shortname = emoji;
|
|
|
|
} else {
|
|
|
|
shortname = emoji.name;
|
|
|
|
}
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.setReaction(shortname, messageId);
|
2019-09-16 20:26:32 +00:00
|
|
|
this.onReactionClose();
|
2020-02-03 18:28:18 +00:00
|
|
|
Review.pushPositiveEvent();
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
};
|
2017-08-04 00:34:37 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onReactionLongPress = (message: TAnyMessageModel) => {
|
2022-08-03 16:32:16 +00:00
|
|
|
this.setState({ selectedMessage: message });
|
2022-09-29 19:42:04 +00:00
|
|
|
const { showActionSheet } = this.props;
|
2022-08-03 16:32:16 +00:00
|
|
|
const { selectedMessage } = this.state;
|
2023-02-24 14:37:56 +00:00
|
|
|
this.handleCloseEmoji(showActionSheet, {
|
2022-09-29 19:42:04 +00:00
|
|
|
children: <ReactionsList reactions={selectedMessage?.reactions} getCustomEmoji={this.getCustomEmoji} />,
|
|
|
|
snaps: ['50%', '80%'],
|
2022-08-03 16:32:16 +00:00
|
|
|
enableContentPanningGesture: false
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
onEncryptedPress = () => {
|
|
|
|
logEvent(events.ROOM_ENCRYPTED_PRESS);
|
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
|
|
|
|
const screen = { screen: 'E2EHowItWorksView', params: { showCloseModal: true } };
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2020-09-11 14:31:38 +00:00
|
|
|
return navigation.navigate('ModalStackNavigator', screen);
|
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2020-09-11 14:31:38 +00:00
|
|
|
navigation.navigate('E2ESaveYourPasswordStackNavigator', screen);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onDiscussionPress = debounce(
|
2022-06-14 16:12:44 +00:00
|
|
|
async (item: TAnyMessageModel) => {
|
2022-11-25 13:21:56 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
2022-06-14 16:12:44 +00:00
|
|
|
if (!item.drid) return;
|
|
|
|
const sub = await getRoomInfo(item.drid);
|
2022-11-25 13:21:56 +00:00
|
|
|
if (sub) {
|
|
|
|
goRoom({
|
|
|
|
item: sub as TGoRoomItem,
|
|
|
|
isMasterDetail
|
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
},
|
|
|
|
1000,
|
|
|
|
true
|
|
|
|
);
|
2019-04-08 12:35:28 +00:00
|
|
|
|
2019-08-22 19:15:30 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2021-09-13 20:41:05 +00:00
|
|
|
updateUnreadCount = async () => {
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!this.rid) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
2022-02-01 13:39:09 +00:00
|
|
|
const observable = await db
|
2019-09-16 20:26:32 +00:00
|
|
|
.get('subscriptions')
|
2021-09-13 20:41:05 +00:00
|
|
|
.query(Q.where('archived', false), Q.where('open', true), Q.where('rid', Q.notEq(this.rid)))
|
2019-09-16 20:26:32 +00:00
|
|
|
.observeWithColumns(['unread']);
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
this.queryUnreads = observable.subscribe(data => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { unreadsCount } = this.state;
|
|
|
|
const newUnreadsCount = data.filter(s => s.unread > 0).reduce((a, b) => a + (b.unread || 0), 0);
|
|
|
|
if (unreadsCount !== newUnreadsCount) {
|
|
|
|
this.setState({ unreadsCount: newUnreadsCount }, () => this.setHeader());
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-08-22 19:15:30 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
onThreadPress = debounce((item: TAnyMessageModel) => this.navToThread(item), 1000, true);
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
shouldNavigateToRoom = (message: IMessage) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
if (message.tmid && message.tmid === this.tmid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!message.tmid && message.rid === this.rid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
jumpToMessageByUrl = async (messageUrl?: string) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!messageUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const parsedUrl = parse(messageUrl, true);
|
|
|
|
const messageId = parsedUrl.query.msg;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (messageId) {
|
|
|
|
await this.jumpToMessage(messageId);
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
jumpToMessage = async (messageId: string) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
try {
|
2022-08-19 21:14:37 +00:00
|
|
|
sendLoadingEvent({ visible: true, onCancel: this.cancelJumpToMessage });
|
2021-05-26 17:24:54 +00:00
|
|
|
const message = await RoomServices.getMessageInfo(messageId);
|
|
|
|
|
|
|
|
if (!message) {
|
2022-08-19 21:14:37 +00:00
|
|
|
this.cancelJumpToMessage();
|
2021-05-26 17:24:54 +00:00
|
|
|
return;
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
if (this.shouldNavigateToRoom(message)) {
|
|
|
|
if (message.rid !== this.rid) {
|
|
|
|
this.navToRoom(message);
|
|
|
|
} else {
|
|
|
|
this.navToThread(message);
|
|
|
|
}
|
2022-11-25 13:21:56 +00:00
|
|
|
} else if (!message.tmid && message.rid === this.rid && this.t === 'thread' && !message.replies) {
|
|
|
|
/**
|
|
|
|
* if the user is within a thread and the message that he is trying to jump to, is a message in the main room
|
|
|
|
*/
|
|
|
|
return this.navToRoom(message);
|
2021-05-26 17:24:54 +00:00
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* if it's from server, we don't have it saved locally and so we fetch surroundings
|
2022-04-28 20:37:25 +00:00
|
|
|
* we test if it's not from threads because we're fetching from threads currently with `loadThreadMessages`
|
2021-05-26 17:24:54 +00:00
|
|
|
*/
|
2022-03-03 20:25:03 +00:00
|
|
|
if (message.fromServer && !message.tmid && this.rid) {
|
2022-04-28 20:37:25 +00:00
|
|
|
await loadSurroundingMessages({ messageId, rid: this.rid });
|
2021-05-26 17:24:54 +00:00
|
|
|
}
|
2022-05-02 22:58:23 +00:00
|
|
|
await Promise.race([this.list.current?.jumpToMessage(message.id), new Promise(res => setTimeout(res, 5000))]);
|
2022-08-19 21:14:37 +00:00
|
|
|
this.cancelJumpToMessage();
|
2020-09-11 14:31:38 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2022-08-19 21:14:37 +00:00
|
|
|
this.cancelJumpToMessage();
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2022-08-19 21:14:37 +00:00
|
|
|
cancelJumpToMessage = () => {
|
|
|
|
this.list.current?.cancelJumpToMessage();
|
|
|
|
sendLoadingEvent({ visible: false });
|
|
|
|
};
|
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
replyBroadcast = (message: IMessage) => {
|
2022-03-02 14:18:01 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(replyBroadcast(message));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
handleConnected = () => {
|
|
|
|
this.init();
|
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
handleRoomRemoved = ({ rid }: { rid: string }) => {
|
2020-03-04 11:49:54 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
if (rid === this.rid) {
|
2020-03-06 13:13:24 +00:00
|
|
|
Navigation.navigate('RoomsListView');
|
2021-09-13 20:41:05 +00:00
|
|
|
!this.isOmnichannel &&
|
2022-04-28 20:37:25 +00:00
|
|
|
showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: getRoomTitle(room) }), I18n.t('Oops'));
|
2020-03-04 11:49:54 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-04 11:49:54 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
internalSetState = (...args: any[]) => {
|
2019-05-03 14:54:57 +00:00
|
|
|
if (!this.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore TODO: TS is complaining about this, but I don't feel like changing rn since it should be working
|
2018-10-23 21:39:48 +00:00
|
|
|
this.setState(...args);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
handleSendMessage = (message: string, tmid?: string, tshow?: boolean) => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.ROOM_SEND_MESSAGE);
|
2022-03-02 14:18:01 +00:00
|
|
|
const { rid } = this.state.room;
|
2019-07-29 16:33:28 +00:00
|
|
|
const { user } = this.props;
|
2022-04-28 20:37:25 +00:00
|
|
|
sendMessage(rid, message, this.tmid || tmid, user, tshow).then(() => {
|
2019-11-07 19:53:39 +00:00
|
|
|
if (this.list && this.list.current) {
|
2022-05-02 22:58:23 +00:00
|
|
|
this.list.current?.update();
|
2019-11-07 19:53:39 +00:00
|
|
|
}
|
2019-03-27 20:06:57 +00:00
|
|
|
this.setLastOpen(null);
|
2020-02-03 18:28:18 +00:00
|
|
|
Review.pushPositiveEvent();
|
2018-02-08 14:08:50 +00:00
|
|
|
});
|
|
|
|
};
|
2017-08-09 01:40:55 +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-03-02 14:18:01 +00:00
|
|
|
setLastOpen = (lastOpen: Date | null) => this.setState({ lastOpen });
|
2019-03-27 20:06:57 +00:00
|
|
|
|
2020-12-01 17:30:39 +00:00
|
|
|
onJoin = () => {
|
|
|
|
this.internalSetState({
|
|
|
|
joined: true
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-12-01 17:30:39 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
joinRoom = async () => {
|
2020-07-31 18:22:30 +00:00
|
|
|
logEvent(events.ROOM_JOIN);
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2020-07-31 18:22:30 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
|
|
|
|
if (this.isOmnichannel) {
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('_id' in room) {
|
|
|
|
await takeInquiry(room._id);
|
|
|
|
}
|
2021-08-23 13:43:09 +00:00
|
|
|
this.onJoin();
|
2020-07-31 18:22:30 +00:00
|
|
|
} else {
|
2022-03-02 14:18:01 +00:00
|
|
|
const { joinCodeRequired, rid } = room;
|
2020-12-01 17:30:39 +00:00
|
|
|
if (joinCodeRequired) {
|
|
|
|
this.joinCode.current?.show();
|
|
|
|
} else {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.joinRoom(rid, null, this.t as any);
|
2020-12-01 17:30:39 +00:00
|
|
|
this.onJoin();
|
|
|
|
}
|
2020-07-31 18:22:30 +00:00
|
|
|
}
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-10 16:16:32 +00:00
|
|
|
|
2022-04-20 20:53:11 +00:00
|
|
|
resumeRoom = async () => {
|
|
|
|
logEvent(events.ROOM_RESUME);
|
|
|
|
try {
|
|
|
|
const { room } = this.state;
|
|
|
|
|
|
|
|
if (this.isOmnichannel) {
|
|
|
|
if ('rid' in room) {
|
|
|
|
await takeResume(room.rid);
|
|
|
|
}
|
|
|
|
this.onJoin();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
getThreadName = (tmid: string, messageId: string) => {
|
|
|
|
const { rid } = this.state.room;
|
|
|
|
return getThreadName(rid, tmid, messageId);
|
|
|
|
};
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
toggleFollowThread = async (isFollowingThread: boolean, tmid?: string) => {
|
2019-05-15 19:33:30 +00:00
|
|
|
try {
|
2022-03-02 14:18:01 +00:00
|
|
|
const threadMessageId = tmid ?? this.tmid;
|
|
|
|
if (!threadMessageId) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.toggleFollowMessage(threadMessageId, !isFollowingThread);
|
2020-01-28 13:25:28 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: isFollowingThread ? I18n.t('Unfollowed_thread') : I18n.t('Following_thread') });
|
2019-05-15 19:33:30 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-05-15 19:33:30 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-15 19:33:30 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
getBadgeColor = (messageId: string) => {
|
2020-10-30 17:35:07 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { theme } = this.props;
|
|
|
|
return getBadgeColor({ subscription: room, theme, messageId });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-10-30 17:35:07 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
navToRoomInfo = (navParam: any) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, user, isMasterDetail } = this.props;
|
2022-10-13 21:29:55 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events[`ROOM_GO_${navParam.t === 'd' ? 'USER' : 'ROOM'}_INFO`]);
|
2019-08-22 18:08:07 +00:00
|
|
|
if (navParam.rid === user.id) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-13 21:29:55 +00:00
|
|
|
navParam.fromRid = room.rid;
|
2020-06-15 14:00:46 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
navParam.showCloseModal = true;
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'RoomInfoView', params: navParam });
|
2019-11-25 20:01:17 +00:00
|
|
|
} else {
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('RoomInfoView', navParam);
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-22 18:08:07 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
navToThread = async (item: TAnyMessageModel | { tmid: string }) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { roomUserId } = this.state;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!this.rid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
if (item.tmid) {
|
2022-03-02 14:18:01 +00:00
|
|
|
let name = '';
|
|
|
|
let jumpToMessageId = '';
|
|
|
|
if ('id' in item) {
|
|
|
|
name = item.tmsg ?? '';
|
|
|
|
jumpToMessageId = item.id;
|
|
|
|
}
|
2022-08-19 21:14:37 +00:00
|
|
|
sendLoadingEvent({ visible: true, onCancel: this.cancelJumpToMessage });
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!name) {
|
2022-03-02 14:18:01 +00:00
|
|
|
const result = await this.getThreadName(item.tmid, jumpToMessageId);
|
2021-10-26 16:11:50 +00:00
|
|
|
// test if there isn't a thread
|
|
|
|
if (!result) {
|
2022-08-19 21:14:37 +00:00
|
|
|
sendLoadingEvent({ visible: false });
|
2021-10-26 16:11:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
name = result;
|
2021-05-26 17:24:54 +00:00
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in item && item.t === E2E_MESSAGE_TYPE && item.e2e !== E2E_STATUS.DONE) {
|
2021-05-26 17:24:54 +00:00
|
|
|
name = I18n.t('Encrypted_message');
|
|
|
|
}
|
2023-03-07 12:28:51 +00:00
|
|
|
if (!jumpToMessageId) {
|
|
|
|
setTimeout(() => {
|
|
|
|
sendLoadingEvent({ visible: false });
|
|
|
|
}, 300);
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
return navigation.push('RoomView', {
|
2021-09-13 20:41:05 +00:00
|
|
|
rid: this.rid,
|
|
|
|
tmid: item.tmid,
|
|
|
|
name,
|
2022-03-02 14:18:01 +00:00
|
|
|
t: SubscriptionType.THREAD,
|
2021-09-13 20:41:05 +00:00
|
|
|
roomUserId,
|
2022-03-02 14:18:01 +00:00
|
|
|
jumpToMessageId
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('tlm' in item) {
|
2021-05-26 17:24:54 +00:00
|
|
|
return navigation.push('RoomView', {
|
2021-09-13 20:41:05 +00:00
|
|
|
rid: this.rid,
|
|
|
|
tmid: item.id,
|
|
|
|
name: makeThreadName(item),
|
2022-03-02 14:18:01 +00:00
|
|
|
t: SubscriptionType.THREAD,
|
2021-09-13 20:41:05 +00:00
|
|
|
roomUserId
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
navToRoom = async (message: TAnyMessageModel) => {
|
2022-11-25 13:21:56 +00:00
|
|
|
const { isMasterDetail } = this.props;
|
2021-05-26 17:24:54 +00:00
|
|
|
const roomInfo = await getRoomInfo(message.rid);
|
2022-11-25 13:21:56 +00:00
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
return goRoom({
|
2022-03-02 14:49:43 +00:00
|
|
|
item: roomInfo as TGoRoomItem,
|
2021-09-13 20:41:05 +00:00
|
|
|
isMasterDetail,
|
|
|
|
jumpToMessageId: message.id
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2023-03-01 18:26:56 +00:00
|
|
|
// OLD METHOD - support versions before 5.0.0
|
|
|
|
handleEnterCall = () => {
|
2019-09-18 17:32:12 +00:00
|
|
|
const { room } = this.state;
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room) {
|
|
|
|
const { jitsiTimeout } = room;
|
2022-03-08 16:25:27 +00:00
|
|
|
if (jitsiTimeout && jitsiTimeout < new Date()) {
|
2022-03-02 14:18:01 +00:00
|
|
|
showErrorAlert(I18n.t('Call_already_ended'));
|
|
|
|
} else {
|
2023-03-01 18:26:56 +00:00
|
|
|
callJitsi({ room });
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
2019-09-18 17:32:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
handleCommands = ({ event }: { event: IKeyCommandEvent }) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (this.rid) {
|
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandScroll(event)) {
|
|
|
|
const offset = input === 'UIKeyInputUpArrow' ? 100 : -100;
|
|
|
|
this.offset += offset;
|
2022-05-02 22:58:23 +00:00
|
|
|
this.flatList?.current?.scrollToOffset({ offset: this.offset });
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandRoomActions(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoomActionsView();
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSearchMessages(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoomActionsView('SearchMessagesView');
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandReplyLatest(event)) {
|
|
|
|
if (this.list && this.list.current) {
|
|
|
|
const message = this.list.current.getLastMessage();
|
2022-05-02 22:58:23 +00:00
|
|
|
if (message) {
|
|
|
|
this.onReplyInit(message, false);
|
|
|
|
}
|
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-03-02 14:18:01 +00:00
|
|
|
blockAction = ({
|
|
|
|
actionId,
|
|
|
|
appId,
|
|
|
|
value,
|
|
|
|
blockId,
|
|
|
|
rid,
|
|
|
|
mid
|
|
|
|
}: {
|
|
|
|
actionId: string;
|
|
|
|
appId: string;
|
|
|
|
value: any;
|
|
|
|
blockId: string;
|
|
|
|
rid: string;
|
|
|
|
mid: string;
|
|
|
|
}) =>
|
2022-04-28 20:37:25 +00:00
|
|
|
triggerBlockAction({
|
2021-09-13 20:41:05 +00:00
|
|
|
blockId,
|
|
|
|
actionId,
|
|
|
|
value,
|
|
|
|
mid,
|
|
|
|
rid,
|
|
|
|
appId,
|
|
|
|
container: {
|
2022-03-16 19:07:49 +00:00
|
|
|
type: ContainerTypes.MESSAGE,
|
2021-09-13 20:41:05 +00:00
|
|
|
id: mid
|
|
|
|
}
|
|
|
|
});
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
closeBanner = async () => {
|
2020-05-08 12:57:04 +00:00
|
|
|
const { room } = this.state;
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room) {
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
|
|
|
await db.write(async () => {
|
|
|
|
await room.update(r => {
|
|
|
|
r.bannerClosed = true;
|
|
|
|
});
|
2020-05-08 12:57:04 +00:00
|
|
|
});
|
2022-03-02 14:18:01 +00:00
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
2020-05-08 12:57:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
isIgnored = (message: TAnyMessageModel): boolean => {
|
2020-11-30 20:00:31 +00:00
|
|
|
const { room } = this.state;
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room) {
|
|
|
|
return room?.ignored?.includes?.(message?.u?._id) ?? false;
|
|
|
|
}
|
|
|
|
return false;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-11-30 20:00:31 +00:00
|
|
|
|
2022-06-09 14:42:12 +00:00
|
|
|
goToCannedResponses = () => {
|
|
|
|
const { room } = this.state;
|
|
|
|
Navigation.navigate('CannedResponsesListView', { rid: room.rid });
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
renderItem = (item: TAnyMessageModel, previousItem: TAnyMessageModel, highlightedMessage?: string) => {
|
2019-06-28 17:02:30 +00:00
|
|
|
const { room, lastOpen, canAutoTranslate } = this.state;
|
2022-04-11 18:01:43 +00:00
|
|
|
const { user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, Message_Read_Receipt_Enabled, theme } =
|
|
|
|
this.props;
|
2019-03-27 20:06:57 +00:00
|
|
|
let dateSeparator = null;
|
|
|
|
let showUnreadSeparator = false;
|
|
|
|
|
|
|
|
if (!previousItem) {
|
|
|
|
dateSeparator = item.ts;
|
|
|
|
showUnreadSeparator = moment(item.ts).isAfter(lastOpen);
|
|
|
|
} else {
|
2022-03-02 14:18:01 +00:00
|
|
|
showUnreadSeparator =
|
|
|
|
(lastOpen && moment(item.ts).isSameOrAfter(lastOpen) && moment(previousItem.ts).isBefore(lastOpen)) ?? false;
|
2019-03-27 20:06:57 +00:00
|
|
|
if (!moment(item.ts).isSame(previousItem.ts, 'day')) {
|
2019-04-08 12:35:28 +00:00
|
|
|
dateSeparator = item.ts;
|
2019-03-27 20:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
let content = null;
|
2022-03-03 20:25:03 +00:00
|
|
|
if (item.t && MESSAGE_TYPE_ANY_LOAD.includes(item.t as MessageTypeLoad)) {
|
2021-09-13 20:41:05 +00:00
|
|
|
content = (
|
|
|
|
<LoadMore
|
2023-01-13 19:32:52 +00:00
|
|
|
rid={room.rid}
|
|
|
|
t={room.t as RoomType}
|
|
|
|
loaderId={item.id}
|
2021-09-13 20:41:05 +00:00
|
|
|
type={item.t}
|
2022-03-03 20:25:03 +00:00
|
|
|
runOnRender={item.t === MessageTypeLoad.MORE && !previousItem}
|
2021-09-13 20:41:05 +00:00
|
|
|
/>
|
|
|
|
);
|
2021-05-26 17:24:54 +00:00
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<Message
|
|
|
|
item={item}
|
2022-03-02 14:18:01 +00:00
|
|
|
user={user as any}
|
2021-05-26 17:24:54 +00:00
|
|
|
rid={room.rid}
|
2022-03-02 14:18:01 +00:00
|
|
|
archived={'id' in room && room.archived}
|
|
|
|
broadcast={'id' in room && room.broadcast}
|
2021-05-26 17:24:54 +00:00
|
|
|
status={item.status}
|
|
|
|
isThreadRoom={!!this.tmid}
|
|
|
|
isIgnored={this.isIgnored(item)}
|
|
|
|
previousItem={previousItem}
|
|
|
|
fetchThreadName={this.getThreadName}
|
|
|
|
onReactionPress={this.onReactionPress}
|
|
|
|
onReactionLongPress={this.onReactionLongPress}
|
|
|
|
onLongPress={this.onMessageLongPress}
|
|
|
|
onEncryptedPress={this.onEncryptedPress}
|
|
|
|
onDiscussionPress={this.onDiscussionPress}
|
|
|
|
onThreadPress={this.onThreadPress}
|
2022-04-28 20:37:25 +00:00
|
|
|
onAnswerButtonPress={this.handleSendMessage}
|
2021-05-26 17:24:54 +00:00
|
|
|
showAttachment={this.showAttachment}
|
|
|
|
reactionInit={this.onReactionInit}
|
|
|
|
replyBroadcast={this.replyBroadcast}
|
|
|
|
errorActionsShow={this.errorActionsShow}
|
2022-05-03 14:27:20 +00:00
|
|
|
isSystemMessage={room.sysMes as boolean}
|
2021-05-26 17:24:54 +00:00
|
|
|
baseUrl={baseUrl}
|
|
|
|
Message_GroupingPeriod={Message_GroupingPeriod}
|
|
|
|
timeFormat={Message_TimeFormat}
|
|
|
|
useRealName={useRealName}
|
|
|
|
isReadReceiptEnabled={Message_Read_Receipt_Enabled}
|
2022-03-02 14:18:01 +00:00
|
|
|
autoTranslateRoom={canAutoTranslate && 'id' in room && room.autoTranslate}
|
|
|
|
autoTranslateLanguage={'id' in room ? room.autoTranslateLanguage : undefined}
|
2021-05-26 17:24:54 +00:00
|
|
|
navToRoomInfo={this.navToRoomInfo}
|
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
2023-03-01 18:26:56 +00:00
|
|
|
handleEnterCall={this.handleEnterCall}
|
2021-05-26 17:24:54 +00:00
|
|
|
blockAction={this.blockAction}
|
|
|
|
threadBadgeColor={this.getBadgeColor(item?.id)}
|
|
|
|
toggleFollowThread={this.toggleFollowThread}
|
|
|
|
jumpToMessage={this.jumpToMessageByUrl}
|
|
|
|
highlighted={highlightedMessage === item.id}
|
2022-04-11 18:01:43 +00:00
|
|
|
theme={theme}
|
2023-02-24 14:37:56 +00:00
|
|
|
closeEmojiAndAction={this.handleCloseEmoji}
|
2021-05-26 17:24:54 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
if (showUnreadSeparator || dateSeparator) {
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2022-03-02 14:18:01 +00:00
|
|
|
<Separator ts={dateSeparator} unread={showUnreadSeparator} />
|
2022-09-22 12:49:59 +00:00
|
|
|
{content}
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
return content;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-07 00:34:35 +00:00
|
|
|
|
2017-08-10 16:16:32 +00:00
|
|
|
renderFooter = () => {
|
2022-06-09 14:42:12 +00:00
|
|
|
const { joined, room, selectedMessage, editing, replying, replyWithMention, readOnly, loading, canViewCannedResponse } =
|
|
|
|
this.state;
|
2021-09-22 17:29:26 +00:00
|
|
|
const { navigation, theme, route } = this.props;
|
|
|
|
|
|
|
|
const usedCannedResponse = route?.params?.usedCannedResponse;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (!this.rid) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-20 20:53:11 +00:00
|
|
|
if ('onHold' in room && room.onHold) {
|
|
|
|
return (
|
|
|
|
<View style={styles.joinRoomContainer} key='room-view-chat-on-hold' testID='room-view-chat-on-hold'>
|
|
|
|
<Text accessibilityLabel={I18n.t('Chat_is_on_hold')} style={[styles.previewMode, { color: themes[theme].titleText }]}>
|
|
|
|
{I18n.t('Chat_is_on_hold')}
|
|
|
|
</Text>
|
|
|
|
<Touch
|
|
|
|
onPress={this.resumeRoom}
|
|
|
|
style={[styles.joinRoomButton, { backgroundColor: themes[theme].actionTintColor }]}
|
|
|
|
enabled={!loading}
|
2022-08-08 21:02:08 +00:00
|
|
|
>
|
2022-04-20 20:53:11 +00:00
|
|
|
<Text style={[styles.joinRoomText, { color: themes[theme].buttonText }]} testID='room-view-chat-on-hold-button'>
|
|
|
|
{I18n.t('Resume')}
|
|
|
|
</Text>
|
|
|
|
</Touch>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2023-03-16 15:49:18 +00:00
|
|
|
if (!joined) {
|
2018-09-19 14:18:32 +00:00
|
|
|
return (
|
2018-12-21 10:55:35 +00:00
|
|
|
<View style={styles.joinRoomContainer} key='room-view-join' testID='room-view-join'>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text
|
|
|
|
accessibilityLabel={I18n.t('You_are_in_preview_mode')}
|
2022-08-08 21:02:08 +00:00
|
|
|
style={[styles.previewMode, { color: themes[theme].titleText }]}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{I18n.t('You_are_in_preview_mode')}
|
|
|
|
</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Touch
|
2018-09-19 14:18:32 +00:00
|
|
|
onPress={this.joinRoom}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.joinRoomButton, { backgroundColor: themes[theme].actionTintColor }]}
|
2021-09-22 17:29:26 +00:00
|
|
|
enabled={!loading}
|
2022-08-08 21:02:08 +00:00
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.joinRoomText, { color: themes[theme].buttonText }]} testID='room-view-join-button'>
|
|
|
|
{I18n.t(this.isOmnichannel ? 'Take_it' : 'Join')}
|
|
|
|
</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
</Touch>
|
2018-09-19 14:18:32 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2020-04-13 12:51:16 +00:00
|
|
|
if (readOnly) {
|
2018-01-17 16:42:30 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text
|
|
|
|
style={[styles.previewMode, { color: themes[theme].titleText }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
accessibilityLabel={I18n.t('This_room_is_read_only')}
|
|
|
|
>
|
2021-09-13 20:41:05 +00:00
|
|
|
{I18n.t('This_room_is_read_only')}
|
|
|
|
</Text>
|
2018-01-17 16:42:30 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
if ('id' in room && isBlocked(room)) {
|
2018-05-24 20:17:45 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.previewMode, { color: themes[theme].titleText }]}>{I18n.t('This_room_is_blocked')}</Text>
|
2018-05-24 20:17:45 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
return (
|
|
|
|
<MessageBox
|
|
|
|
ref={this.messagebox}
|
2022-06-09 14:42:12 +00:00
|
|
|
goToCannedResponses={canViewCannedResponse ? this.goToCannedResponses : null}
|
2022-04-28 20:37:25 +00:00
|
|
|
onSubmit={this.handleSendMessage}
|
2019-04-24 18:36:29 +00:00
|
|
|
rid={this.rid}
|
|
|
|
tmid={this.tmid}
|
2022-06-09 14:42:12 +00:00
|
|
|
joined={joined}
|
2019-04-24 18:36:29 +00:00
|
|
|
roomType={room.t}
|
2019-10-28 20:51:46 +00:00
|
|
|
isFocused={navigation.isFocused}
|
2020-01-07 13:58:47 +00:00
|
|
|
theme={theme}
|
2019-09-16 20:26:32 +00:00
|
|
|
message={selectedMessage}
|
|
|
|
editing={editing}
|
|
|
|
editRequest={this.onEditRequest}
|
|
|
|
editCancel={this.onEditCancel}
|
|
|
|
replying={replying}
|
|
|
|
replyWithMention={replyWithMention}
|
|
|
|
replyCancel={this.onReplyCancel}
|
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
2020-02-28 17:52:50 +00:00
|
|
|
navigation={navigation}
|
2021-09-22 17:29:26 +00:00
|
|
|
usedCannedResponse={usedCannedResponse}
|
2019-04-24 18:36:29 +00:00
|
|
|
/>
|
|
|
|
);
|
2017-09-25 13:15:28 +00:00
|
|
|
};
|
2017-08-09 20:08:50 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
renderActions = () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { room, readOnly } = this.state;
|
2020-12-17 16:55:19 +00:00
|
|
|
const { user } = this.props;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!('id' in room)) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-18 20:34:59 +00:00
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2020-06-15 19:35:45 +00:00
|
|
|
<MessageActions
|
2023-01-13 19:32:52 +00:00
|
|
|
ref={ref => (this.messageActions = ref)}
|
2020-06-15 19:35:45 +00:00
|
|
|
tmid={this.tmid}
|
|
|
|
room={room}
|
|
|
|
user={user}
|
|
|
|
editInit={this.onEditInit}
|
|
|
|
replyInit={this.onReplyInit}
|
|
|
|
reactionInit={this.onReactionInit}
|
|
|
|
onReactionPress={this.onReactionPress}
|
|
|
|
isReadOnly={readOnly}
|
|
|
|
/>
|
2023-01-13 19:32:52 +00:00
|
|
|
<MessageErrorActions ref={ref => (this.messageErrorActions = ref)} tmid={this.tmid} />
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2018-07-18 20:34:59 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-07-18 20:34:59 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
console.count(`${this.constructor.name}.render calls`);
|
2022-10-21 18:27:55 +00:00
|
|
|
const { room, loading } = this.state;
|
|
|
|
const { user, baseUrl, theme, navigation, Hide_System_Messages, width, serverVersion } = this.props;
|
2022-03-02 14:18:01 +00:00
|
|
|
const { rid, t } = room;
|
|
|
|
let sysMes;
|
|
|
|
let bannerClosed;
|
|
|
|
let announcement;
|
|
|
|
let tunread;
|
|
|
|
let ignored;
|
|
|
|
if ('id' in room) {
|
|
|
|
({ sysMes, bannerClosed, announcement, tunread, ignored } = room);
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }} testID='room-view'>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2022-03-02 14:18:01 +00:00
|
|
|
<Banner title={I18n.t('Announcement')} text={announcement} bannerClosed={bannerClosed} closeBanner={this.closeBanner} />
|
2019-09-16 20:26:32 +00:00
|
|
|
<List
|
2019-11-07 19:53:39 +00:00
|
|
|
ref={this.list}
|
2021-05-26 17:24:54 +00:00
|
|
|
listRef={this.flatList}
|
2019-09-16 20:26:32 +00:00
|
|
|
rid={rid}
|
|
|
|
tmid={this.tmid}
|
2022-03-02 14:18:01 +00:00
|
|
|
tunread={tunread}
|
|
|
|
ignored={ignored}
|
2019-09-16 20:26:32 +00:00
|
|
|
renderRow={this.renderItem}
|
|
|
|
loading={loading}
|
2020-02-17 19:06:18 +00:00
|
|
|
navigation={navigation}
|
2020-06-09 20:11:52 +00:00
|
|
|
hideSystemMessages={Array.isArray(sysMes) ? sysMes : Hide_System_Messages}
|
2022-03-02 14:18:01 +00:00
|
|
|
showMessageInMainThread={user.showMessageInMainThread ?? false}
|
2021-10-20 16:35:28 +00:00
|
|
|
serverVersion={serverVersion}
|
2019-09-16 20:26:32 +00:00
|
|
|
/>
|
2019-04-17 17:01:03 +00:00
|
|
|
{this.renderFooter()}
|
|
|
|
{this.renderActions()}
|
2022-03-02 14:18:01 +00:00
|
|
|
<UploadProgress rid={rid} user={user} baseUrl={baseUrl} width={width} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<JoinCode ref={this.joinCode} onJoin={this.onJoin} rid={rid} t={t} theme={theme} />
|
2018-08-01 19:35:06 +00:00
|
|
|
</SafeAreaView>
|
2017-08-04 00:34:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-03-02 14:18:01 +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,
|
2019-08-07 13:51:34 +00:00
|
|
|
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
2022-03-02 14:18:01 +00:00
|
|
|
useRealName: state.settings.UI_Use_Real_Name as boolean,
|
2019-08-07 13:51:34 +00:00
|
|
|
isAuthenticated: state.login.isAuthenticated,
|
2022-03-02 14:18:01 +00:00
|
|
|
Message_GroupingPeriod: state.settings.Message_GroupingPeriod as number,
|
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat as string,
|
2019-09-16 20:26:32 +00:00
|
|
|
customEmojis: state.customEmojis,
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server,
|
2021-10-20 16:35:28 +00:00
|
|
|
serverVersion: state.server.version,
|
2022-03-02 14:18:01 +00:00
|
|
|
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled as boolean,
|
2022-06-09 14:42:12 +00:00
|
|
|
Hide_System_Messages: state.settings.Hide_System_Messages as string[],
|
|
|
|
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
|
|
|
|
viewCannedResponsesPermission: state.permissions['view-canned-responses'],
|
|
|
|
livechatAllowManualOnHold: state.settings.Livechat_allow_manual_on_hold as boolean
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2022-08-03 16:32:16 +00:00
|
|
|
export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(withActionSheet(RoomView)))));
|