2022-01-24 12:53:34 +03:00
|
|
|
let intervalId = null;
|
|
|
|
|
|
|
|
exports.runQuery = function (roomId, disable) {
|
|
|
|
|
|
|
|
if (intervalId) {
|
|
|
|
clearInterval(intervalId);
|
|
|
|
intervalId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disable) return;
|
|
|
|
|
|
|
|
intervalId = setInterval(() => {
|
2019-07-04 00:27:39 +03:00
|
|
|
axios({
|
|
|
|
method: 'GET',
|
2024-09-29 20:53:07 +03:00
|
|
|
url: `https://${fediverse.auth[event.getSender()].domain}/api/v1/notifications`,
|
|
|
|
headers: { Authorization: `Bearer ${fediverse.auth[event.getSender()].access_token}` },
|
2021-02-14 10:57:35 +03:00
|
|
|
})
|
|
|
|
.then((res) => {
|
2024-09-29 20:53:07 +03:00
|
|
|
let notifications = JSON.parse(localStorage.getItem('notifications'));
|
|
|
|
let past = notifications[event.getSender()] || {}
|
2021-02-14 10:57:35 +03:00
|
|
|
if (past.length === 0) past = res.data;
|
|
|
|
const events = res.data;
|
|
|
|
const len = events.length;
|
|
|
|
for (let i = len - 1; i >= 0; i--) {
|
|
|
|
if (past.findIndex((x) => x.created_at === events[i].created_at) === -1) {
|
2021-04-25 10:53:23 +03:00
|
|
|
const lastStored = past.slice(past.length - 1, past.length);
|
|
|
|
if (events[i].created_at < lastStored[0].created_at) return;
|
2021-02-14 10:57:35 +03:00
|
|
|
events[i].label = 'notifications';
|
|
|
|
fediverse.utils.formatter(events[i], roomId);
|
|
|
|
}
|
2019-07-04 00:27:39 +03:00
|
|
|
}
|
2024-09-29 20:53:07 +03:00
|
|
|
notifications[event.getSender()] = events
|
|
|
|
localStorage.setItem('notifications', JSON.stringify(notifications, null, 2));
|
2021-02-14 10:57:35 +03:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
matrix.utils.sendError(null, roomId, e);
|
|
|
|
});
|
|
|
|
}, 30000);
|
2019-07-04 00:27:39 +03:00
|
|
|
};
|