added getChannel api service and use that over getChannels where appropriate on client
Этот коммит содержится в:
@@ -146,12 +146,39 @@ var ChannelStore = assign({}, EventEmitter.prototype, {
|
||||
|
||||
return extra;
|
||||
},
|
||||
_storeChannel: function(channel) {
|
||||
var channels = this._getChannels();
|
||||
var found;
|
||||
|
||||
for (var i = 0; i < channels.length; i++) {
|
||||
if (channels[i].id == channel.id) {
|
||||
channels[i] = channel;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
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;
|
||||
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);
|
||||
},
|
||||
@@ -202,6 +229,14 @@ ChannelStore.dispatchToken = AppDispatcher.register(function(payload) {
|
||||
ChannelStore.emitChange();
|
||||
break;
|
||||
|
||||
case ActionTypes.RECIEVED_CHANNEL:
|
||||
ChannelStore._storeChannel(action.channel);
|
||||
ChannelStore._storeChannelMember(action.member);
|
||||
var currentId = ChannelStore.getCurrentId();
|
||||
if (currentId) ChannelStore.resetCounts(currentId);
|
||||
ChannelStore.emitChange();
|
||||
break;
|
||||
|
||||
case ActionTypes.RECIEVED_MORE_CHANNELS:
|
||||
ChannelStore._storeMoreChannels(action.channels);
|
||||
ChannelStore.emitMoreChange();
|
||||
@@ -218,4 +253,4 @@ ChannelStore.dispatchToken = AppDispatcher.register(function(payload) {
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ChannelStore;
|
||||
module.exports = ChannelStore;
|
||||
|
||||
Ссылка в новой задаче
Block a user