[FIX] Change user own status (#1995)

* [FIX] Change user own status

* [IMPROVEMENT] Set activeUsers

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-04-06 16:32:58 -03:00 committed by GitHub
parent 32d105051d
commit c24c16c932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View File

@ -769,12 +769,9 @@ const RocketChat = {
setUserPresenceOnline() { setUserPresenceOnline() {
return this.methodCall('UserPresence:online'); return this.methodCall('UserPresence:online');
}, },
setUserPresenceDefaultStatus(status) { setUserStatus(status, message) {
return this.methodCall('UserPresence:setDefaultStatus', status);
},
setUserStatus(message) {
// RC 1.2.0 // RC 1.2.0
return this.post('users.setStatus', { message }); return this.post('users.setStatus', { status, message });
}, },
setReaction(emoji, messageId) { setReaction(emoji, messageId) {
// RC 0.62.2 // RC 0.62.2

View File

@ -21,6 +21,7 @@ import database from '../lib/database';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
import { inviteLinksRequest } from '../actions/inviteLinks'; import { inviteLinksRequest } from '../actions/inviteLinks';
import { showErrorAlert } from '../utils/info'; import { showErrorAlert } from '../utils/info';
import { setActiveUsers } from '../actions/activeUsers';
const getServer = state => state.server.server; const getServer = state => state.server.server;
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args); 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) { if (user && user.language) {
I18n.locale = user.language; I18n.locale = user.language;
moment.locale(toMomentLocale(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() { const root = function* root() {

View File

@ -21,6 +21,8 @@ import { withSplit } from '../split';
import { themedHeader } from '../utils/navigation'; import { themedHeader } from '../utils/navigation';
import { getUserSelector } from '../selectors/login'; import { getUserSelector } from '../selectors/login';
import { CustomHeaderButtons, Item, CancelModalButton } from '../containers/HeaderButton'; import { CustomHeaderButtons, Item, CancelModalButton } from '../containers/HeaderButton';
import store from '../lib/createStore';
import { setUser } from '../actions/login';
const STATUS = [{ const STATUS = [{
id: 'online', id: 'online',
@ -75,6 +77,7 @@ class StatusView extends React.Component {
static propTypes = { static propTypes = {
user: PropTypes.shape({ user: PropTypes.shape({
id: PropTypes.string,
status: PropTypes.string, status: PropTypes.string,
statusText: PropTypes.string statusText: PropTypes.string
}), }),
@ -112,11 +115,12 @@ class StatusView extends React.Component {
setCustomStatus = async() => { setCustomStatus = async() => {
const { statusText } = this.state; const { statusText } = this.state;
const { user } = this.props;
this.setState({ loading: true }); this.setState({ loading: true });
try { try {
const result = await RocketChat.setUserStatus(statusText); const result = await RocketChat.setUserStatus(user.status, statusText);
if (result.success) { if (result.success) {
EventEmitter.emit(LISTENER, { message: I18n.t('Status_saved_successfully') }); EventEmitter.emit(LISTENER, { message: I18n.t('Status_saved_successfully') });
} else { } else {
@ -163,6 +167,7 @@ class StatusView extends React.Component {
} }
renderItem = ({ item }) => { renderItem = ({ item }) => {
const { statusText } = this.state;
const { theme, user } = this.props; const { theme, user } = this.props;
const { id, name } = item; const { id, name } = item;
return ( return (
@ -171,7 +176,10 @@ class StatusView extends React.Component {
onPress={async() => { onPress={async() => {
if (user.status !== item.id) { if (user.status !== item.id) {
try { 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) { } catch (e) {
log(e); log(e);
} }