Fix notification replies for iOS (#1341)
* Fix notification replies for iOS * Review feedback * Review feedback 2
This commit is contained in:
parent
71df3ef8fa
commit
7860478d54
3 changed files with 25 additions and 20 deletions
|
|
@ -81,7 +81,7 @@ export function purgeOfflineStore() {
|
|||
}
|
||||
|
||||
export function createPost(post) {
|
||||
return async (dispatch, getState) => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const currentUserId = state.entities.users.currentUserId;
|
||||
|
||||
|
|
@ -95,8 +95,7 @@ export function createPost(post) {
|
|||
update_at: timestamp
|
||||
};
|
||||
|
||||
try {
|
||||
const payload = Client4.createPost({...newPost, create_at: 0});
|
||||
return Client4.createPost({...newPost, create_at: 0}).then((payload) => {
|
||||
dispatch({
|
||||
type: PostTypes.RECEIVED_POSTS,
|
||||
data: {
|
||||
|
|
@ -107,11 +106,7 @@ export function createPost(post) {
|
|||
},
|
||||
channelId: payload.channel_id
|
||||
});
|
||||
} catch (error) {
|
||||
return {error};
|
||||
}
|
||||
|
||||
return {data: true};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -401,11 +401,12 @@ export default class Mattermost {
|
|||
|
||||
const isNotActive = AppState.currentState !== 'active';
|
||||
const notification = PushNotifications.getNotification();
|
||||
if (notification) {
|
||||
if (notification || this.replyNotificationData) {
|
||||
// If we have a notification means that the app was started cause of a reply
|
||||
// and the app was not sitting in the background nor opened
|
||||
const {data, text, badge} = notification;
|
||||
this.onPushNotificationReply(data, text, badge);
|
||||
const notificationData = notification || this.replyNotificationData;
|
||||
const {data, text, badge, completed} = notificationData;
|
||||
this.onPushNotificationReply(data, text, badge, completed);
|
||||
PushNotifications.resetNotification();
|
||||
}
|
||||
|
||||
|
|
@ -521,17 +522,22 @@ export default class Mattermost {
|
|||
Client4.setToken(state.entities.general.credentials.token);
|
||||
}
|
||||
|
||||
createPost(post)(dispatch, getState);
|
||||
markChannelAsRead(data.channel_id)(dispatch, getState);
|
||||
createPost(post)(dispatch, getState).then(() => {
|
||||
markChannelAsRead(data.channel_id)(dispatch, getState);
|
||||
|
||||
if (badge >= 0) {
|
||||
PushNotifications.setApplicationIconBadgeNumber(badge);
|
||||
}
|
||||
}
|
||||
if (badge >= 0) {
|
||||
PushNotifications.setApplicationIconBadgeNumber(badge);
|
||||
}
|
||||
|
||||
if (completed) {
|
||||
// You must call to completed(), otherwise the action will not be triggered
|
||||
completed();
|
||||
this.replyNotificationData = null;
|
||||
}).then(completed);
|
||||
} else {
|
||||
this.replyNotificationData = {
|
||||
data,
|
||||
text,
|
||||
badge,
|
||||
completed
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,10 @@ class PushNotification {
|
|||
getNotification() {
|
||||
return null;
|
||||
}
|
||||
|
||||
resetNotification() {
|
||||
this.deviceNotification = null;
|
||||
}
|
||||
}
|
||||
|
||||
export default new PushNotification();
|
||||
|
|
|
|||
Loading…
Reference in a new issue