Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Omnichannel Status Toggle #2217

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export default {
No_available_agents_to_transfer: 'No available agents to transfer',
Offline: 'Offline',
Oops: 'Oops!',
Omnichannel: 'Omnichannel',
Onboarding_description: 'A workspace is your team or organization’s space to collaborate. Ask the workspace admin for address to join or create one for your team.',
Onboarding_join_workspace: 'Join a workspace',
Onboarding_subtitle: 'Beyond Team Collaboration',
Expand Down
5 changes: 5 additions & 0 deletions app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import buildMessage from '../helpers/buildMessage';
import RocketChat from '../../rocketchat';
import EventEmitter from '../../../utils/events';
import { removedRoom } from '../../../actions/room';
import { setUser } from '../../../actions/login';
import { INAPP_NOTIFICATION_EMITTER } from '../../../containers/InAppNotification';

const removeListener = listener => listener.stop();
Expand Down Expand Up @@ -241,6 +242,10 @@ export default function subscribeRooms() {
}
const [type, data] = ddpMessage.fields.args;
const [, ev] = ddpMessage.fields.eventName.split('/');
if (/userData/.test(ev)) {
const [{ diff }] = ddpMessage.fields.args;
store.dispatch(setUser({ statusLivechat: diff?.statusLivechat }));
}
if (/subscriptions/.test(ev)) {
if (type === 'removed') {
try {
Expand Down
5 changes: 5 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ const RocketChat = {
status: result.me.status,
statusText: result.me.statusText,
customFields: result.me.customFields,
statusLivechat: result.me.statusLivechat,
emails: result.me.emails,
roles: result.me.roles
};
Expand Down Expand Up @@ -809,6 +810,10 @@ const RocketChat = {
// RC 2.2.0
return this.sdk.get('livechat/custom-fields');
},
changeLivechatStatus() {
// RC 0.26.0
return this.methodCall('livechat:changeLivechatStatus');
},

getUidDirectMessage(room) {
const { id: userId } = reduxStore.getState().login.user;
Expand Down
2 changes: 1 addition & 1 deletion app/sagas/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const handleDeleteRoom = function* handleDeleteRoom({ rid, t }) {
};

const handleCloseRoom = function* handleCloseRoom({ rid }) {
const isMasterDetail = yield select(state => state.app.isMasterDetail);
const requestComment = yield select(state => state.settings.Livechat_request_comment_when_closing_conversation);

const closeRoom = async(comment = '') => {
try {
await RocketChat.closeLivechat(rid, comment);
const isMasterDetail = await select(state => state.app.isMasterDetail);
if (isMasterDetail) {
Navigation.navigate('DrawerNavigator');
} else {
Expand Down
46 changes: 44 additions & 2 deletions app/views/SettingsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,20 @@ class SettingsView extends React.Component {
isMasterDetail: PropTypes.bool,
logout: PropTypes.func.isRequired,
selectServerRequest: PropTypes.func,
token: PropTypes.string,
user: PropTypes.shape({
roles: PropTypes.array,
statusLivechat: PropTypes.string
}),
appStart: PropTypes.func
}

get showLivechat() {
const { user } = this.props;
const { roles } = user;

return roles.includes('livechat-agent');
}

handleLogout = () => {
showConfirmationAlert({
message: I18n.t('You_will_be_logged_out_of_this_application'),
Expand Down Expand Up @@ -114,6 +124,14 @@ class SettingsView extends React.Component {
}
}

toggleLivechat = async() => {
try {
await RocketChat.changeLivechatStatus();
} catch {
// Do nothing
}
}

navigateToScreen = (screen) => {
const { navigation } = this.props;
navigation.navigate(screen);
Expand Down Expand Up @@ -172,6 +190,18 @@ class SettingsView extends React.Component {
);
}

renderLivechatSwitch = () => {
const { user } = this.props;
const { statusLivechat } = user;
return (
<Switch
value={statusLivechat === 'available'}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={this.toggleLivechat}
/>
);
}

render() {
const { server, isMasterDetail, theme } = this.props;
return (
Expand Down Expand Up @@ -292,6 +322,18 @@ class SettingsView extends React.Component {

<SectionSeparator theme={theme} />

{this.showLivechat ? (
<>
<ListItem
title={I18n.t('Omnichannel')}
testID='settings-view-livechat'
right={() => this.renderLivechatSwitch()}
theme={theme}
/>
<SectionSeparator theme={theme} />
</>
) : null}

<ListItem
title={I18n.t('Send_crash_report')}
testID='settings-view-crash-report'
Expand Down Expand Up @@ -331,7 +373,7 @@ class SettingsView extends React.Component {

const mapStateToProps = state => ({
server: state.server,
token: getUserSelector(state).token,
user: getUserSelector(state),
allowCrashReport: state.crashReport.allowCrashReport,
isMasterDetail: state.app.isMasterDetail
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"react-native-keyboard-tracking-view": "5.7.0",
"react-native-keycommands": "2.0.3",
"react-native-localize": "1.4.0",
"react-native-mime-types": "^2.2.1",
"react-native-mime-types": "2.3.0",
"react-native-modal": "11.5.6",
"react-native-navigation-bar-color": "2.0.1",
"react-native-notifications": "2.1.7",
Expand Down
14 changes: 14 additions & 0 deletions patches/@rocket.chat+sdk+1.0.0-dj.15.patch
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ index 17c2c2b..cb094e8 100644
/** Check result data for success, allowing override to ignore some errors */
success (result: any, ignore?: RegExp) {
return (
diff --git a/node_modules/@rocket.chat/sdk/lib/drivers/ddp.ts b/node_modules/@rocket.chat/sdk/lib/drivers/ddp.ts
index 247ce8b..2687abc 100644
--- a/node_modules/@rocket.chat/sdk/lib/drivers/ddp.ts
+++ b/node_modules/@rocket.chat/sdk/lib/drivers/ddp.ts
@@ -538,7 +538,8 @@ export class DDPDriver extends EventEmitter implements ISocket, IDriver {
'notification',
'rooms-changed',
'subscriptions-changed',
- 'uiInteraction'
+ 'uiInteraction',
+ 'userData'
].map(event => this.subscribe(topic, `${this.userId}/${event}`, false)))
}

2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11877,7 +11877,7 @@ react-native-localize@1.4.0:
resolved "https://registry.yarnpkg.com/react-native-localize/-/react-native-localize-1.4.0.tgz#4653596d066d0941c48f5404dc1c0d08b6950443"
integrity sha512-W2MQxm6hzD549ZbZcbWzWtYJseY7S7WR2WgsNhm9ULmbwP7tXFfOTbkJjQoqgPXYSXogKN3srXhntVsNZL0Ksw==

react-native-mime-types@^2.2.1:
react-native-mime-types@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/react-native-mime-types/-/react-native-mime-types-2.3.0.tgz#1278602c3da94ffb47c6400ef861901c4ebac420"
integrity sha512-9l/kkT1QM0i0xAKkOADkP6jIMhqiS+R/eSKBS/lsUmuMYMqboClyrwTFFZwUcaVIN0SpeH4wOKhYTqCnFgRsEw==
Expand Down