mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 06:10:22 +00:00
* feat: ensure djs clients are singleton instances * feat: add votes table * feat: vote notification * chore: reduce vote cooldown to 15 min * feat: add SetNotification to server * chore: add debug logs * fix: do not add notification when token and voteid already exists * feat: add loading indicator * feat: refresh notification when voted * feat: add opt-out * feat: add debug log * fix: initialize firebase app * fix: remove app on messaging * feat: show notifications only with service worker * fix: state improperly used * fix: schedule notification if notification is newly added * chore: remove duplicated notification * chore: add spacing * chore: get token if notification is granted * chore: change vote cooldown to 12 hours * chore: remove logging
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
/* eslint-disable no-undef */
|
|
|
|
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js')
|
|
importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js')
|
|
|
|
firebase.initializeApp({
|
|
apiKey: 'AIzaSyDWnwXCBaP1C627gfIBQxyZbmNnAU_b_1Q',
|
|
authDomain: 'koreanlist-e95d9.firebaseapp.com',
|
|
projectId: 'koreanlist-e95d9',
|
|
storageBucket: 'koreanlist-e95d9.firebasestorage.app',
|
|
messagingSenderId: '716438516411',
|
|
appId: '1:716438516411:web:cddd6c7cc3b0571fa4af9e',
|
|
})
|
|
|
|
const messaging = firebase.messaging()
|
|
|
|
/*
|
|
{
|
|
type: 'vote-available',
|
|
name: target.name,
|
|
imageUrl: image ?? undefined,
|
|
url: `/${isBot ? 'bots' : 'servers'}/${noti.target_id}`,
|
|
}
|
|
*/
|
|
|
|
messaging.onBackgroundMessage(function (payload) {
|
|
if (payload.data.type !== 'vote-available') return
|
|
const notificationTitle = '투표 알림'
|
|
const notificationOptions = {
|
|
body: `${payload.data.name}의 투표가 가능합니다.`,
|
|
icon: payload.data.imageUrl,
|
|
}
|
|
notificationOptions.data = payload.data
|
|
|
|
self.addEventListener('notificationclick', function (event) {
|
|
event.notification.close()
|
|
clients.openWindow(event.notification.data.url)
|
|
})
|
|
|
|
self.registration.showNotification(notificationTitle, notificationOptions)
|
|
})
|