Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
|
2e67b8d100 | |
|
be40312fe6 | |
|
bcf4e2e144 | |
|
dc3eec8b16 | |
|
c202e2477d | |
|
7414e9afbf | |
|
9dd7ebe7e5 | |
|
374da08c59 | |
|
6608c1ecea | |
|
6c11015a63 |
|
@ -1,55 +0,0 @@
|
|||
import * as types from './actionsTypes';
|
||||
|
||||
export function inquirySetEnabled(enabled) {
|
||||
return {
|
||||
type: types.INQUIRY.SET_ENABLED,
|
||||
enabled
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryReset() {
|
||||
return {
|
||||
type: types.INQUIRY.RESET
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryQueueAdd(inquiry) {
|
||||
return {
|
||||
type: types.INQUIRY.QUEUE_ADD,
|
||||
inquiry
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryQueueUpdate(inquiry) {
|
||||
return {
|
||||
type: types.INQUIRY.QUEUE_UPDATE,
|
||||
inquiry
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryQueueRemove(inquiryId) {
|
||||
return {
|
||||
type: types.INQUIRY.QUEUE_REMOVE,
|
||||
inquiryId
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryRequest() {
|
||||
return {
|
||||
type: types.INQUIRY.REQUEST
|
||||
};
|
||||
}
|
||||
|
||||
export function inquirySuccess(inquiries) {
|
||||
return {
|
||||
type: types.INQUIRY.SUCCESS,
|
||||
inquiries
|
||||
};
|
||||
}
|
||||
|
||||
export function inquiryFailure(error) {
|
||||
return {
|
||||
type: types.INQUIRY.FAILURE,
|
||||
error
|
||||
};
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
import log from '../../../utils/log';
|
||||
import store from '../../createStore';
|
||||
import RocketChat from '../../rocketchat';
|
||||
import {
|
||||
inquiryRequest,
|
||||
inquiryQueueAdd,
|
||||
inquiryQueueUpdate,
|
||||
inquiryQueueRemove
|
||||
} from '../../../actions/inquiry';
|
||||
|
||||
const removeListener = listener => listener.stop();
|
||||
|
||||
let connectedListener;
|
||||
let disconnectedListener;
|
||||
let queueListener;
|
||||
|
||||
const streamTopic = 'stream-livechat-inquiry-queue-observer';
|
||||
|
||||
export default function subscribeInquiry() {
|
||||
const handleConnection = () => {
|
||||
store.dispatch(inquiryRequest());
|
||||
};
|
||||
|
||||
const handleQueueMessageReceived = (ddpMessage) => {
|
||||
const [{ type, ...sub }] = ddpMessage.fields.args;
|
||||
|
||||
// added can be ignored, since it is handled by 'changed' event
|
||||
if (/added/.test(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the sub isn't on the queue anymore
|
||||
if (sub.status !== 'queued') {
|
||||
// remove it from the queue
|
||||
store.dispatch(inquiryQueueRemove(sub._id));
|
||||
return;
|
||||
}
|
||||
|
||||
const { queued } = store.getState().inquiry;
|
||||
// check if this sub is on the current queue
|
||||
const idx = queued.findIndex(item => item._id === sub._id);
|
||||
if (idx >= 0) {
|
||||
// if it is on the queue let's update
|
||||
store.dispatch(inquiryQueueUpdate(sub));
|
||||
} else {
|
||||
// if it is not on the queue let's add
|
||||
store.dispatch(inquiryQueueAdd(sub));
|
||||
}
|
||||
};
|
||||
|
||||
const stop = () => {
|
||||
if (connectedListener) {
|
||||
connectedListener.then(removeListener);
|
||||
connectedListener = false;
|
||||
}
|
||||
if (disconnectedListener) {
|
||||
disconnectedListener.then(removeListener);
|
||||
disconnectedListener = false;
|
||||
}
|
||||
if (queueListener) {
|
||||
queueListener.then(removeListener);
|
||||
queueListener = false;
|
||||
}
|
||||
};
|
||||
|
||||
connectedListener = this.sdk.onStreamData('connected', handleConnection);
|
||||
disconnectedListener = this.sdk.onStreamData('close', handleConnection);
|
||||
queueListener = this.sdk.onStreamData(streamTopic, handleQueueMessageReceived);
|
||||
|
||||
try {
|
||||
const { user } = store.getState().login;
|
||||
RocketChat.getAgentDepartments(user.id).then((result) => {
|
||||
if (result.success) {
|
||||
const { departments } = result;
|
||||
|
||||
if (!departments.length || RocketChat.hasRole('livechat-manager')) {
|
||||
this.sdk.subscribe(streamTopic, 'public').catch(e => console.log(e));
|
||||
}
|
||||
|
||||
const departmentIds = departments.map(({ departmentId }) => departmentId);
|
||||
departmentIds.forEach((departmentId) => {
|
||||
// subscribe to all departments of the agent
|
||||
this.sdk.subscribe(streamTopic, `department/${ departmentId }`).catch(e => console.log(e));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
stop: () => stop()
|
||||
};
|
||||
} catch (e) {
|
||||
log(e);
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
|
@ -19,7 +19,6 @@ import {
|
|||
} from '../actions/share';
|
||||
|
||||
import subscribeRooms from './methods/subscriptions/rooms';
|
||||
import subscribeInquiry from './methods/subscriptions/inquiry';
|
||||
import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';
|
||||
|
||||
import protectedFunction from './methods/helpers/protectedFunction';
|
||||
|
@ -54,6 +53,7 @@ import { twoFactor } from '../utils/twoFactor';
|
|||
import { selectServerFailure } from '../actions/server';
|
||||
import { useSsl } from '../utils/url';
|
||||
import UserPreferences from './userPreferences';
|
||||
import EventEmitter from '../utils/events';
|
||||
|
||||
const TOKEN_KEY = 'reactnativemeteor_usertoken';
|
||||
const CURRENT_SERVER = 'currentServer';
|
||||
|
@ -78,15 +78,6 @@ const RocketChat = {
|
|||
}
|
||||
}
|
||||
},
|
||||
async subscribeInquiry() {
|
||||
if (!this.inquirySub) {
|
||||
try {
|
||||
this.inquirySub = await subscribeInquiry.call(this);
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
canOpenRoom,
|
||||
createChannel({
|
||||
name, users, type, readOnly, broadcast
|
||||
|
@ -211,10 +202,7 @@ const RocketChat = {
|
|||
this.roomsSub = null;
|
||||
}
|
||||
|
||||
if (this.inquirySub) {
|
||||
this.inquirySub.stop();
|
||||
this.inquirySub = null;
|
||||
}
|
||||
EventEmitter.emit('INQUIRY_UNSUBSCRIBE');
|
||||
|
||||
if (this.sdk) {
|
||||
this.sdk.disconnect();
|
||||
|
@ -860,20 +848,6 @@ const RocketChat = {
|
|||
// RC 2.2.0
|
||||
return this.sdk.get('livechat/custom-fields');
|
||||
},
|
||||
changeLivechatStatus() {
|
||||
// RC 0.26.0
|
||||
return this.methodCallWrapper('livechat:changeLivechatStatus');
|
||||
},
|
||||
getInquiriesQueued() {
|
||||
// RC 2.4.0
|
||||
return this.sdk.get('livechat/inquiries.queued');
|
||||
},
|
||||
takeInquiry(inquiryId) {
|
||||
// this inquiry is added to the db by the subscriptions stream
|
||||
// and will be removed by the queue stream
|
||||
// RC 2.4.0
|
||||
return this.methodCallWrapper('livechat:takeInquiry', inquiryId);
|
||||
},
|
||||
|
||||
getUidDirectMessage(room) {
|
||||
const { id: userId } = reduxStore.getState().login.user;
|
||||
|
|
|
@ -16,7 +16,6 @@ import activeUsers from './activeUsers';
|
|||
import usersTyping from './usersTyping';
|
||||
import inviteLinks from './inviteLinks';
|
||||
import createDiscussion from './createDiscussion';
|
||||
import inquiry from './inquiry';
|
||||
import enterpriseModules from './enterpriseModules';
|
||||
|
||||
export default combineReducers({
|
||||
|
@ -37,6 +36,5 @@ export default combineReducers({
|
|||
usersTyping,
|
||||
inviteLinks,
|
||||
createDiscussion,
|
||||
inquiry,
|
||||
enterpriseModules
|
||||
});
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
import { INQUIRY } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = {
|
||||
enabled: false,
|
||||
queued: [],
|
||||
error: {}
|
||||
};
|
||||
|
||||
export default function inquiry(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case INQUIRY.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
queued: action.inquiries
|
||||
};
|
||||
case INQUIRY.FAILURE:
|
||||
return {
|
||||
...state,
|
||||
error: action.error
|
||||
};
|
||||
case INQUIRY.SET_ENABLED:
|
||||
return {
|
||||
...state,
|
||||
enabled: action.enabled
|
||||
};
|
||||
case INQUIRY.QUEUE_ADD:
|
||||
return {
|
||||
...state,
|
||||
queued: [...state.queued, action.inquiry]
|
||||
};
|
||||
case INQUIRY.QUEUE_UPDATE:
|
||||
return {
|
||||
...state,
|
||||
queued: state.queued.map((item) => {
|
||||
if (item._id === action.inquiry._id) {
|
||||
return action.inquiry;
|
||||
}
|
||||
return item;
|
||||
})
|
||||
};
|
||||
case INQUIRY.QUEUE_REMOVE:
|
||||
return {
|
||||
...state,
|
||||
queued: state.queued.filter(({ _id }) => _id !== action.inquiryId)
|
||||
};
|
||||
case INQUIRY.RESET:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@ import state from './state';
|
|||
import deepLinking from './deepLinking';
|
||||
import inviteLinks from './inviteLinks';
|
||||
import createDiscussion from './createDiscussion';
|
||||
import inquiry from './inquiry';
|
||||
|
||||
const root = function* root() {
|
||||
yield all([
|
||||
|
@ -24,8 +23,7 @@ const root = function* root() {
|
|||
state(),
|
||||
deepLinking(),
|
||||
inviteLinks(),
|
||||
createDiscussion(),
|
||||
inquiry()
|
||||
createDiscussion()
|
||||
]);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import { put, takeLatest, select } from 'redux-saga/effects';
|
||||
|
||||
import * as types from '../actions/actionsTypes';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
import { inquirySuccess, inquiryFailure, inquirySetEnabled } from '../actions/inquiry';
|
||||
|
||||
const handleRequest = function* handleRequest() {
|
||||
try {
|
||||
const routingConfig = yield RocketChat.getRoutingConfig();
|
||||
const statusLivechat = yield select(state => state.login.user.statusLivechat);
|
||||
// if routingConfig showQueue is enabled and omnichannel is enabled
|
||||
const showQueue = routingConfig.showQueue && statusLivechat === 'available';
|
||||
|
||||
if (showQueue) {
|
||||
// get all the current chats on the queue
|
||||
const result = yield RocketChat.getInquiriesQueued();
|
||||
if (result.success) {
|
||||
const { inquiries } = result;
|
||||
|
||||
// subscribe to inquiry queue changes
|
||||
RocketChat.subscribeInquiry();
|
||||
|
||||
// put request result on redux state
|
||||
yield put(inquirySuccess(inquiries));
|
||||
}
|
||||
}
|
||||
|
||||
// set enabled to know if we should show the queue button
|
||||
yield put(inquirySetEnabled(showQueue));
|
||||
} catch (e) {
|
||||
yield put(inquiryFailure(e));
|
||||
}
|
||||
};
|
||||
|
||||
const root = function* root() {
|
||||
yield takeLatest(types.INQUIRY.REQUEST, handleRequest);
|
||||
};
|
||||
export default root;
|
|
@ -14,7 +14,6 @@ import {
|
|||
loginFailure, loginSuccess, setUser, logout
|
||||
} from '../actions/login';
|
||||
import { roomsRequest } from '../actions/rooms';
|
||||
import { inquiryRequest, inquiryReset } from '../actions/inquiry';
|
||||
import { toMomentLocale } from '../utils/moment';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
import log, { logEvent, events } from '../utils/log';
|
||||
|
@ -85,12 +84,8 @@ const fetchUsersPresence = function* fetchUserPresence() {
|
|||
RocketChat.subscribeUsersPresence();
|
||||
};
|
||||
|
||||
const fetchEnterpriseModules = function* fetchEnterpriseModules({ user }) {
|
||||
const fetchEnterpriseModules = function* fetchEnterpriseModules() {
|
||||
yield RocketChat.getEnterpriseModules();
|
||||
|
||||
if (user && user.statusLivechat === 'available' && RocketChat.isOmnichannelModuleAvailable()) {
|
||||
yield put(inquiryRequest());
|
||||
}
|
||||
};
|
||||
|
||||
const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
||||
|
@ -219,14 +214,6 @@ const handleSetUser = function* handleSetUser({ user }) {
|
|||
const userId = yield select(state => state.login.user.id);
|
||||
yield put(setActiveUsers({ [userId]: user }));
|
||||
}
|
||||
|
||||
if (user?.statusLivechat && RocketChat.isOmnichannelModuleAvailable()) {
|
||||
if (user.statusLivechat === 'available') {
|
||||
yield put(inquiryRequest());
|
||||
} else {
|
||||
yield put(inquiryReset());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const root = function* root() {
|
||||
|
|
|
@ -18,7 +18,6 @@ import I18n from '../i18n';
|
|||
import { BASIC_AUTH_KEY, setBasicAuth } from '../utils/fetch';
|
||||
import { appStart, ROOT_INSIDE, ROOT_OUTSIDE } from '../actions/app';
|
||||
import UserPreferences from '../lib/userPreferences';
|
||||
import { inquiryReset } from '../actions/inquiry';
|
||||
|
||||
const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
|
||||
try {
|
||||
|
@ -65,7 +64,6 @@ const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
|
|||
|
||||
const handleSelectServer = function* handleSelectServer({ server, version, fetchVersion }) {
|
||||
try {
|
||||
yield put(inquiryReset());
|
||||
const serversDB = database.servers;
|
||||
yield UserPreferences.setStringAsync(RocketChat.CURRENT_SERVER, server);
|
||||
const userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { createSelector } from 'reselect';
|
||||
|
||||
const getInquiryQueue = state => state.inquiry.queued;
|
||||
|
||||
export const getInquiryQueueSelector = createSelector(
|
||||
[getInquiryQueue],
|
||||
queue => queue
|
||||
);
|
|
@ -30,7 +30,6 @@ import PickerView from '../views/PickerView';
|
|||
import ThreadMessagesView from '../views/ThreadMessagesView';
|
||||
import MarkdownTableView from '../views/MarkdownTableView';
|
||||
import ReadReceiptsView from '../views/ReadReceiptView';
|
||||
import QueueListView from '../views/QueueListView';
|
||||
|
||||
// Profile Stack
|
||||
import ProfileView from '../views/ProfileView';
|
||||
|
@ -166,11 +165,6 @@ const ChatsStackNavigator = () => {
|
|||
component={ReadReceiptsView}
|
||||
options={ReadReceiptsView.navigationOptions}
|
||||
/>
|
||||
<ChatsStack.Screen
|
||||
name='QueueListView'
|
||||
component={QueueListView}
|
||||
options={QueueListView.navigationOptions}
|
||||
/>
|
||||
</ChatsStack.Navigator>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -41,7 +41,6 @@ import ScreenLockConfigView from '../../views/ScreenLockConfigView';
|
|||
import AdminPanelView from '../../views/AdminPanelView';
|
||||
import NewMessageView from '../../views/NewMessageView';
|
||||
import CreateChannelView from '../../views/CreateChannelView';
|
||||
import QueueListView from '../../views/QueueListView';
|
||||
import UserPreferencesView from '../../views/UserPreferencesView';
|
||||
import UserNotificationPrefView from '../../views/UserNotificationPreferencesView';
|
||||
|
||||
|
@ -153,11 +152,6 @@ const ModalStackNavigator = React.memo(({ navigation }) => {
|
|||
component={DirectoryView}
|
||||
options={props => DirectoryView.navigationOptions({ ...props, isMasterDetail: true })}
|
||||
/>
|
||||
<ModalStack.Screen
|
||||
name='QueueListView'
|
||||
component={QueueListView}
|
||||
options={props => QueueListView.navigationOptions({ ...props, isMasterDetail: true })}
|
||||
/>
|
||||
<ModalStack.Screen
|
||||
name='NotificationPrefView'
|
||||
component={NotificationPrefView}
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { FlatList } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import isEqual from 'react-fast-compare';
|
||||
|
||||
import I18n from '../i18n';
|
||||
import RoomItem, { ROW_HEIGHT } from '../presentation/RoomItem';
|
||||
import { MAX_SIDEBAR_WIDTH } from '../constants/tablet';
|
||||
import { isTablet, isIOS } from '../utils/deviceInfo';
|
||||
import { getUserSelector } from '../selectors/login';
|
||||
import { withTheme } from '../theme';
|
||||
import { withDimensions } from '../dimensions';
|
||||
import SafeAreaView from '../containers/SafeAreaView';
|
||||
import { themes } from '../constants/colors';
|
||||
import StatusBar from '../containers/StatusBar';
|
||||
import { goRoom } from '../utils/goRoom';
|
||||
import { CloseModalButton } from '../containers/HeaderButton';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
import { logEvent, events } from '../utils/log';
|
||||
import { getInquiryQueueSelector } from '../selectors/inquiry';
|
||||
|
||||
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
|
||||
const getItemLayout = (data, index) => ({
|
||||
length: ROW_HEIGHT,
|
||||
offset: ROW_HEIGHT * index,
|
||||
index
|
||||
});
|
||||
const keyExtractor = item => item.rid;
|
||||
|
||||
class QueueListView extends React.Component {
|
||||
static navigationOptions = ({ navigation, isMasterDetail }) => {
|
||||
const options = {
|
||||
title: I18n.t('Queued_chats')
|
||||
};
|
||||
if (isMasterDetail) {
|
||||
options.headerLeft = () => <CloseModalButton navigation={navigation} testID='directory-view-close' />;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
user: PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
username: PropTypes.string,
|
||||
token: PropTypes.string
|
||||
}),
|
||||
isMasterDetail: PropTypes.bool,
|
||||
width: PropTypes.number,
|
||||
queued: PropTypes.array,
|
||||
server: PropTypes.string,
|
||||
useRealName: PropTypes.bool,
|
||||
navigation: PropTypes.object,
|
||||
theme: PropTypes.string
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
const { queued } = this.props;
|
||||
if (!isEqual(nextProps.queued, queued)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
onPressItem = (item = {}) => {
|
||||
logEvent(events.QL_GO_ROOM);
|
||||
const { navigation, isMasterDetail } = this.props;
|
||||
if (isMasterDetail) {
|
||||
navigation.navigate('DrawerNavigator');
|
||||
} else {
|
||||
navigation.navigate('RoomsListView');
|
||||
}
|
||||
|
||||
goRoom({
|
||||
item: {
|
||||
...item,
|
||||
// we're calling v as visitor on our mergeSubscriptionsRooms
|
||||
visitor: item.v
|
||||
},
|
||||
isMasterDetail
|
||||
});
|
||||
};
|
||||
|
||||
getRoomTitle = item => RocketChat.getRoomTitle(item)
|
||||
|
||||
getRoomAvatar = item => RocketChat.getRoomAvatar(item)
|
||||
|
||||
getUidDirectMessage = room => RocketChat.getUidDirectMessage(room)
|
||||
|
||||
renderItem = ({ item }) => {
|
||||
const {
|
||||
user: {
|
||||
id: userId,
|
||||
username,
|
||||
token
|
||||
},
|
||||
server,
|
||||
useRealName,
|
||||
theme,
|
||||
isMasterDetail,
|
||||
width
|
||||
} = this.props;
|
||||
const id = this.getUidDirectMessage(item);
|
||||
|
||||
return (
|
||||
<RoomItem
|
||||
item={item}
|
||||
theme={theme}
|
||||
id={id}
|
||||
type={item.t}
|
||||
userId={userId}
|
||||
username={username}
|
||||
token={token}
|
||||
baseUrl={server}
|
||||
onPress={this.onPressItem}
|
||||
testID={`queue-list-view-item-${ item.name }`}
|
||||
width={isMasterDetail ? MAX_SIDEBAR_WIDTH : width}
|
||||
useRealName={useRealName}
|
||||
getRoomTitle={this.getRoomTitle}
|
||||
getRoomAvatar={this.getRoomAvatar}
|
||||
visitor={item.v}
|
||||
swipeEnabled={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { queued, theme } = this.props;
|
||||
return (
|
||||
<SafeAreaView testID='queue-list-view' theme={theme} style={{ backgroundColor: themes[theme].backgroundColor }}>
|
||||
<StatusBar theme={theme} />
|
||||
<FlatList
|
||||
ref={this.getScrollRef}
|
||||
data={queued}
|
||||
extraData={queued}
|
||||
keyExtractor={keyExtractor}
|
||||
style={{ backgroundColor: themes[theme].backgroundColor }}
|
||||
renderItem={this.renderItem}
|
||||
getItemLayout={getItemLayout}
|
||||
removeClippedSubviews={isIOS}
|
||||
keyboardShouldPersistTaps='always'
|
||||
initialNumToRender={INITIAL_NUM_TO_RENDER}
|
||||
windowSize={9}
|
||||
onEndReached={this.onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
user: getUserSelector(state),
|
||||
isMasterDetail: state.app.isMasterDetail,
|
||||
server: state.server.server,
|
||||
useRealName: state.settings.UI_Use_Real_Name,
|
||||
queued: getInquiryQueueSelector(state)
|
||||
});
|
||||
export default connect(mapStateToProps)(withDimensions(withTheme(QueueListView)));
|
|
@ -686,13 +686,7 @@ class RoomView extends React.Component {
|
|||
joinRoom = async() => {
|
||||
logEvent(events.ROOM_JOIN);
|
||||
try {
|
||||
const { room } = this.state;
|
||||
|
||||
if (this.isOmnichannel) {
|
||||
await RocketChat.takeInquiry(room._id);
|
||||
} else {
|
||||
await RocketChat.joinRoom(this.rid, this.t);
|
||||
}
|
||||
await RocketChat.joinRoom(this.rid, this.t);
|
||||
this.internalSetState({
|
||||
joined: true
|
||||
});
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
import React, { memo, useState, useEffect } from 'react';
|
||||
import {
|
||||
View, Text, StyleSheet, Switch
|
||||
} from 'react-native';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Touch from '../../../utils/touch';
|
||||
import { CustomIcon } from '../../../lib/Icons';
|
||||
import I18n from '../../../i18n';
|
||||
import styles from '../styles';
|
||||
import { themes, SWITCH_TRACK_COLOR } from '../../../constants/colors';
|
||||
import { withTheme } from '../../../theme';
|
||||
import UnreadBadge from '../../../presentation/UnreadBadge';
|
||||
import RocketChat from '../../../lib/rocketchat';
|
||||
|
||||
const OmnichannelStatus = memo(({
|
||||
searching, goQueue, theme, queueSize, inquiryEnabled, user
|
||||
}) => {
|
||||
if (searching > 0 || !(RocketChat.isOmnichannelModuleAvailable() && user?.roles?.includes('livechat-agent'))) {
|
||||
return null;
|
||||
}
|
||||
const [status, setStatus] = useState(user?.statusLivechat === 'available');
|
||||
|
||||
useEffect(() => {
|
||||
setStatus(user.statusLivechat === 'available');
|
||||
}, [user.statusLivechat]);
|
||||
|
||||
const toggleLivechat = async() => {
|
||||
try {
|
||||
setStatus(v => !v);
|
||||
await RocketChat.changeLivechatStatus();
|
||||
} catch {
|
||||
setStatus(v => !v);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Touch
|
||||
onPress={goQueue}
|
||||
theme={theme}
|
||||
style={{ backgroundColor: themes[theme].headerSecondaryBackground }}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.dropdownContainerHeader,
|
||||
{ borderBottomWidth: StyleSheet.hairlineWidth, borderColor: themes[theme].separatorColor }
|
||||
]}
|
||||
>
|
||||
<CustomIcon style={[styles.queueIcon, { color: themes[theme].auxiliaryText }]} size={22} name='omnichannel' />
|
||||
<Text style={[styles.queueToggleText, { color: themes[theme].auxiliaryText }]}>{I18n.t('Omnichannel')}</Text>
|
||||
{inquiryEnabled
|
||||
? (
|
||||
<UnreadBadge
|
||||
style={styles.queueIcon}
|
||||
unread={queueSize}
|
||||
theme={theme}
|
||||
/>
|
||||
)
|
||||
: null}
|
||||
<Switch
|
||||
style={styles.omnichannelToggle}
|
||||
value={status}
|
||||
trackColor={SWITCH_TRACK_COLOR}
|
||||
onValueChange={toggleLivechat}
|
||||
/>
|
||||
</View>
|
||||
</Touch>
|
||||
);
|
||||
});
|
||||
|
||||
OmnichannelStatus.propTypes = {
|
||||
searching: PropTypes.bool,
|
||||
goQueue: PropTypes.func,
|
||||
queueSize: PropTypes.number,
|
||||
inquiryEnabled: PropTypes.bool,
|
||||
theme: PropTypes.string,
|
||||
user: PropTypes.shape({
|
||||
roles: PropTypes.array,
|
||||
statusLivechat: PropTypes.string
|
||||
})
|
||||
};
|
||||
|
||||
export default withTheme(OmnichannelStatus);
|
|
@ -2,31 +2,19 @@ import React from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
import Sort from './Sort';
|
||||
import OmnichannelStatus from './OmnichannelStatus';
|
||||
|
||||
const ListHeader = React.memo(({
|
||||
searching,
|
||||
sortBy,
|
||||
toggleSort,
|
||||
goQueue,
|
||||
queueSize,
|
||||
inquiryEnabled,
|
||||
user
|
||||
toggleSort
|
||||
}) => (
|
||||
<>
|
||||
<Sort searching={searching} sortBy={sortBy} toggleSort={toggleSort} />
|
||||
<OmnichannelStatus searching={searching} goQueue={goQueue} inquiryEnabled={inquiryEnabled} queueSize={queueSize} user={user} />
|
||||
</>
|
||||
<Sort searching={searching} sortBy={sortBy} toggleSort={toggleSort} />
|
||||
));
|
||||
|
||||
ListHeader.propTypes = {
|
||||
searching: PropTypes.bool,
|
||||
sortBy: PropTypes.string,
|
||||
toggleSort: PropTypes.func,
|
||||
goQueue: PropTypes.func,
|
||||
queueSize: PropTypes.number,
|
||||
inquiryEnabled: PropTypes.bool,
|
||||
user: PropTypes.object
|
||||
toggleSort: PropTypes.func
|
||||
};
|
||||
|
||||
export default ListHeader;
|
||||
|
|
|
@ -62,8 +62,6 @@ import { goRoom } from '../../utils/goRoom';
|
|||
import SafeAreaView from '../../containers/SafeAreaView';
|
||||
import Header, { getHeaderTitlePosition } from '../../containers/Header';
|
||||
import { withDimensions } from '../../dimensions';
|
||||
import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
|
||||
import { getInquiryQueueSelector } from '../../selectors/inquiry';
|
||||
|
||||
const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12;
|
||||
const CHATS_HEADER = 'Chats';
|
||||
|
@ -139,9 +137,7 @@ class RoomsListView extends React.Component {
|
|||
isMasterDetail: PropTypes.bool,
|
||||
rooms: PropTypes.array,
|
||||
width: PropTypes.number,
|
||||
insets: PropTypes.object,
|
||||
queueSize: PropTypes.number,
|
||||
inquiryEnabled: PropTypes.bool
|
||||
insets: PropTypes.object
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
|
@ -694,41 +690,6 @@ class RoomsListView extends React.Component {
|
|||
}
|
||||
};
|
||||
|
||||
goQueue = () => {
|
||||
logEvent(events.RL_GO_QUEUE);
|
||||
const {
|
||||
navigation, isMasterDetail, queueSize, inquiryEnabled, user
|
||||
} = this.props;
|
||||
|
||||
// if not-available, prompt to change to available
|
||||
if (user?.statusLivechat !== 'available') {
|
||||
showConfirmationAlert({
|
||||
message: I18n.t('Omnichannel_enable_alert'),
|
||||
confirmationText: I18n.t('Yes'),
|
||||
onPress: async() => {
|
||||
try {
|
||||
await RocketChat.changeLivechatStatus();
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!inquiryEnabled) {
|
||||
return;
|
||||
}
|
||||
// prevent navigation to empty list
|
||||
if (!queueSize) {
|
||||
return showErrorAlert(I18n.t('Queue_is_empty'), I18n.t('Oops'));
|
||||
}
|
||||
if (isMasterDetail) {
|
||||
navigation.navigate('ModalStackNavigator', { screen: 'QueueListView' });
|
||||
} else {
|
||||
navigation.navigate('QueueListView');
|
||||
}
|
||||
};
|
||||
|
||||
goRoom = ({ item, isMasterDetail }) => {
|
||||
logEvent(events.RL_GO_ROOM);
|
||||
const { item: currentItem } = this.state;
|
||||
|
@ -846,7 +807,7 @@ class RoomsListView extends React.Component {
|
|||
renderListHeader = () => {
|
||||
const { searching } = this.state;
|
||||
const {
|
||||
sortBy, queueSize, inquiryEnabled, user
|
||||
sortBy, user
|
||||
} = this.props;
|
||||
return (
|
||||
<ListHeader
|
||||
|
@ -855,8 +816,6 @@ class RoomsListView extends React.Component {
|
|||
toggleSort={this.toggleSort}
|
||||
goDirectory={this.goDirectory}
|
||||
goQueue={this.goQueue}
|
||||
queueSize={queueSize}
|
||||
inquiryEnabled={inquiryEnabled}
|
||||
user={user}
|
||||
/>
|
||||
);
|
||||
|
@ -1024,9 +983,7 @@ const mapStateToProps = state => ({
|
|||
useRealName: state.settings.UI_Use_Real_Name,
|
||||
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
||||
StoreLastMessage: state.settings.Store_Last_Message,
|
||||
rooms: state.room.rooms,
|
||||
queueSize: getInquiryQueueSelector(state).length,
|
||||
inquiryEnabled: state.inquiry.enabled
|
||||
rooms: state.room.rooms
|
||||
});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
|
|
Loading…
Reference in New Issue