From c24c16c932df32d9636386bc782f301833047a5d Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 6 Apr 2020 16:32:58 -0300 Subject: [PATCH] [FIX] Change user own status (#1995) * [FIX] Change user own status * [IMPROVEMENT] Set activeUsers Co-authored-by: Diego Mello --- app/lib/rocketchat.js | 7 ++----- app/sagas/login.js | 8 +++++++- app/views/StatusView.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index e7247c2ce..f0dbf2489 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -769,12 +769,9 @@ const RocketChat = { setUserPresenceOnline() { return this.methodCall('UserPresence:online'); }, - setUserPresenceDefaultStatus(status) { - return this.methodCall('UserPresence:setDefaultStatus', status); - }, - setUserStatus(message) { + setUserStatus(status, message) { // RC 1.2.0 - return this.post('users.setStatus', { message }); + return this.post('users.setStatus', { status, message }); }, setReaction(emoji, messageId) { // RC 0.62.2 diff --git a/app/sagas/login.js b/app/sagas/login.js index 80d158ddc..4fc4a3504 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -21,6 +21,7 @@ import database from '../lib/database'; import EventEmitter from '../utils/events'; import { inviteLinksRequest } from '../actions/inviteLinks'; import { showErrorAlert } from '../utils/info'; +import { setActiveUsers } from '../actions/activeUsers'; const getServer = state => state.server.server; const loginWithPasswordCall = args => RocketChat.loginWithPassword(args); @@ -188,11 +189,16 @@ const handleLogout = function* handleLogout({ forcedByServer }) { } }; -const handleSetUser = function handleSetUser({ user }) { +const handleSetUser = function* handleSetUser({ user }) { if (user && user.language) { I18n.locale = user.language; moment.locale(toMomentLocale(user.language)); } + + if (user && user.status) { + const userId = yield select(state => state.login.user.id); + yield put(setActiveUsers({ [userId]: user })); + } }; const root = function* root() { diff --git a/app/views/StatusView.js b/app/views/StatusView.js index 1f142794c..335529907 100644 --- a/app/views/StatusView.js +++ b/app/views/StatusView.js @@ -21,6 +21,8 @@ import { withSplit } from '../split'; import { themedHeader } from '../utils/navigation'; import { getUserSelector } from '../selectors/login'; import { CustomHeaderButtons, Item, CancelModalButton } from '../containers/HeaderButton'; +import store from '../lib/createStore'; +import { setUser } from '../actions/login'; const STATUS = [{ id: 'online', @@ -75,6 +77,7 @@ class StatusView extends React.Component { static propTypes = { user: PropTypes.shape({ + id: PropTypes.string, status: PropTypes.string, statusText: PropTypes.string }), @@ -112,11 +115,12 @@ class StatusView extends React.Component { setCustomStatus = async() => { const { statusText } = this.state; + const { user } = this.props; this.setState({ loading: true }); try { - const result = await RocketChat.setUserStatus(statusText); + const result = await RocketChat.setUserStatus(user.status, statusText); if (result.success) { EventEmitter.emit(LISTENER, { message: I18n.t('Status_saved_successfully') }); } else { @@ -163,6 +167,7 @@ class StatusView extends React.Component { } renderItem = ({ item }) => { + const { statusText } = this.state; const { theme, user } = this.props; const { id, name } = item; return ( @@ -171,7 +176,10 @@ class StatusView extends React.Component { onPress={async() => { if (user.status !== item.id) { try { - await RocketChat.setUserPresenceDefaultStatus(item.id); + const result = await RocketChat.setUserStatus(item.id, statusText); + if (result.success) { + store.dispatch(setUser({ status: item.id })); + } } catch (e) { log(e); }