Skip to content

Commit

Permalink
Load channel members with channels to make sure we have latest unread…
Browse files Browse the repository at this point in the history
… counts
  • Loading branch information
jwilander committed Oct 31, 2016
1 parent 3f30aa5 commit 62ee5d7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
5 changes: 5 additions & 0 deletions webapp/actions/channel_actions.jsx
Expand Up @@ -186,3 +186,8 @@ export function unmarkFavorite(channelId) {

AsyncClient.deletePreferences([pref]);
}

export function loadChannelsForCurrentUser() {
AsyncClient.getChannels();
AsyncClient.getMyChannelMembers();
}
7 changes: 4 additions & 3 deletions webapp/actions/global_actions.jsx
Expand Up @@ -14,6 +14,7 @@ import SearchStore from 'stores/search_store.jsx';

import {handleNewPost, loadPosts, loadPostsBefore, loadPostsAfter} from 'actions/post_actions.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';

import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
Expand Down Expand Up @@ -42,7 +43,7 @@ export function emitChannelClickEvent(channel) {
);
}
function switchToChannel(chan) {
AsyncClient.getChannelStats(chan.id);
AsyncClient.getChannelStats(chan.id, true);
AsyncClient.updateLastViewedAt(chan.id);
loadPosts(chan.id);
trackPage();
Expand Down Expand Up @@ -140,15 +141,15 @@ export function doFocusPost(channelId, postId, data) {
channelId,
post_list: data
});
AsyncClient.getChannels(true);
loadChannelsForCurrentUser();
AsyncClient.getMoreChannels(true);
AsyncClient.getChannelStats(channelId);
loadPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS, true);
loadPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS, true);
}

export function emitPostFocusEvent(postId, onSuccess) {
AsyncClient.getChannels(true);
loadChannelsForCurrentUser();
Client.getPermalinkTmp(
postId,
(data) => {
Expand Down
8 changes: 4 additions & 4 deletions webapp/actions/websocket_actions.jsx
Expand Up @@ -20,6 +20,7 @@ import * as AsyncClient from 'utils/async_client.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {handleNewPost, loadPosts} from 'actions/post_actions.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';
import * as StatusActions from 'actions/status_actions.jsx';

import {Constants, SocketEvents, UserStatuses} from 'utils/constants.jsx';
Expand Down Expand Up @@ -75,8 +76,7 @@ function handleFirstConnect() {

function handleReconnect() {
if (Client.teamId) {
AsyncClient.getChannels();
AsyncClient.getMyChannelMembers();
loadChannelsForCurrentUser();
loadPosts(ChannelStore.getCurrentId());
}

Expand Down Expand Up @@ -234,7 +234,7 @@ function handleUserAddedEvent(msg) {

function handleUserRemovedEvent(msg) {
if (UserStore.getCurrentId() === msg.broadcast.user_id) {
AsyncClient.getChannels();
loadChannelsForCurrentUser();

if (msg.data.remover_id !== msg.broadcast.user_id &&
msg.data.channel_id === ChannelStore.getCurrentId() &&
Expand Down Expand Up @@ -273,7 +273,7 @@ function handleChannelDeletedEvent(msg) {
const teamUrl = TeamStore.getCurrentTeamRelativeUrl();
browserHistory.push(teamUrl + '/channels/' + Constants.DEFAULT_CHANNEL);
}
AsyncClient.getChannels();
loadChannelsForCurrentUser();
}

function handlePreferenceChangedEvent(msg) {
Expand Down
4 changes: 3 additions & 1 deletion webapp/components/delete_channel_modal.jsx
Expand Up @@ -13,6 +13,8 @@ import {browserHistory} from 'react-router/es6';

import React from 'react';

import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';

export default class DeleteChannelModal extends React.Component {
constructor(props) {
super(props);
Expand All @@ -29,7 +31,7 @@ export default class DeleteChannelModal extends React.Component {
Client.deleteChannel(
this.props.channel.id,
() => {
AsyncClient.getChannels(true);
loadChannelsForCurrentUser();
},
(err) => {
AsyncClient.dispatchError(err, 'handleDelete');
Expand Down
3 changes: 2 additions & 1 deletion webapp/components/navbar.jsx
Expand Up @@ -112,7 +112,8 @@ export default class Navbar extends React.Component {

Client.leaveChannel(channelId,
() => {
AsyncClient.getChannels(true);
ChannelActions.loadChannelsForCurrentUser();

if (this.state.isFavorite) {
ChannelActions.unmarkFavorite(channelId);
}
Expand Down
1 change: 1 addition & 0 deletions webapp/stores/channel_store.jsx
Expand Up @@ -400,6 +400,7 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
ChannelStore.resetCounts(currentId);
}
ChannelStore.setUnreadCountsByMembers(action.members);
ChannelStore.emitChange();
break;
case ActionTypes.RECEIVED_MORE_CHANNELS:
ChannelStore.storeMoreChannels(action.channels);
Expand Down
18 changes: 7 additions & 11 deletions webapp/utils/async_client.jsx
Expand Up @@ -63,7 +63,7 @@ export function checkVersion() {
}
}

export function getChannels(doVersionCheck) {
export function getChannels() {
if (isCallInProgress('getChannels')) {
return null;
}
Expand All @@ -74,10 +74,6 @@ export function getChannels(doVersionCheck) {
(data) => {
callTracker.getChannels = 0;

if (doVersionCheck) {
checkVersion();
}

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNELS,
channels: data
Expand Down Expand Up @@ -114,7 +110,7 @@ export function getChannel(id) {
);
}

export function getMyChannelMembers(doVersionCheck) {
export function getMyChannelMembers() {
if (isCallInProgress('getMyChannelMembers')) {
return;
}
Expand All @@ -125,10 +121,6 @@ export function getMyChannelMembers(doVersionCheck) {
(data) => {
callTracker.getMyChannelMembers = 0;

if (doVersionCheck) {
checkVersion();
}

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
members: data
Expand Down Expand Up @@ -242,7 +234,7 @@ export function getMoreChannels(force) {
}
}

export function getChannelStats(channelId = ChannelStore.getCurrentId()) {
export function getChannelStats(channelId = ChannelStore.getCurrentId(), doVersionCheck = false) {
if (isCallInProgress('getChannelStats' + channelId)) {
return;
}
Expand All @@ -254,6 +246,10 @@ export function getChannelStats(channelId = ChannelStore.getCurrentId()) {
(data) => {
callTracker['getChannelStats' + channelId] = 0;

if (doVersionCheck) {
checkVersion();
}

AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL_STATS,
stats: data
Expand Down

0 comments on commit 62ee5d7

Please sign in to comment.