|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
import { notificApi } from "@/api/notifications/request"; |
|
|
|
|
import config from "@/config"; |
|
|
|
|
import { RouteEnum } from "@/containers/App/router"; |
|
|
|
|
import { IPushNotification, NotificationKeys } from "@/shared"; |
|
|
|
|
import { SelectChatId } from "@/store/chats"; |
|
|
|
@ -7,7 +8,7 @@ import OneSignal from "react-onesignal";
@@ -7,7 +8,7 @@ import OneSignal from "react-onesignal";
|
|
|
|
|
|
|
|
|
|
export const needRedirect = { |
|
|
|
|
to: null, |
|
|
|
|
payload: null |
|
|
|
|
payload: null, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const saveNeedRedirect = ({ to, payload }) => { |
|
|
|
@ -26,9 +27,9 @@ export const notificationActions = (
@@ -26,9 +27,9 @@ export const notificationActions = (
|
|
|
|
|
); |
|
|
|
|
saveNeedRedirect({ |
|
|
|
|
to: `/chats?id=${notification.data.chatId}`, |
|
|
|
|
payload: null |
|
|
|
|
payload: null, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[NotificationKeys.NEW_CHAT_MEMBER]: { |
|
|
|
|
redirect: () => { |
|
|
|
@ -37,17 +38,17 @@ export const notificationActions = (
@@ -37,17 +38,17 @@ export const notificationActions = (
|
|
|
|
|
); |
|
|
|
|
saveNeedRedirect({ |
|
|
|
|
to: `/chats?id=${notification.data.chatId}`, |
|
|
|
|
payload: null |
|
|
|
|
payload: null, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[NotificationKeys.NEW_TASK]: { |
|
|
|
|
redirect: () => { |
|
|
|
|
saveNeedRedirect({ |
|
|
|
|
to: RouteEnum.Tasks, |
|
|
|
|
payload: null |
|
|
|
|
payload: null, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[NotificationKeys.NEW_TASK_COMMENT]: { |
|
|
|
|
redirect: () => { |
|
|
|
@ -55,10 +56,10 @@ export const notificationActions = (
@@ -55,10 +56,10 @@ export const notificationActions = (
|
|
|
|
|
to: RouteEnum.Tasks, |
|
|
|
|
payload: { |
|
|
|
|
type: NotificationKeys.NEW_TASK_COMMENT, |
|
|
|
|
taskId: notification.data.taskId |
|
|
|
|
} |
|
|
|
|
taskId: notification.data.taskId, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[NotificationKeys.NEW_TASK_FILE]: { |
|
|
|
|
redirect: () => { |
|
|
|
@ -66,22 +67,22 @@ export const notificationActions = (
@@ -66,22 +67,22 @@ export const notificationActions = (
|
|
|
|
|
to: RouteEnum.Tasks, |
|
|
|
|
payload: { |
|
|
|
|
type: NotificationKeys.NEW_TASK_FILE, |
|
|
|
|
taskId: notification.data.taskId |
|
|
|
|
} |
|
|
|
|
taskId: notification.data.taskId, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
[NotificationKeys.TODAY_BIRTHDAY]: { |
|
|
|
|
redirect: () => { |
|
|
|
|
saveNeedRedirect({ |
|
|
|
|
to: RouteEnum.Contacts, |
|
|
|
|
payload: { soonBirthday: true } |
|
|
|
|
payload: { soonBirthday: true }, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const onOpened = openResult => { |
|
|
|
|
const onOpened = (openResult) => { |
|
|
|
|
try { |
|
|
|
|
const notif: IPushNotification = { |
|
|
|
|
id: 0, |
|
|
|
@ -90,7 +91,7 @@ const onOpened = openResult => {
@@ -90,7 +91,7 @@ const onOpened = openResult => {
|
|
|
|
|
createDate: null, |
|
|
|
|
isRead: false, |
|
|
|
|
userId: null, |
|
|
|
|
data: openResult.data as any |
|
|
|
|
data: openResult.data as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const action = notificationActions(notif)[ |
|
|
|
@ -106,13 +107,15 @@ const onOpened = openResult => {
@@ -106,13 +107,15 @@ const onOpened = openResult => {
|
|
|
|
|
const runOneSignal = async () => { |
|
|
|
|
try { |
|
|
|
|
await OneSignal.init({ |
|
|
|
|
appId: "8b9066f5-8c3f-49f7-bef4-c5ab621f9d27", |
|
|
|
|
allowLocalhostAsSecureOrigin: false |
|
|
|
|
appId: config.oneSignalId, |
|
|
|
|
allowLocalhostAsSecureOrigin: false, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
console.log("one signal is inited"); |
|
|
|
|
const isPermitted = await OneSignal.getNotificationPermission(); |
|
|
|
|
console.log("is notifications permitted", isPermitted); |
|
|
|
|
if (isPermitted !== "granted") await OneSignal.showNativePrompt(); |
|
|
|
|
|
|
|
|
|
if (isPermitted !== "granted") await OneSignal.showSlidedownPrompt(); |
|
|
|
|
|
|
|
|
|
if (isPermitted) await OneSignal.setSubscription(true); |
|
|
|
|
|
|
|
|
@ -121,14 +124,14 @@ const runOneSignal = async () => {
@@ -121,14 +124,14 @@ const runOneSignal = async () => {
|
|
|
|
|
if (userId) |
|
|
|
|
await notificApi.saveUserDevice({ |
|
|
|
|
notificationUserId: userId, |
|
|
|
|
deviceUuid: userId |
|
|
|
|
deviceUuid: userId, |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log("ONE SIGNAL RUNNING ERROR", e); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
OneSignal.on("subscriptionChange", async isSubscribed => { |
|
|
|
|
OneSignal.on("subscriptionChange", async (isSubscribed) => { |
|
|
|
|
console.log("SUBSCRIPTION IS CHANGED", isSubscribed); |
|
|
|
|
await OneSignal.setSubscription(isSubscribed); |
|
|
|
|
}); |
|
|
|
@ -136,5 +139,5 @@ OneSignal.on("subscriptionChange", async isSubscribed => {
@@ -136,5 +139,5 @@ OneSignal.on("subscriptionChange", async isSubscribed => {
|
|
|
|
|
OneSignal.addListenerForNotificationOpened(onOpened); |
|
|
|
|
|
|
|
|
|
export const notificationsService = { |
|
|
|
|
runOneSignal |
|
|
|
|
runOneSignal, |
|
|
|
|
}; |
|
|
|
|