Этот коммит содержится в:
Christopher Speller
2016-11-11 14:55:05 -05:00
коммит произвёл Harrison Healey
родитель 29efeff095
Коммит ced5f54500
4 изменённых файлов: 80 добавлений и 50 удалений

Просмотреть файл

@@ -43,16 +43,20 @@ export function emitChannelClickEvent(channel) {
);
}
function switchToChannel(chan) {
AsyncClient.getChannelStats(chan.id, true);
AsyncClient.updateLastViewedAt(chan.id);
loadPosts(chan.id);
trackPage();
const getMyChannelMembersPromise = AsyncClient.getChannelMember(chan.id, UserStore.getCurrentId());
AppDispatcher.handleViewAction({
type: ActionTypes.CLICK_CHANNEL,
name: chan.name,
id: chan.id,
prev: ChannelStore.getCurrentId()
getMyChannelMembersPromise.then(() => {
AsyncClient.getChannelStats(chan.id, true);
AsyncClient.updateLastViewedAt(chan.id);
loadPosts(chan.id);
trackPage();
AppDispatcher.handleViewAction({
type: ActionTypes.CLICK_CHANNEL,
name: chan.name,
id: chan.id,
prev: ChannelStore.getCurrentId()
});
});
}

Просмотреть файл

@@ -263,6 +263,12 @@ class ChannelStoreClass extends EventEmitter {
});
}
setUnreadCountsByCurrentMembers() {
Object.keys(this.myChannelMembers).forEach((key) => {
this.setUnreadCountByChannel(this.myChannelMembers[key].channel_id);
});
}
setUnreadCountsByChannels(channels) {
channels.forEach((c) => {
this.setUnreadCountByChannel(c.id);
@@ -368,6 +374,15 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
ChannelStore.setUnreadCountsByMembers(action.members);
ChannelStore.emitChange();
break;
case ActionTypes.RECEIVED_CHANNEL_MEMBER:
ChannelStore.storeMyChannelMember(action.member);
currentId = ChannelStore.getCurrentId();
if (currentId && window.isActive) {
ChannelStore.resetCounts(currentId);
}
ChannelStore.setUnreadCountsByCurrentMembers();
ChannelStore.emitChange();
break;
case ActionTypes.RECEIVED_MORE_CHANNELS:
ChannelStore.storeMoreChannels(action.channels);
ChannelStore.emitChange();
@@ -385,4 +400,4 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
}
});
export default ChannelStore;
export default ChannelStore;

Просмотреть файл

@@ -111,26 +111,31 @@ export function getChannel(id) {
}
export function getMyChannelMembers() {
if (isCallInProgress('getMyChannelMembers')) {
return;
}
callTracker.getMyChannelMembers = utils.getTimestamp();
Client.getMyChannelMembers(
(data) => {
callTracker.getMyChannelMembers = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
members: data
});
},
(err) => {
callTracker.getChannelsUnread = 0;
dispatchError(err, 'getMyChannelMembers');
return new Promise((resolve, reject) => {
if (isCallInProgress('getMyChannelMembers')) {
resolve();
return;
}
);
callTracker.getMyChannelMembers = utils.getTimestamp();
Client.getMyChannelMembers(
(data) => {
callTracker.getMyChannelMembers = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
members: data
});
resolve();
},
(err) => {
callTracker.getChannelsUnread = 0;
dispatchError(err, 'getMyChannelMembers');
reject();
}
);
});
}
export function updateLastViewedAt(id, active) {
@@ -263,28 +268,33 @@ export function getChannelStats(channelId = ChannelStore.getCurrentId(), doVersi
}
export function getChannelMember(channelId, userId) {
if (isCallInProgress(`getChannelMember${channelId}${userId}`)) {
return;
}
callTracker[`getChannelMember${channelId}${userId}`] = utils.getTimestamp();
Client.getChannelMember(
channelId,
userId,
(data) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL_MEMBER,
member: data
});
},
(err) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
dispatchError(err, 'getChannelMember');
return new Promise((resolve, reject) => {
if (isCallInProgress(`getChannelMember${channelId}${userId}`)) {
resolve();
return;
}
);
callTracker[`getChannelMember${channelId}${userId}`] = utils.getTimestamp();
Client.getChannelMember(
channelId,
userId,
(data) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL_MEMBER,
member: data
});
resolve();
},
(err) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
dispatchError(err, 'getChannelMember');
reject();
}
);
});
}
export function getUser(userId) {

Просмотреть файл

@@ -70,6 +70,7 @@ export const ActionTypes = keyMirror({
RECEIVED_CHANNELS: null,
RECEIVED_CHANNEL: null,
RECEIVED_CHANNEL_MEMBER: null,
RECEIVED_MORE_CHANNELS: null,
RECEIVED_CHANNEL_STATS: null,
RECEIVED_MY_CHANNEL_MEMBERS: null,