ligh7hau5/commands/fediverse/notify.js
vulet 42563ebc35 feat(matrix/fediverse): allow users to directly reply on Fediverse posts from Matrix, using <mx-reply> on our new meta field.
feat(matrix/fediverse): allow users to favorite, reblog, and redact Fediverse posts from Matrix, using m.reaction on our new meta field.
feat(fediverse): add suggestions for follow/unfollow commands.
refactor(matrix/fediverse): add meta field for commands by reaction, and commands by reply.
refactor(fediverse): relax polling on timeline/notifs thru new handling.
2021-02-14 15:57:35 +08:00

26 lines
971 B
JavaScript

exports.runQuery = function (roomId) {
setInterval(() => {
axios({
method: 'GET',
url: `${config.fediverse.domain}/api/v1/notifications`,
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);
}
}
localStorage.setItem('notifications', JSON.stringify(events, null, 2));
})
.catch((e) => {
matrix.utils.sendError(null, roomId, e);
});
}, 30000);
};