2022-11-25 13:21:56 +00:00
|
|
|
import { CommonActions } from '@react-navigation/native';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import Navigation from '../../navigation/appNavigation';
|
|
|
|
import { IOmnichannelRoom, SubscriptionType, IVisitor, TSubscriptionModel, ISubscription } from '../../../definitions';
|
|
|
|
import { getRoomTitle, getUidDirectMessage } from './helpers';
|
|
|
|
import { Services } from '../../services';
|
2022-02-25 16:43:42 +00:00
|
|
|
|
2022-03-02 14:49:43 +00:00
|
|
|
interface IGoRoomItem {
|
2022-02-25 16:43:42 +00:00
|
|
|
search?: boolean; // comes from spotlight
|
|
|
|
username?: string;
|
|
|
|
t?: SubscriptionType;
|
2022-02-25 18:59:39 +00:00
|
|
|
rid?: string;
|
2022-02-25 16:43:42 +00:00
|
|
|
name?: string;
|
|
|
|
prid?: string;
|
|
|
|
visitor?: IVisitor;
|
|
|
|
}
|
2020-05-13 19:02:57 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
export type TGoRoomItem = IGoRoomItem | TSubscriptionModel | ISubscription | IOmnichannelRoomVisitor;
|
2022-03-02 14:49:43 +00:00
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
const navigate = ({
|
|
|
|
item,
|
|
|
|
isMasterDetail,
|
2022-11-25 13:21:56 +00:00
|
|
|
popToRoot,
|
2022-01-12 12:54:04 +00:00
|
|
|
...props
|
|
|
|
}: {
|
2022-03-02 14:49:43 +00:00
|
|
|
item: TGoRoomItem;
|
2022-01-12 12:54:04 +00:00
|
|
|
isMasterDetail: boolean;
|
2022-11-25 13:21:56 +00:00
|
|
|
popToRoot: boolean;
|
2022-01-12 12:54:04 +00:00
|
|
|
}) => {
|
2022-11-25 13:21:56 +00:00
|
|
|
const routeParams = {
|
2020-05-13 19:02:57 +00:00
|
|
|
rid: item.rid,
|
2022-04-28 20:37:25 +00:00
|
|
|
name: getRoomTitle(item),
|
2020-05-13 19:02:57 +00:00
|
|
|
t: item.t,
|
|
|
|
prid: item.prid,
|
|
|
|
room: item,
|
|
|
|
visitor: item.visitor,
|
2022-04-28 20:37:25 +00:00
|
|
|
roomUserId: getUidDirectMessage(item),
|
2020-06-15 14:00:46 +00:00
|
|
|
...props
|
2022-11-25 13:21:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
|
|
|
if (popToRoot) {
|
|
|
|
Navigation.navigate('DrawerNavigator');
|
|
|
|
}
|
|
|
|
return Navigation.dispatch((state: any) => {
|
|
|
|
const routesRoomView = state.routes.filter((r: any) => r.name !== 'RoomView');
|
|
|
|
return CommonActions.reset({
|
|
|
|
...state,
|
|
|
|
routes: [
|
|
|
|
...routesRoomView,
|
|
|
|
{
|
|
|
|
name: 'RoomView',
|
|
|
|
params: routeParams
|
|
|
|
}
|
|
|
|
],
|
|
|
|
index: routesRoomView.length
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (popToRoot) {
|
|
|
|
Navigation.navigate('RoomsListView');
|
|
|
|
}
|
|
|
|
return Navigation.dispatch((state: any) => {
|
|
|
|
const routesRoomsListView = state.routes.filter((r: any) => r.name === 'RoomsListView');
|
|
|
|
return CommonActions.reset({
|
|
|
|
...state,
|
|
|
|
routes: [
|
|
|
|
...routesRoomsListView,
|
|
|
|
{
|
|
|
|
name: 'RoomView',
|
|
|
|
params: routeParams
|
|
|
|
}
|
|
|
|
],
|
|
|
|
index: routesRoomsListView.length
|
|
|
|
});
|
2020-05-13 19:02:57 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
interface IOmnichannelRoomVisitor extends IOmnichannelRoom {
|
|
|
|
// this visitor came from ee/omnichannel/views/QueueListView
|
|
|
|
visitor: IVisitor;
|
|
|
|
}
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const goRoom = async ({
|
|
|
|
item,
|
|
|
|
isMasterDetail = false,
|
2022-11-25 13:21:56 +00:00
|
|
|
popToRoot = false,
|
2022-01-12 12:54:04 +00:00
|
|
|
...props
|
|
|
|
}: {
|
2022-03-02 14:49:43 +00:00
|
|
|
item: TGoRoomItem;
|
2022-01-12 12:54:04 +00:00
|
|
|
isMasterDetail: boolean;
|
|
|
|
jumpToMessageId?: string;
|
2022-02-04 22:15:01 +00:00
|
|
|
usedCannedResponse?: string;
|
2022-11-25 13:21:56 +00:00
|
|
|
popToRoot?: boolean;
|
2022-01-12 12:54:04 +00:00
|
|
|
}): Promise<void> => {
|
2022-03-02 14:49:43 +00:00
|
|
|
if (!('id' in item) && item.t === SubscriptionType.DIRECT && item?.search) {
|
2020-05-13 19:02:57 +00:00
|
|
|
// if user is using the search we need first to join/create room
|
|
|
|
try {
|
|
|
|
const { username } = item;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.createDirectMessage(username as string);
|
2022-02-25 16:43:42 +00:00
|
|
|
if (result.success && result?.room?._id) {
|
2020-05-13 19:02:57 +00:00
|
|
|
return navigate({
|
2020-06-15 14:00:46 +00:00
|
|
|
item: {
|
|
|
|
rid: result.room._id,
|
2022-02-04 22:15:01 +00:00
|
|
|
name: username || '',
|
2022-01-12 12:54:04 +00:00
|
|
|
t: SubscriptionType.DIRECT
|
2020-06-15 14:00:46 +00:00
|
|
|
},
|
|
|
|
isMasterDetail,
|
2022-11-25 13:21:56 +00:00
|
|
|
popToRoot,
|
2020-06-15 14:00:46 +00:00
|
|
|
...props
|
2020-05-13 19:02:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-11-25 13:21:56 +00:00
|
|
|
return navigate({ item, isMasterDetail, popToRoot, ...props });
|
2020-05-13 19:02:57 +00:00
|
|
|
};
|
2023-11-24 12:46:58 +00:00
|
|
|
|
|
|
|
export const navigateToRoom = navigate;
|