Fixing new messages indicator (#4531)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
29efeff095
Коммит
ced5f54500
@@ -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,
|
||||
|
||||
Ссылка в новой задаче
Block a user