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']) {
|
||||
const accounts = await getAccounts();
|
||||
console.log(accounts);
|
||||
if (!accounts.some(x => x.id === id)) {
|
||||
return set('accounts', accounts.concat([{ id, token }]));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export async function readNotification(
|
|||
notificationIds: Notification['id'][]
|
||||
) {
|
||||
// Update documents
|
||||
await Notifications.update({
|
||||
const updatedNotificatons = await Notifications.update({
|
||||
id: In(notificationIds),
|
||||
isRead: false
|
||||
}, {
|
||||
|
@ -20,7 +20,13 @@ export async function readNotification(
|
|||
});
|
||||
|
||||
if (!await Users.getHasUnreadNotification(userId)) {
|
||||
// ユーザーのすべての通知が既読だったら、
|
||||
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
|
||||
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 { PackedMessagingMessage } from '../models/repositories/messaging-message';
|
||||
|
||||
type notificationType = 'notification' | 'unreadMessagingMessage';
|
||||
type notificationBody = PackedNotification | PackedMessagingMessage;
|
||||
type pushNotificationsTypes = {
|
||||
'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();
|
||||
|
||||
if (!meta.enableServiceWorker || meta.swPublicKey == null || meta.swPrivateKey == null) return;
|
||||
|
|
Loading…
Reference in a new issue