From 7d03c24b44a2f4eba86adf86954280fa73e726e4 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Fri, 2 Oct 2015 09:50:34 -0400 Subject: Changed direct channels in the sidebar to be displayed based on user preferences --- web/react/utils/async_client.jsx | 29 +++++++++++++++++++++++++++++ web/react/utils/client.jsx | 14 ++++++++++++++ web/react/utils/constants.jsx | 1 + 3 files changed, 44 insertions(+) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index a903f055b..3f084578a 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -637,3 +637,32 @@ export function getMyTeam() { } ); } + +export function getDirectChannels() { + if (isCallInProgress('getDirectChannels')) { + return; + } + + callTracker.getDirectChannels = utils.getTimestamp(); + client.getPreferencesByName( + 'direct_channels', + 'show_hide', + (data, textStatus, xhr) => { + callTracker.getDirectChannels = 0; + + if (xhr.status === 304 || !data) { + return; + } + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_PREFERENCES, + preferences: data + }); + }, + (err) => { + callTracker.getDirectChannels = 0; + dispatchError(err, 'getDirectChannels'); + } + ); +} + diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 6dccfcdeb..f1827f296 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -1141,3 +1141,17 @@ export function listIncomingHooks(success, error) { } }); } + +export function getPreferencesByName(category, name, success, error) { + $.ajax({ + url: `/api/v1/preferences/${category}/${name}`, + dataType: 'json', + type: 'GET', + success, + error: (xhr, status, err) => { + var e = handleError('getPreferencesByName', xhr, status, err); + error(e); + } + }); +} + diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index e3cbfccde..56c47a244 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -28,6 +28,7 @@ module.exports = { RECIEVED_AUDITS: null, RECIEVED_TEAMS: null, RECIEVED_STATUSES: null, + RECIEVED_PREFERENCES: null, RECIEVED_MSG: null, -- cgit v1.2.3-1-g7c22 From ed31538893ad2790de46ace7eeac5c1aa015a7f1 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Fri, 2 Oct 2015 14:25:55 -0400 Subject: Changed direct messages channels so users can show/hide them --- web/react/utils/async_client.jsx | 24 ++++++++++++++++++++++++ web/react/utils/client.jsx | 13 +++++++++++++ 2 files changed, 37 insertions(+) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index 3f084578a..d665dfc94 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -666,3 +666,27 @@ export function getDirectChannels() { ); } +export function setPreferences(preferences, success, error) { + client.setPreferences( + preferences, + (data, textStatus, xhr) => { + if (xhr.status !== 304) { + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_PREFERENCES, + preferences + }); + } + + if (success) { + success(data); + } + }, + (err) => { + dispatchError(err, 'setPreferences'); + + if (error) { + error(); + } + } + ); +} diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index f1827f296..2134dc0f5 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -1155,3 +1155,16 @@ export function getPreferencesByName(category, name, success, error) { }); } +export function setPreferences(preferences, success, error) { + $.ajax({ + url: '/api/v1/preferences/set', + dataType: 'json', + type: 'POST', + data: JSON.stringify(preferences), + success, + error: (xhr, status, err) => { + var e = handleError('setPreferences', xhr, status, err); + error(e); + } + }); +} -- cgit v1.2.3-1-g7c22 From 599644fb2fa75d1760420806c8c821959fc6b645 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 5 Oct 2015 12:03:27 -0400 Subject: Renamed show_hide preference to show --- web/react/utils/async_client.jsx | 4 ++-- web/react/utils/constants.jsx | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index d665dfc94..a0ccccd88 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -645,8 +645,8 @@ export function getDirectChannels() { callTracker.getDirectChannels = utils.getTimestamp(); client.getPreferencesByName( - 'direct_channels', - 'show_hide', + Constants.Preferences.CATEGORY_DIRECT_CHANNELS, + Constants.Preferences.NAME_SHOW, (data, textStatus, xhr) => { callTracker.getDirectChannels = 0; diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index 56c47a244..a576b9098 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -286,5 +286,9 @@ module.exports = { id: 'mentionHighlightLink', uiName: 'Mention Highlight Link' } - ] + ], + Preferences: { + CATEGORY_DIRECT_CHANNELS: 'direct_channels', + NAME_SHOW: 'show' + } }; -- cgit v1.2.3-1-g7c22 From 097d236f437b0c5af167cd383c6ee4c3ee45f495 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 7 Oct 2015 11:34:29 -0400 Subject: Fixed edge cases with leaving a direct channel while viewing that channel --- web/react/utils/client.jsx | 1 + 1 file changed, 1 insertion(+) (limited to 'web/react/utils') diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 2134dc0f5..4e3505ad2 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -1159,6 +1159,7 @@ export function setPreferences(preferences, success, error) { $.ajax({ url: '/api/v1/preferences/set', dataType: 'json', + contentType: 'application/json', type: 'POST', data: JSON.stringify(preferences), success, -- cgit v1.2.3-1-g7c22 From 2a39e8dbfab8506b09d0d030f87cac4c079b975a Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 13 Oct 2015 11:52:17 -0400 Subject: Removed Preference.AltId --- web/react/utils/async_client.jsx | 23 +++++++++++------------ web/react/utils/client.jsx | 12 ++++++------ web/react/utils/constants.jsx | 3 +-- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'web/react/utils') diff --git a/web/react/utils/async_client.jsx b/web/react/utils/async_client.jsx index a0ccccd88..1bf8a6fee 100644 --- a/web/react/utils/async_client.jsx +++ b/web/react/utils/async_client.jsx @@ -638,17 +638,16 @@ export function getMyTeam() { ); } -export function getDirectChannels() { - if (isCallInProgress('getDirectChannels')) { +export function getDirectChannelPreferences() { + if (isCallInProgress('getDirectChannelPreferences')) { return; } - callTracker.getDirectChannels = utils.getTimestamp(); - client.getPreferencesByName( - Constants.Preferences.CATEGORY_DIRECT_CHANNELS, - Constants.Preferences.NAME_SHOW, + callTracker.getDirectChannelPreferences = utils.getTimestamp(); + client.getPreferenceCategory( + Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, (data, textStatus, xhr) => { - callTracker.getDirectChannels = 0; + callTracker.getDirectChannelPreferences = 0; if (xhr.status === 304 || !data) { return; @@ -660,14 +659,14 @@ export function getDirectChannels() { }); }, (err) => { - callTracker.getDirectChannels = 0; - dispatchError(err, 'getDirectChannels'); + callTracker.getDirectChannelPreferences = 0; + dispatchError(err, 'getDirectChannelPreferences'); } ); } -export function setPreferences(preferences, success, error) { - client.setPreferences( +export function savePreferences(preferences, success, error) { + client.savePreferences( preferences, (data, textStatus, xhr) => { if (xhr.status !== 304) { @@ -682,7 +681,7 @@ export function setPreferences(preferences, success, error) { } }, (err) => { - dispatchError(err, 'setPreferences'); + dispatchError(err, 'savePreferences'); if (error) { error(); diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx index 4e3505ad2..76a402855 100644 --- a/web/react/utils/client.jsx +++ b/web/react/utils/client.jsx @@ -1142,29 +1142,29 @@ export function listIncomingHooks(success, error) { }); } -export function getPreferencesByName(category, name, success, error) { +export function getPreferenceCategory(category, success, error) { $.ajax({ - url: `/api/v1/preferences/${category}/${name}`, + url: `/api/v1/preferences/${category}`, dataType: 'json', type: 'GET', success, error: (xhr, status, err) => { - var e = handleError('getPreferencesByName', xhr, status, err); + var e = handleError('getPreferenceCategory', xhr, status, err); error(e); } }); } -export function setPreferences(preferences, success, error) { +export function savePreferences(preferences, success, error) { $.ajax({ - url: '/api/v1/preferences/set', + url: '/api/v1/preferences/save', dataType: 'json', contentType: 'application/json', type: 'POST', data: JSON.stringify(preferences), success, error: (xhr, status, err) => { - var e = handleError('setPreferences', xhr, status, err); + var e = handleError('savePreferences', xhr, status, err); error(e); } }); diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index a576b9098..cee2ec114 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -288,7 +288,6 @@ module.exports = { } ], Preferences: { - CATEGORY_DIRECT_CHANNELS: 'direct_channels', - NAME_SHOW: 'show' + CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show' } }; -- cgit v1.2.3-1-g7c22