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

Commit

Permalink
Reset Preferences (#141)
Browse files Browse the repository at this point in the history
* Reset preferences

* Emit event when removed from the current channel

* Fix eslint
  • Loading branch information
enahum committed Jun 9, 2017
1 parent 8e0492e commit 488faa2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/action_types/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export default keyMirror({
DELETE_PREFERENCES_FAILURE: null,

RECEIVED_PREFERENCES: null,
RECEIVED_ALL_PREFERENCES: null,
DELETED_PREFERENCES: null
});
2 changes: 1 addition & 1 deletion src/actions/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function getMyPreferences() {
return bindClientFunc(
Client4.getMyPreferences,
PreferenceTypes.MY_PREFERENCES_REQUEST,
[PreferenceTypes.RECEIVED_PREFERENCES, PreferenceTypes.MY_PREFERENCES_SUCCESS],
[PreferenceTypes.RECEIVED_ALL_PREFERENCES, PreferenceTypes.MY_PREFERENCES_SUCCESS],
PreferenceTypes.MY_PREFERENCES_FAILURE
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/actions/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ function handleUserRemovedEvent(msg, dispatch, getState) {

if (msg.data.channel_id === currentChannelId) {
const defaultChannel = Object.values(channels).find((c) => c.team_id === currentTeamId && c.name === General.DEFAULT_CHANNEL);

// emit the event so the client can change his own state
EventEmitter.emit(General.DEFAULT_CHANNEL, defaultChannel.display_name);
selectChannel(defaultChannel.id)(dispatch, getState);
}
} else if (msg.data.channel_id === currentChannelId) {
Expand Down
12 changes: 12 additions & 0 deletions src/reducers/entities/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ function getKey(preference) {

function myPreferences(state = {}, action) {
switch (action.type) {
case PreferenceTypes.RECEIVED_ALL_PREFERENCES: {
const nextState = {};

if (action.data) {
for (const preference of action.data) {
nextState[getKey(preference)] = preference;
}
}

return nextState;
}

case PreferenceTypes.RECEIVED_PREFERENCES: {
const nextState = {...state};

Expand Down

0 comments on commit 488faa2

Please sign in to comment.