format channel_store to more closely match style guide and sort channels in channel store over sidebar
Этот коммит содержится в:
@@ -113,22 +113,9 @@ function getStateFromStores() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var channels = ChannelStore.getAll();
|
|
||||||
if (channels) {
|
|
||||||
channels.sort(function chanSort(a, b) {
|
|
||||||
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.display_name.toLowerCase() > b.display_name.toLowerCase()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeId: currentId,
|
activeId: currentId,
|
||||||
channels: channels,
|
channels: ChannelStore.getAll(),
|
||||||
members: members,
|
members: members,
|
||||||
showDirectChannels: showDirectChannels,
|
showDirectChannels: showDirectChannels,
|
||||||
hideDirectChannels: readDirectChannels
|
hideDirectChannels: readDirectChannels
|
||||||
|
|||||||
@@ -10,247 +10,264 @@ var ActionTypes = Constants.ActionTypes;
|
|||||||
|
|
||||||
var BrowserStore = require('../stores/browser_store.jsx');
|
var BrowserStore = require('../stores/browser_store.jsx');
|
||||||
|
|
||||||
|
|
||||||
var CHANGE_EVENT = 'change';
|
var CHANGE_EVENT = 'change';
|
||||||
var MORE_CHANGE_EVENT = 'change';
|
var MORE_CHANGE_EVENT = 'change';
|
||||||
var EXTRA_INFO_EVENT = 'extra_info';
|
var EXTRA_INFO_EVENT = 'extra_info';
|
||||||
|
|
||||||
var ChannelStore = assign({}, EventEmitter.prototype, {
|
var ChannelStore = assign({}, EventEmitter.prototype, {
|
||||||
_current_id: null,
|
_currentId: null,
|
||||||
emitChange: function() {
|
emitChange: function() {
|
||||||
this.emit(CHANGE_EVENT);
|
this.emit(CHANGE_EVENT);
|
||||||
},
|
},
|
||||||
addChangeListener: function(callback) {
|
addChangeListener: function(callback) {
|
||||||
this.on(CHANGE_EVENT, callback);
|
this.on(CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
removeChangeListener: function(callback) {
|
removeChangeListener: function(callback) {
|
||||||
this.removeListener(CHANGE_EVENT, callback);
|
this.removeListener(CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
emitMoreChange: function() {
|
emitMoreChange: function() {
|
||||||
this.emit(MORE_CHANGE_EVENT);
|
this.emit(MORE_CHANGE_EVENT);
|
||||||
},
|
},
|
||||||
addMoreChangeListener: function(callback) {
|
addMoreChangeListener: function(callback) {
|
||||||
this.on(MORE_CHANGE_EVENT, callback);
|
this.on(MORE_CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
removeMoreChangeListener: function(callback) {
|
removeMoreChangeListener: function(callback) {
|
||||||
this.removeListener(MORE_CHANGE_EVENT, callback);
|
this.removeListener(MORE_CHANGE_EVENT, callback);
|
||||||
},
|
},
|
||||||
emitExtraInfoChange: function() {
|
emitExtraInfoChange: function() {
|
||||||
this.emit(EXTRA_INFO_EVENT);
|
this.emit(EXTRA_INFO_EVENT);
|
||||||
},
|
},
|
||||||
addExtraInfoChangeListener: function(callback) {
|
addExtraInfoChangeListener: function(callback) {
|
||||||
this.on(EXTRA_INFO_EVENT, callback);
|
this.on(EXTRA_INFO_EVENT, callback);
|
||||||
},
|
},
|
||||||
removeExtraInfoChangeListener: function(callback) {
|
removeExtraInfoChangeListener: function(callback) {
|
||||||
this.removeListener(EXTRA_INFO_EVENT, callback);
|
this.removeListener(EXTRA_INFO_EVENT, callback);
|
||||||
},
|
},
|
||||||
findFirstBy: function(field, value) {
|
findFirstBy: function(field, value) {
|
||||||
var channels = this._getChannels();
|
var channels = this._getChannels();
|
||||||
for (var i = 0; i < channels.length; i++) {
|
for (var i = 0; i < channels.length; i++) {
|
||||||
if (channels[i][field] == value) {
|
if (channels[i][field] === value) {
|
||||||
return channels[i];
|
return channels[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
get: function(id) {
|
get: function(id) {
|
||||||
return this.findFirstBy('id', id);
|
return this.findFirstBy('id', id);
|
||||||
},
|
},
|
||||||
getMember: function(id) {
|
getMember: function(id) {
|
||||||
return this.getAllMembers()[id];
|
return this.getAllMembers()[id];
|
||||||
},
|
},
|
||||||
getByName: function(name) {
|
getByName: function(name) {
|
||||||
return this.findFirstBy('name', name);
|
return this.findFirstBy('name', name);
|
||||||
},
|
},
|
||||||
getAll: function() {
|
getAll: function() {
|
||||||
return this._getChannels();
|
return this._getChannels();
|
||||||
},
|
},
|
||||||
getAllMembers: function() {
|
getAllMembers: function() {
|
||||||
return this._getChannelMembers();
|
return this._getChannelMembers();
|
||||||
},
|
},
|
||||||
getMoreAll: function() {
|
getMoreAll: function() {
|
||||||
return this._getMoreChannels();
|
return this._getMoreChannels();
|
||||||
},
|
},
|
||||||
setCurrentId: function(id) {
|
setCurrentId: function(id) {
|
||||||
this._current_id = id;
|
this._currentId = id;
|
||||||
},
|
},
|
||||||
setLastVisitedName: function(name) {
|
setLastVisitedName: function(name) {
|
||||||
if (name == null)
|
if (name == null) {
|
||||||
BrowserStore.removeItem("last_visited_name");
|
BrowserStore.removeItem('last_visited_name');
|
||||||
else
|
} else {
|
||||||
BrowserStore.setItem("last_visited_name", name);
|
BrowserStore.setItem('last_visited_name', name);
|
||||||
},
|
}
|
||||||
getLastVisitedName: function() {
|
},
|
||||||
return BrowserStore.getItem("last_visited_name");
|
getLastVisitedName: function() {
|
||||||
},
|
return BrowserStore.getItem('last_visited_name');
|
||||||
resetCounts: function(id) {
|
},
|
||||||
var cm = this._getChannelMembers();
|
resetCounts: function(id) {
|
||||||
for (var cmid in cm) {
|
var cm = this._getChannelMembers();
|
||||||
if (cm[cmid].channel_id == id) {
|
for (var cmid in cm) {
|
||||||
var c = this.get(id);
|
if (cm[cmid].channel_id === id) {
|
||||||
if (c) {
|
var c = this.get(id);
|
||||||
cm[cmid].msg_count = this.get(id).total_msg_count;
|
if (c) {
|
||||||
cm[cmid].mention_count = 0;
|
cm[cmid].msg_count = this.get(id).total_msg_count;
|
||||||
}
|
cm[cmid].mention_count = 0;
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
this._storeChannelMembers(cm);
|
}
|
||||||
},
|
this._storeChannelMembers(cm);
|
||||||
getCurrentId: function() {
|
},
|
||||||
return this._current_id;
|
getCurrentId: function() {
|
||||||
},
|
return this._currentId;
|
||||||
getCurrent: function() {
|
},
|
||||||
var currentId = this.getCurrentId();
|
getCurrent: function() {
|
||||||
|
var currentId = this.getCurrentId();
|
||||||
|
|
||||||
if (currentId)
|
if (currentId) {
|
||||||
return this.get(currentId);
|
return this.get(currentId);
|
||||||
else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
getCurrentMember: function() {
|
},
|
||||||
var currentId = ChannelStore.getCurrentId();
|
getCurrentMember: function() {
|
||||||
|
var currentId = ChannelStore.getCurrentId();
|
||||||
|
|
||||||
if (currentId)
|
if (currentId) {
|
||||||
return this.getAllMembers()[currentId];
|
return this.getAllMembers()[currentId];
|
||||||
else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
setChannelMember: function(member) {
|
},
|
||||||
var members = this._getChannelMembers();
|
setChannelMember: function(member) {
|
||||||
members[member.channel_id] = member;
|
var members = this._getChannelMembers();
|
||||||
this._storeChannelMembers(members);
|
members[member.channel_id] = member;
|
||||||
this.emitChange();
|
this._storeChannelMembers(members);
|
||||||
},
|
this.emitChange();
|
||||||
getCurrentExtraInfo: function() {
|
},
|
||||||
var currentId = ChannelStore.getCurrentId();
|
getCurrentExtraInfo: function() {
|
||||||
var extra = null;
|
var currentId = ChannelStore.getCurrentId();
|
||||||
|
var extra = null;
|
||||||
|
|
||||||
if (currentId)
|
if (currentId) {
|
||||||
extra = this._getExtraInfos()[currentId];
|
extra = this._getExtraInfos()[currentId];
|
||||||
|
}
|
||||||
|
|
||||||
if (extra == null)
|
if (extra == null) {
|
||||||
extra = {members: []};
|
extra = {members: []};
|
||||||
|
}
|
||||||
|
|
||||||
return extra;
|
return extra;
|
||||||
},
|
},
|
||||||
getExtraInfo: function(channel_id) {
|
getExtraInfo: function(channelId) {
|
||||||
var extra = null;
|
var extra = null;
|
||||||
|
|
||||||
if (channel_id)
|
if (channelId) {
|
||||||
extra = this._getExtraInfos()[channel_id];
|
extra = this._getExtraInfos()[channelId];
|
||||||
|
}
|
||||||
|
|
||||||
if (extra == null)
|
if (extra == null) {
|
||||||
extra = {members: []};
|
extra = {members: []};
|
||||||
|
}
|
||||||
|
|
||||||
return extra;
|
return extra;
|
||||||
},
|
},
|
||||||
_storeChannel: function(channel) {
|
_storeChannel: function(channel) {
|
||||||
var channels = this._getChannels();
|
var channels = this._getChannels();
|
||||||
var found;
|
var found;
|
||||||
|
|
||||||
for (var i = 0; i < channels.length; i++) {
|
for (var i = 0; i < channels.length; i++) {
|
||||||
if (channels[i].id == channel.id) {
|
if (channels[i].id === channel.id) {
|
||||||
channels[i] = channel;
|
channels[i] = channel;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
channels.push(channel);
|
channels.push(channel);
|
||||||
channels.sort(function(a,b) {
|
}
|
||||||
if (a.display_name < b.display_name) return -1;
|
|
||||||
if (a.display_name > b.display_name) return 1;
|
channels.sort(function chanSort(a, b) {
|
||||||
return 0;
|
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (a.display_name.toLowerCase() > b.display_name.toLowerCase()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
this._storeChannels(channels);
|
|
||||||
},
|
|
||||||
_storeChannels: function(channels) {
|
|
||||||
BrowserStore.setItem("channels", channels);
|
|
||||||
},
|
|
||||||
_getChannels: function() {
|
|
||||||
return BrowserStore.getItem("channels", []);
|
|
||||||
},
|
|
||||||
_storeChannelMember: function(channelMember) {
|
|
||||||
var members = this._getChannelMembers();
|
|
||||||
members[channelMember.channel_id] = channelMember;
|
|
||||||
this._storeChannelMembers(members);
|
|
||||||
},
|
|
||||||
_storeChannelMembers: function(channelMembers) {
|
|
||||||
BrowserStore.setItem("channel_members", channelMembers);
|
|
||||||
},
|
|
||||||
_getChannelMembers: function() {
|
|
||||||
return BrowserStore.getItem("channel_members", {});
|
|
||||||
},
|
|
||||||
_storeMoreChannels: function(channels) {
|
|
||||||
BrowserStore.setItem("more_channels", channels);
|
|
||||||
},
|
|
||||||
_getMoreChannels: function() {
|
|
||||||
var channels = BrowserStore.getItem("more_channels");
|
|
||||||
|
|
||||||
if (channels == null) {
|
this._storeChannels(channels);
|
||||||
channels = {};
|
},
|
||||||
channels.loading = true;
|
_storeChannels: function(channels) {
|
||||||
}
|
BrowserStore.setItem('channels', channels);
|
||||||
|
},
|
||||||
|
_getChannels: function() {
|
||||||
|
return BrowserStore.getItem('channels', []);
|
||||||
|
},
|
||||||
|
_storeChannelMember: function(channelMember) {
|
||||||
|
var members = this._getChannelMembers();
|
||||||
|
members[channelMember.channel_id] = channelMember;
|
||||||
|
this._storeChannelMembers(members);
|
||||||
|
},
|
||||||
|
_storeChannelMembers: function(channelMembers) {
|
||||||
|
BrowserStore.setItem('channel_members', channelMembers);
|
||||||
|
},
|
||||||
|
_getChannelMembers: function() {
|
||||||
|
return BrowserStore.getItem('channel_members', {});
|
||||||
|
},
|
||||||
|
_storeMoreChannels: function(channels) {
|
||||||
|
BrowserStore.setItem('more_channels', channels);
|
||||||
|
},
|
||||||
|
_getMoreChannels: function() {
|
||||||
|
var channels = BrowserStore.getItem('more_channels');
|
||||||
|
|
||||||
return channels;
|
if (channels == null) {
|
||||||
},
|
channels = {};
|
||||||
_storeExtraInfos: function(extraInfos) {
|
channels.loading = true;
|
||||||
BrowserStore.setItem("extra_infos", extraInfos);
|
}
|
||||||
},
|
|
||||||
_getExtraInfos: function() {
|
return channels;
|
||||||
return BrowserStore.getItem("extra_infos", {});
|
},
|
||||||
},
|
_storeExtraInfos: function(extraInfos) {
|
||||||
isDefault: function(channel) {
|
BrowserStore.setItem('extra_infos', extraInfos);
|
||||||
return channel.name == Constants.DEFAULT_CHANNEL;
|
},
|
||||||
}
|
_getExtraInfos: function() {
|
||||||
|
return BrowserStore.getItem('extra_infos', {});
|
||||||
|
},
|
||||||
|
isDefault: function(channel) {
|
||||||
|
return channel.name === Constants.DEFAULT_CHANNEL;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ChannelStore.dispatchToken = AppDispatcher.register(function(payload) {
|
ChannelStore.dispatchToken = AppDispatcher.register(function(payload) {
|
||||||
var action = payload.action;
|
var action = payload.action;
|
||||||
|
var currentId;
|
||||||
|
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
|
|
||||||
case ActionTypes.CLICK_CHANNEL:
|
case ActionTypes.CLICK_CHANNEL:
|
||||||
ChannelStore.setCurrentId(action.id);
|
ChannelStore.setCurrentId(action.id);
|
||||||
ChannelStore.setLastVisitedName(action.name);
|
ChannelStore.setLastVisitedName(action.name);
|
||||||
ChannelStore.resetCounts(action.id);
|
ChannelStore.resetCounts(action.id);
|
||||||
ChannelStore.emitChange();
|
ChannelStore.emitChange();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ActionTypes.RECIEVED_CHANNELS:
|
case ActionTypes.RECIEVED_CHANNELS:
|
||||||
ChannelStore._storeChannels(action.channels);
|
ChannelStore._storeChannels(action.channels);
|
||||||
ChannelStore._storeChannelMembers(action.members);
|
ChannelStore._storeChannelMembers(action.members);
|
||||||
var currentId = ChannelStore.getCurrentId();
|
currentId = ChannelStore.getCurrentId();
|
||||||
if (currentId) ChannelStore.resetCounts(currentId);
|
if (currentId) {
|
||||||
ChannelStore.emitChange();
|
ChannelStore.resetCounts(currentId);
|
||||||
break;
|
}
|
||||||
|
ChannelStore.emitChange();
|
||||||
|
break;
|
||||||
|
|
||||||
case ActionTypes.RECIEVED_CHANNEL:
|
case ActionTypes.RECIEVED_CHANNEL:
|
||||||
ChannelStore._storeChannel(action.channel);
|
ChannelStore._storeChannel(action.channel);
|
||||||
ChannelStore._storeChannelMember(action.member);
|
ChannelStore._storeChannelMember(action.member);
|
||||||
var currentId = ChannelStore.getCurrentId();
|
currentId = ChannelStore.getCurrentId();
|
||||||
if (currentId) ChannelStore.resetCounts(currentId);
|
if (currentId) {
|
||||||
ChannelStore.emitChange();
|
ChannelStore.resetCounts(currentId);
|
||||||
break;
|
}
|
||||||
|
ChannelStore.emitChange();
|
||||||
|
break;
|
||||||
|
|
||||||
case ActionTypes.RECIEVED_MORE_CHANNELS:
|
case ActionTypes.RECIEVED_MORE_CHANNELS:
|
||||||
ChannelStore._storeMoreChannels(action.channels);
|
ChannelStore._storeMoreChannels(action.channels);
|
||||||
ChannelStore.emitMoreChange();
|
ChannelStore.emitMoreChange();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ActionTypes.RECIEVED_CHANNEL_EXTRA_INFO:
|
case ActionTypes.RECIEVED_CHANNEL_EXTRA_INFO:
|
||||||
var extra_infos = ChannelStore._getExtraInfos();
|
var extraInfos = ChannelStore._getExtraInfos();
|
||||||
extra_infos[action.extra_info.id] = action.extra_info;
|
extraInfos[action.extra_info.id] = action.extra_info;
|
||||||
ChannelStore._storeExtraInfos(extra_infos);
|
ChannelStore._storeExtraInfos(extraInfos);
|
||||||
ChannelStore.emitExtraInfoChange();
|
ChannelStore.emitExtraInfoChange();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = ChannelStore;
|
module.exports = ChannelStore;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user