2021-02-01 11:58:59 +03:00
|
|
|
exports.runQuery = function (matrixClient, room) {
|
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`,
|
|
|
|
headers: { Authorization: `Bearer ${fediverse_auth.access_token}` },
|
|
|
|
}).then((events) => {
|
|
|
|
let lastEvent = JSON.parse(localStorage.getItem('notifications'));
|
|
|
|
localStorage.setItem('notifications', JSON.stringify(events.data[0].created_at, null, 2));
|
|
|
|
if (lastEvent !== events.data[0].created_at) {
|
|
|
|
if (events.data[0].type === 'follow') {
|
2019-07-04 00:27:39 +03:00
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2021-02-01 11:58:59 +03:00
|
|
|
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
|
|
|
|
${events.data[0].account.acct}</a></b>
|
2019-07-04 00:27:39 +03:00
|
|
|
<font color="#03b381"><b>has followed you.</b></font>
|
2021-02-01 11:58:59 +03:00
|
|
|
<br><i>${events.data[0].account.note}</i>`);
|
|
|
|
} else if (events.data[0].type === 'favourite') {
|
2019-07-04 00:27:39 +03:00
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2021-02-01 11:58:59 +03:00
|
|
|
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
|
|
|
|
${events.data[0].account.acct}</a></b>
|
|
|
|
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">favorited</a>
|
2019-07-04 00:27:39 +03:00
|
|
|
your post:</b></font>
|
2021-02-01 11:58:59 +03:00
|
|
|
<br><blockquote><i><b>${events.data[0].status.content}</i></b></blockquote>`);
|
|
|
|
} else if (events.data[0].type === 'mention') {
|
2019-07-04 00:27:39 +03:00
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2021-02-01 11:58:59 +03:00
|
|
|
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
|
|
|
|
${events.data[0].account.acct}</a></b>
|
|
|
|
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">mentioned</a>
|
|
|
|
you:</b></font><br><blockquote><i><b>${events.data[0].status.content}
|
|
|
|
<br>(id: ${events.data[0].status.id}) ${registrar.media.visibilityEmoji(events.data[0].status.visibility)}</i></b>
|
2020-05-16 20:50:16 +03:00
|
|
|
</blockquote>`);
|
2021-02-01 11:58:59 +03:00
|
|
|
} else if (events.data[0].type === 'reblog') {
|
2019-07-04 00:27:39 +03:00
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2021-02-01 11:58:59 +03:00
|
|
|
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
|
|
|
|
${events.data[0].account.acct}</a></b>
|
|
|
|
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">repeated</a>
|
2019-07-04 00:27:39 +03:00
|
|
|
your post:</b></font><br>
|
2021-02-01 11:58:59 +03:00
|
|
|
<blockquote><i><b>${events.data[0].status.content}</i></b></blockquote>`);
|
2019-07-04 00:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 8000);
|
|
|
|
};
|