[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:
parent
32d105051d
commit
c24c16c932
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue