2022-04-26 06:09:55 +03:00
|
|
|
exports.runQuery = function (roomId, event, userInput) {
|
|
|
|
const instance = axios.create({
|
|
|
|
baseURL: config.fediverse.domain,
|
|
|
|
method: 'GET',
|
|
|
|
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
|
|
|
});
|
|
|
|
instance.get(`/api/v1/statuses/${userInput}/context`)
|
|
|
|
.then(async (response) => {
|
|
|
|
let story = [];
|
2023-08-23 10:25:48 +03:00
|
|
|
const rel = event.getContent()['m.relates_to'];
|
|
|
|
const eventId = rel && rel.event_id ? rel.event_id : event.getId();
|
2022-04-26 06:09:55 +03:00
|
|
|
const original = await instance.get(`/api/v1/statuses/${userInput}`);
|
|
|
|
const ancestors = response.data.ancestors;
|
|
|
|
const descendants = response.data.descendants;
|
|
|
|
story = [...story, ancestors, original.data, descendants];
|
|
|
|
const book = story.flat();
|
2023-08-23 10:25:48 +03:00
|
|
|
await fediverse.utils.thread(roomId, eventId, '<br><hr><h3>...Beginning thread...</h3><hr><br>');
|
2022-04-26 06:09:55 +03:00
|
|
|
for (const [i, entry] of book.entries()) {
|
|
|
|
entry.label = 'thread';
|
2023-08-23 10:25:48 +03:00
|
|
|
fediverse.utils.formatter(entry, roomId, eventId);
|
2022-04-26 06:09:55 +03:00
|
|
|
}
|
2023-08-23 10:25:48 +03:00
|
|
|
await fediverse.utils.thread(roomId, eventId, '<br><hr><h3>...Thread ended...</h3><hr><br>');
|
2022-04-26 06:09:55 +03:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
matrix.utils.addReact(event, '❌');
|
|
|
|
matrix.utils.sendError(event, roomId, e);
|
|
|
|
});
|
|
|
|
};
|