ligh7hau5/commands/fediverse/flood.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

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',
url: `${config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
})
.then((res) => {
let past = JSON.parse(localStorage.getItem('timeline'));
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) {
const lastStored = past.slice(past.length - 1, past.length);
if (events[i].created_at < lastStored[0].created_at) return;
events[i].label = 'status';
fediverse.utils.formatter(events[i], roomId);
}
2019-07-04 00:27:39 +03:00
}
localStorage.setItem('timeline', JSON.stringify(events, null, 2));
})
.catch((e) => {
matrix.utils.sendError(null, roomId, e);
});
}, 30000);
2019-07-04 00:27:39 +03:00
};