mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-23 15:14:49 +01:00
Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1 c9887cb1 Fix team template git-subtree-dir: CTFd/themes/core-beta git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
This commit is contained in:
33
assets/js/notifications.js
Normal file
33
assets/js/notifications.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import Alpine from "alpinejs";
|
||||
import CTFd from "./index";
|
||||
|
||||
window.CTFd = CTFd;
|
||||
window.Alpine = Alpine;
|
||||
|
||||
// Get unread notifications from server
|
||||
let lastId = CTFd.events.counter.read.getLast();
|
||||
CTFd.fetch(`/api/v1/notifications?since_id=${lastId}`)
|
||||
.then(response => {
|
||||
return response.json();
|
||||
})
|
||||
.then(response => {
|
||||
// Get notifications from server and mark them as read
|
||||
let notifications = response.data;
|
||||
let read = CTFd.events.counter.read.getAll();
|
||||
notifications.forEach(n => {
|
||||
read.push(n.id);
|
||||
});
|
||||
CTFd.events.counter.read.setAll(read);
|
||||
|
||||
// Mark all unread as read
|
||||
CTFd.events.counter.unread.readAll();
|
||||
|
||||
// Broadcast our new count (which should be 0)
|
||||
let count = CTFd.events.counter.unread.getAll().length;
|
||||
CTFd.events.controller.broadcast("counter", {
|
||||
count: count,
|
||||
});
|
||||
Alpine.store("unread_count", count);
|
||||
});
|
||||
|
||||
Alpine.start();
|
||||
Reference in New Issue
Block a user