Fetch posts when receive push notifications as soon as possible (#1811)

This commit is contained in:
Elias Nahum 2018-06-27 12:08:00 -04:00 committed by GitHub
parent dcb0def8ca
commit dbb6f16e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 19 deletions

View file

@ -6,7 +6,6 @@ import {Client4} from 'mattermost-redux/client';
import {General} from 'mattermost-redux/constants';
import {fetchMyChannelsAndMembers, markChannelAsRead} from 'mattermost-redux/actions/channels';
import {getClientConfig, getDataRetentionPolicy, getLicenseConfig} from 'mattermost-redux/actions/general';
import {getPosts} from 'mattermost-redux/actions/posts';
import {getMyTeams, getMyTeamMembers, selectTeam} from 'mattermost-redux/actions/teams';
import {ViewTypes} from 'app/constants';
@ -15,7 +14,6 @@ import {recordTime} from 'app/utils/segment';
import {
handleSelectChannel,
setChannelDisplayName,
retryGetPostsAction,
} from 'app/actions/views/channel';
export function startDataCleanup() {
@ -83,12 +81,10 @@ export function loadFromPushNotification(notification) {
dispatch(selectTeam({id: teamId}));
}
// when the notification is from the same channel as the current channel
// we should get the posts
if (channelId === currentChannelId) {
dispatch(markChannelAsRead(channelId, null, false));
await retryGetPostsAction(getPosts(channelId), dispatch, getState);
} else {
// mark channel as read
dispatch(markChannelAsRead(channelId, channelId === currentChannelId ? null : currentChannelId, false));
if (channelId !== currentChannelId) {
// when the notification is from a channel other than the current channel
dispatch(markChannelAsRead(channelId, currentChannelId, false));
dispatch(setChannelDisplayName(''));

View file

@ -9,10 +9,12 @@ import {Client4} from 'mattermost-redux/client';
import {markChannelAsRead} from 'mattermost-redux/actions/channels';
import {setDeviceToken} from 'mattermost-redux/actions/general';
import {getPosts} from 'mattermost-redux/actions/posts';
import {General} from 'mattermost-redux/constants';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {ViewTypes} from 'app/constants';
import {retryGetPostsAction} from 'app/actions/views/channel';
import {
createPost,
loadFromPushNotification,
@ -66,15 +68,20 @@ const onPushNotification = async (deviceNotification) => {
if (data.type === 'clear') {
dispatch(markChannelAsRead(data.channel_id, null, false));
} else if (foreground) {
EventEmitter.emit(ViewTypes.NOTIFICATION_IN_APP, notification);
} else if (userInteraction && !notification.localNotification) {
EventEmitter.emit('close_channel_drawer');
if (getState().views.root.hydrationComplete) {
await dispatch(loadFromPushNotification(notification));
if (!app.startAppFromPushNotification) {
EventEmitter.emit(ViewTypes.NOTIFICATION_TAPPED);
PushNotifications.resetNotification();
} else {
// get the posts for the channel as soon as possible
retryGetPostsAction(getPosts(data.channel_id), dispatch, getState);
if (foreground) {
EventEmitter.emit(ViewTypes.NOTIFICATION_IN_APP, notification);
} else if (userInteraction && !notification.localNotification) {
EventEmitter.emit('close_channel_drawer');
if (getState().views.root.hydrationComplete) {
await dispatch(loadFromPushNotification(notification));
if (!app.startAppFromPushNotification) {
EventEmitter.emit(ViewTypes.NOTIFICATION_TAPPED);
PushNotifications.resetNotification();
}
}
}
}
@ -112,8 +119,9 @@ export const onPushNotificationReply = (data, text, badge, completed) => {
Client4.setToken(token);
}
createPost(post)(dispatch, getState).then(() => {
markChannelAsRead(data.channel_id)(dispatch, getState);
dispatch(retryGetPostsAction(getPosts(data.channel_id)));
dispatch(createPost(post)).then(() => {
dispatch(markChannelAsRead(data.channel_id));
if (badge >= 0) {
PushNotifications.setApplicationIconBadgeNumber(badge);