wip
This commit is contained in:
parent
6b11344b16
commit
3ce28b706a
|
@ -50,7 +50,6 @@ export async function getAccounts(): Promise<{ id: Account['id'], token: Account
|
||||||
|
|
||||||
export async function addAccount(id: Account['id'], token: Account['token']) {
|
export async function addAccount(id: Account['id'], token: Account['token']) {
|
||||||
const accounts = await getAccounts();
|
const accounts = await getAccounts();
|
||||||
console.log(accounts);
|
|
||||||
if (!accounts.some(x => x.id === id)) {
|
if (!accounts.some(x => x.id === id)) {
|
||||||
return set('accounts', accounts.concat([{ id, token }]));
|
return set('accounts', accounts.concat([{ id, token }]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export async function readNotification(
|
||||||
notificationIds: Notification['id'][]
|
notificationIds: Notification['id'][]
|
||||||
) {
|
) {
|
||||||
// Update documents
|
// Update documents
|
||||||
await Notifications.update({
|
const updatedNotificatons = await Notifications.update({
|
||||||
id: In(notificationIds),
|
id: In(notificationIds),
|
||||||
isRead: false
|
isRead: false
|
||||||
}, {
|
}, {
|
||||||
|
@ -20,7 +20,13 @@ export async function readNotification(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!await Users.getHasUnreadNotification(userId)) {
|
if (!await Users.getHasUnreadNotification(userId)) {
|
||||||
|
// ユーザーのすべての通知が既読だったら、
|
||||||
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
||||||
publishMainStream(userId, 'readAllNotifications');
|
publishMainStream(userId, 'readAllNotifications');
|
||||||
|
} else {
|
||||||
|
// まだすべて既読になっていなければ、
|
||||||
|
// アップデートしたという
|
||||||
|
const updatedNotificationsIds = updatedNotificatons.generatedMaps.map(e => e.id);
|
||||||
|
publishMainStream(userId, 'readNotifications', updatedNotificationsIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,14 @@ import { fetchMeta } from '../misc/fetch-meta';
|
||||||
import { PackedNotification } from '../models/repositories/notification';
|
import { PackedNotification } from '../models/repositories/notification';
|
||||||
import { PackedMessagingMessage } from '../models/repositories/messaging-message';
|
import { PackedMessagingMessage } from '../models/repositories/messaging-message';
|
||||||
|
|
||||||
type notificationType = 'notification' | 'unreadMessagingMessage';
|
type pushNotificationsTypes = {
|
||||||
type notificationBody = PackedNotification | PackedMessagingMessage;
|
'notification': PackedNotification;
|
||||||
|
'unreadMessagingMessage': PackedMessagingMessage;
|
||||||
|
'readNotifications': { notificationIds: string[] };
|
||||||
|
'readAllNotifications': undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export default async function(userId: string, type: notificationType, body: notificationBody) {
|
export default async function<T extends keyof pushNotificationsTypes>(userId: string, type: T, body: pushNotificationsTypes[T]) {
|
||||||
const meta = await fetchMeta();
|
const meta = await fetchMeta();
|
||||||
|
|
||||||
if (!meta.enableServiceWorker || meta.swPublicKey == null || meta.swPrivateKey == null) return;
|
if (!meta.enableServiceWorker || meta.swPublicKey == null || meta.swPrivateKey == null) return;
|
||||||
|
|
Loading…
Reference in a new issue