Removed Preference.AltId
Этот коммит содержится в:
@@ -23,9 +23,8 @@ export default class MoreDirectChannels extends React.Component {
|
||||
}
|
||||
|
||||
handleJoinDirectChannel(channel) {
|
||||
const preference = PreferenceStore.setPreferenceWithAltId(Constants.Preferences.CATEGORY_DIRECT_CHANNELS,
|
||||
Constants.Preferences.NAME_SHOW, channel.teammate_id, 'true');
|
||||
AsyncClient.setPreferences([preference]);
|
||||
const preference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, channel.teammate_id, 'true');
|
||||
AsyncClient.savePreferences([preference]);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -54,7 +54,7 @@ export default class Sidebar extends React.Component {
|
||||
teammates.push(teamMemberMap[id]);
|
||||
}
|
||||
|
||||
const preferences = PreferenceStore.getPreferences(Constants.Preferences.CATEGORY_DIRECT_CHANNELS, Constants.Preferences.NAME_SHOW);
|
||||
const preferences = PreferenceStore.getPreferences(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
|
||||
|
||||
// Create lists of all read and unread direct channels
|
||||
var visibleDirectChannels = [];
|
||||
@@ -95,13 +95,12 @@ export default class Sidebar extends React.Component {
|
||||
channel.teammate_id = teammate.id;
|
||||
channel.status = UserStore.getStatus(teammate.id);
|
||||
|
||||
if (preferences.some((preference) => (preference.alt_id === teammate.id && preference.value !== 'false'))) {
|
||||
if (preferences.some((preference) => (preference.name === teammate.id && preference.value !== 'false'))) {
|
||||
visibleDirectChannels.push(channel);
|
||||
} else if (forceShow) {
|
||||
// make sure that unread direct channels are visible
|
||||
const preference = PreferenceStore.setPreferenceWithAltId(Constants.Preferences.CATEGORY_DIRECT_CHANNELS,
|
||||
Constants.Preferences.NAME_SHOW, teammate.id, 'true');
|
||||
AsyncClient.setPreferences([preference]);
|
||||
const preference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, teammate.id, 'true');
|
||||
AsyncClient.savePreferences([preference]);
|
||||
|
||||
visibleDirectChannels.push(channel);
|
||||
} else {
|
||||
@@ -129,7 +128,7 @@ export default class Sidebar extends React.Component {
|
||||
SocketStore.addChangeListener(this.onSocketChange);
|
||||
PreferenceStore.addChangeListener(this.onChange);
|
||||
|
||||
AsyncClient.getDirectChannels();
|
||||
AsyncClient.getDirectChannelPreferences();
|
||||
|
||||
$('.nav-pills__container').perfectScrollbar();
|
||||
|
||||
@@ -310,9 +309,8 @@ export default class Sidebar extends React.Component {
|
||||
if (!this.isLeaving.get(channel.id)) {
|
||||
this.isLeaving.set(channel.id, true);
|
||||
|
||||
const preference = PreferenceStore.setPreferenceWithAltId(Constants.Preferences.CATEGORY_DIRECT_CHANNELS,
|
||||
Constants.Preferences.NAME_SHOW, channel.teammate_id, 'false');
|
||||
AsyncClient.setPreferences(
|
||||
const preference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, channel.teammate_id, 'false');
|
||||
AsyncClient.savePreferences(
|
||||
[preference],
|
||||
() => {
|
||||
this.isLeaving.set(channel.id, false);
|
||||
|
||||
@@ -15,12 +15,10 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
|
||||
this.getAllPreferences = this.getAllPreferences.bind(this);
|
||||
this.getPreference = this.getPreference.bind(this);
|
||||
this.getPreferenceWithAltId = this.getPreferenceWithAltId.bind(this);
|
||||
this.getPreferences = this.getPreferences.bind(this);
|
||||
this.getPreferencesWhere = this.getPreferencesWhere.bind(this);
|
||||
this.setAllPreferences = this.setAllPreferences.bind(this);
|
||||
this.setPreference = this.setPreference.bind(this);
|
||||
this.setPreferenceWithAltId = this.setPreferenceWithAltId.bind(this);
|
||||
|
||||
this.emitChange = this.emitChange.bind(this);
|
||||
this.addChangeListener = this.addChangeListener.bind(this);
|
||||
@@ -30,12 +28,12 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
this.dispatchToken = AppDispatcher.register(this.handleEventPayload);
|
||||
}
|
||||
|
||||
getKey(category, name, altId = '') {
|
||||
return `${category}-${name}-${altId}`;
|
||||
getKey(category, name) {
|
||||
return `${category}-${name}`;
|
||||
}
|
||||
|
||||
getKeyForModel(preference) {
|
||||
return `${preference.category}-${preference.name}-${preference.alt_id}`;
|
||||
return `${preference.category}-${preference.name}`;
|
||||
}
|
||||
|
||||
getAllPreferences() {
|
||||
@@ -46,12 +44,8 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
return this.getAllPreferences().get(this.getKey(category, name)) || defaultValue;
|
||||
}
|
||||
|
||||
getPreferenceWithAltId(category, name, altId, defaultValue = '') {
|
||||
return this.getAllPreferences().get(this.getKey(category, name, altId)) || defaultValue;
|
||||
}
|
||||
|
||||
getPreferences(category, name) {
|
||||
return this.getPreferencesWhere((preference) => (preference.category === category && preference.name === name));
|
||||
getPreferences(category) {
|
||||
return this.getPreferencesWhere((preference) => (preference.category === category));
|
||||
}
|
||||
|
||||
getPreferencesWhere(pred) {
|
||||
@@ -74,21 +68,16 @@ class PreferenceStoreClass extends EventEmitter {
|
||||
}
|
||||
|
||||
setPreference(category, name, value) {
|
||||
return this.setPreferenceWithAltId(category, name, '', value);
|
||||
}
|
||||
|
||||
setPreferenceWithAltId(category, name, altId, value) {
|
||||
const preferences = this.getAllPreferences();
|
||||
|
||||
const key = this.getKey(category, name, altId);
|
||||
const key = this.getKey(category, name);
|
||||
let preference = preferences.get(key);
|
||||
|
||||
if (!preference) {
|
||||
preference = {
|
||||
user_id: UserStore.getCurrentId(),
|
||||
category,
|
||||
name,
|
||||
alt_id: altId
|
||||
name
|
||||
};
|
||||
}
|
||||
preference.value = value;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -288,7 +288,6 @@ module.exports = {
|
||||
}
|
||||
],
|
||||
Preferences: {
|
||||
CATEGORY_DIRECT_CHANNELS: 'direct_channels',
|
||||
NAME_SHOW: 'show'
|
||||
CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show'
|
||||
}
|
||||
};
|
||||
|
||||
Ссылка в новой задаче
Block a user