Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Fixed a bug where user status is not displayed on first load of a product #9288

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 1 addition & 8 deletions actions/user_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,10 @@ export function autocompleteUsers(username) {
};
}

export function setUserStatus(currentUserId) {
return (doDispatch, doGetState) => {
return UserActions.getStatus(currentUserId)(doDispatch, doGetState);
};
}

export function autoResetStatus() {
return async (doDispatch, doGetState) => {
const {currentUserId} = getState().entities.users;
const {data: userStatus} = await setUserStatus(currentUserId)(doDispatch, doGetState);

const userStatus = Selectors.getCurrentUserStatus(doGetState());
if (userStatus.status === UserStatuses.OUT_OF_OFFICE || !userStatus.manual) {
return userStatus;
}
Expand Down
3 changes: 0 additions & 3 deletions components/status_dropdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {isStatusDropdownOpen} from 'selectors/views/status_dropdown';
import {GenericAction} from 'mattermost-redux/types/actions';
import {GlobalState} from 'types/store';

import {setUserStatus} from '../../actions/user_actions';

import StatusDropdown from './status_dropdown';

function makeMapStateToProps() {
Expand Down Expand Up @@ -54,7 +52,6 @@ function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
setStatus,
unsetCustomStatus,
setStatusDropdown,
setUserStatus,
}, dispatch),
};
}
Expand Down
5 changes: 0 additions & 5 deletions components/status_dropdown/status_dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Props = {
setStatus: (status: UserStatus) => ActionFunc;
unsetCustomStatus: () => ActionFunc;
setStatusDropdown: (open: boolean) => void;
setUserStatus: (userID: string) => void;
};
customStatus?: UserCustomStatus;
currentUser: UserProfile;
Expand Down Expand Up @@ -84,10 +83,6 @@ export default class StatusDropdown extends React.PureComponent <Props, State> {
};
}

componentDidMount() {
this.props.actions.setUserStatus(this.props.userId);
}

setStatus = (status: string, dndEndTime?: number): void => {
this.props.actions.setStatus({
user_id: this.props.userId,
Expand Down
1 change: 1 addition & 0 deletions packages/mattermost-redux/src/actions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export function loadMe(): ActionFunc {
const user = getState().entities.users.profiles[currentUserId];
if (currentUserId) {
Client4.setUserId(currentUserId);
await dispatch(getStatus(currentUserId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wait for this to complete? Since we aren't able to fire off this request while we're loading everything else, perhaps we could just dispatch it without awaiting on it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do need to wait for this. This is because the ResetStatusModal component fetches the status only on the component mount (and not updated) and if the status is not found in the store, sets it to offline. Not awaiting here causes the status to always be displayed as offline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do that since it'll make the first load longer. I think we either need to load the status asynchronously while the other stuff loads (like in the Promise.all above) or we could make the modal handle the unloaded state properly

}

if (user) {
Expand Down
14 changes: 14 additions & 0 deletions packages/mattermost-redux/src/reducers/entities/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,17 @@ function profilesInGroup(state: RelationOneToMany<Group, UserProfile> = {}, acti
}
}

function currentUserStatus(state: RelationOneToOne<UserProfile, string> = {}, action: GenericAction) {
harshilsharma63 marked this conversation as resolved.
Show resolved Hide resolved
switch (action.type) {
case UserTypes.RECEIVED_STATUS: {
return action.data;
}
default: {
return state;
}
}
}

function statuses(state: RelationOneToOne<UserProfile, string> = {}, action: GenericAction) {
switch (action.type) {
case UserTypes.RECEIVED_STATUS: {
Expand Down Expand Up @@ -635,4 +646,7 @@ export default combineReducers({

// Total user stats after filters have been applied
filteredStats,

// Current user's status object, including details about manual status.
currentUserStatus,
});
6 changes: 5 additions & 1 deletion packages/mattermost-redux/src/selectors/entities/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {Reaction} from 'mattermost-redux/types/reactions';
import {GlobalState} from 'mattermost-redux/types/store';
import {Team, TeamMembership} from 'mattermost-redux/types/teams';
import {Group} from 'mattermost-redux/types/groups';
import {UserProfile} from 'mattermost-redux/types/users';
import {UserProfile, UserStatus} from 'mattermost-redux/types/users';
import {
$Email,
$ID,
Expand Down Expand Up @@ -381,6 +381,10 @@ export const getProfilesWithoutTeam: (state: GlobalState, filters: Filters) => U
},
);

export function getCurrentUserStatus(state: GlobalState): UserStatus {
return state.entities.users.currentUserStatus;
}

export function getStatusForUserId(state: GlobalState, userId: $ID<UserProfile>): string {
return getUserStatuses(state)[userId];
}
Expand Down
2 changes: 2 additions & 0 deletions packages/mattermost-redux/src/store/initial_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE.txt for license information.

import {GlobalState} from 'mattermost-redux/types/store';
import {UserStatuses} from '../../../../utils/constants';
harshilsharma63 marked this conversation as resolved.
Show resolved Hide resolved

const state: GlobalState = {
entities: {
Expand All @@ -18,6 +19,7 @@ const state: GlobalState = {
},
users: {
currentUserId: '',
currentUserStatus: {user_id: '', status: UserStatuses.OFFLINE},
isManualStatus: {},
mySessions: [],
myAudits: [],
Expand Down
1 change: 1 addition & 0 deletions packages/mattermost-redux/src/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type UserProfileWithLastViewAt = UserProfile & {

export type UsersState = {
currentUserId: string;
currentUserStatus: UserStatus;
isManualStatus: RelationOneToOne<UserProfile, boolean>;
mySessions: Session[];
myAudits: Audit[];
Expand Down