RN-185 ensure leaving channels and teams when the app is closed or disconnected (#617)

This commit is contained in:
enahum 2017-06-12 12:03:59 -04:00 committed by GitHub
parent bcbc2bbe5f
commit fa2218a835
4 changed files with 22 additions and 21 deletions

View file

@ -27,7 +27,6 @@ import {
isDirectChannel,
isGroupChannel
} from 'mattermost-redux/utils/channel_utils';
import {getLastUpdateAt} from 'mattermost-redux/utils/post_utils';
import {getPreferencesByCategory} from 'mattermost-redux/utils/preference_utils';
export function loadChannelsIfNecessary(teamId) {
@ -139,22 +138,17 @@ export function loadProfilesAndTeamMembersForDMSidebar(teamId) {
export function loadPostsIfNecessary(channel) {
return async (dispatch, getState) => {
const state = getState();
const {posts, postsInChannel} = state.entities.posts;
const {channelsLastFetch} = state.internal;
const lastFetchTime = channelsLastFetch[channel.id] || 0;
const {postsInChannel} = state.entities.posts;
const postsIds = postsInChannel[channel.id];
// Get the first page of posts if it appears we haven't gotten it yet, like the webapp
if (!postsIds || postsIds.length < Posts.POST_CHUNK_SIZE) {
if (!postsIds || postsIds.length < Posts.POST_CHUNK_SIZE || !lastFetchTime) {
return getPosts(channel.id)(dispatch, getState);
}
const postsForChannel = postsIds.map((id) => posts[id]);
const latestPostTime = getLastUpdateAt(postsForChannel);
if (latestPostTime) {
return getPostsSince(channel.id, latestPostTime)(dispatch, getState);
}
return null;
return getPostsSince(channel.id, lastFetchTime)(dispatch, getState);
};
}
@ -191,12 +185,14 @@ export function selectInitialChannel(teamId) {
const channel = Object.values(channels).find((c) => c.team_id === teamId && c.name === General.DEFAULT_CHANNEL);
if (channel) {
dispatch(setChannelDisplayName(''));
await handleSelectChannel(channel.id)(dispatch, getState);
} else {
// Handle case when the default channel cannot be found
// so we need to get the first available channel of the team
const channelsInTeam = Object.values(channels).filter((c) => c.team_id === teamId);
const firstChannel = channelsInTeam[0].id;
dispatch(setChannelDisplayName(''));
await handleSelectChannel(firstChannel.id)(dispatch, getState);
}
};

View file

@ -5,7 +5,8 @@ import {ViewTypes} from 'app/constants';
import {
handleSelectChannel,
loadChannelsIfNecessary,
loadProfilesAndTeamMembersForDMSidebar
loadProfilesAndTeamMembersForDMSidebar,
setChannelDisplayName
} from 'app/actions/views/channel';
import {handleTeamChange, selectFirstAvailableTeam} from 'app/actions/views/select_team';
@ -37,6 +38,7 @@ export function goToNotification(notification) {
const state = getState();
const {data} = notification;
const {currentTeamId, teams} = state.entities.teams;
const {currentChannelId} = state.entities.channels;
const channelId = data.channel_id;
// if the notification does not have a team id is because its from a DM or GM
@ -53,9 +55,10 @@ export function goToNotification(notification) {
viewChannel(channelId)(dispatch, getState);
loadProfilesAndTeamMembersForDMSidebar(teamId)(dispatch, getState);
// when the notification is tapped go to the channel view before selecting the channel to prevent
// weird behavior
handleSelectChannel(channelId)(dispatch, getState);
if (channelId !== currentChannelId) {
dispatch(setChannelDisplayName(''));
handleSelectChannel(channelId)(dispatch, getState);
}
markChannelAsRead(teamId, channelId)(dispatch, getState).then(() => true).catch(() => true);
};
}

View file

@ -30,12 +30,14 @@ export default class LoadTeam extends PureComponent {
if (notification) {
clearNotification();
goToNotification(notification);
this.goToChannelView();
} else if (currentTeam) {
this.onSelectTeam(currentTeam);
} else if (!currentTeam) {
this.selectFirstTeam(teams, myMembers);
return this.goToChannelView();
}
if (currentTeam && myMembers[currentTeam.id]) {
return this.onSelectTeam(currentTeam);
}
return this.selectFirstTeam(teams, myMembers);
}
componentWillReceiveProps(nextProps) {

View file

@ -3645,7 +3645,7 @@ makeerror@1.0.x:
mattermost-redux@mattermost/mattermost-redux#master:
version "0.0.1"
resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/488faa22c03e1c187c714a5db7f0a42b69d50ae8"
resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/909f75d50678998a1fcb9d3b35d1fae9e918147f"
dependencies:
deep-equal "1.0.1"
harmony-reflect "1.5.1"