2021-02-14 10:57:35 +03:00
|
|
|
exports.runQuery = function (roomId) {
|
2019-07-04 00:27:39 +03:00
|
|
|
setInterval(() => {
|
|
|
|
axios({
|
|
|
|
method: 'GET',
|
2021-02-01 11:58:59 +03:00
|
|
|
url: `${config.fediverse.domain}/api/v1/notifications`,
|
2021-02-14 10:57:35 +03:00
|
|
|
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
let past = JSON.parse(localStorage.getItem('notifications'));
|
|
|
|
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) {
|
|
|
|
if (events[i].created_at < past.slice(18, 19)[0].created_at) return;
|
|
|
|
events[i].label = 'notifications';
|
|
|
|
fediverse.utils.formatter(events[i], roomId);
|
|
|
|
}
|
2019-07-04 00:27:39 +03:00
|
|
|
}
|
2021-02-14 10:57:35 +03:00
|
|
|
localStorage.setItem('notifications', JSON.stringify(events, null, 2));
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
matrix.utils.sendError(null, roomId, e);
|
|
|
|
});
|
|
|
|
}, 30000);
|
2019-07-04 00:27:39 +03:00
|
|
|
};
|