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.
This commit is contained in:
parent
430fb350c1
commit
42563ebc35
26 changed files with 619 additions and 375 deletions
|
@ -3,23 +3,6 @@ const qs = require('qs');
|
|||
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
const editNoticeHTML = (client, roomId, event, html, plain) => client.sendMessage(roomId, {
|
||||
body: ` * ${plain || html.replace(/<[^<]+?>/g, '')}`,
|
||||
formatted_body: ` * ${html}`,
|
||||
format: 'org.matrix.custom.html',
|
||||
msgtype: 'm.notice',
|
||||
'm.new_content': {
|
||||
body: plain || html.replace(/<[^<]+?>/g, ''),
|
||||
formatted_body: html,
|
||||
format: 'org.matrix.custom.html',
|
||||
msgtype: 'm.notice'
|
||||
},
|
||||
'm.relates_to': {
|
||||
rel_type: 'm.replace',
|
||||
event_id: event.event_id
|
||||
}
|
||||
});
|
||||
|
||||
const headers = ({ domain, userAgent }) => ({
|
||||
'Host': `${domain}`,
|
||||
'User-Agent': `${userAgent}`
|
||||
|
@ -49,7 +32,7 @@ const arc1Str = str => `<em>Archiving page <code>${str}</code></em>`;
|
|||
const arc2Str = (str, title, date) => `<em>Archived page <code><a href="https://${str}">${str}</code> [${date}]</em><br /><b>${title}</b>`;
|
||||
const arc3Str = str => `<em>Timed out <code>${str}</code></em>`;
|
||||
|
||||
const run = async (matrixClient, { roomId }, userInput, rearchive) => {
|
||||
const run = async (roomId, userInput, rearchive) => {
|
||||
const instance = axios.create({
|
||||
baseURL: `https://${config.archive.domain}`,
|
||||
headers: headers(config.archive),
|
||||
|
@ -62,29 +45,29 @@ const run = async (matrixClient, { roomId }, userInput, rearchive) => {
|
|||
reply = await matrixClient.sendHtmlNotice(roomId, '', reqStr(userInput));
|
||||
const { refresh, id, title, date } = await archive(instance, userInput, rearchive);
|
||||
if (id)
|
||||
return await editNoticeHTML(matrixClient, roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
||||
return await matrix.utils.editNoticeHTML(roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
||||
if (refresh) {
|
||||
const path = refresh.split(`https://${config.archive.domain}`);
|
||||
if (!path[1]) throw refresh;
|
||||
await editNoticeHTML(matrixClient, roomId, reply, arc1Str(refresh));
|
||||
await matrix.utils.editNoticeHTML(roomId, reply, arc1Str(refresh));
|
||||
let tries = 30;
|
||||
while (tries--) {
|
||||
await sleep(10000);
|
||||
const { title, date, id } = await archive(instance, userInput);
|
||||
if (rearchive == false && title !== undefined)
|
||||
return await editNoticeHTML(matrixClient, roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
||||
return await matrix.utils.editNoticeHTML(roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
||||
const { request: { path: reqPath }, headers: { 'memento-datetime': rearchiveDate } } = await instance({ method: 'HEAD', url: path[1] })
|
||||
.catch(e => ({ request: { path: path[1] } }));
|
||||
if (rearchive == true && reqPath !== path[1])
|
||||
return await editNoticeHTML(matrixClient, roomId, reply, arc2Str(`${config.archive.domain}${reqPath}`, title, rearchiveDate));
|
||||
return await matrix.utils.editNoticeHTML(roomId, reply, arc2Str(`${config.archive.domain}${reqPath}`, title, rearchiveDate));
|
||||
}
|
||||
return await editNoticeHTML(matrixClient, roomId, reply, arc3Str(refresh));
|
||||
return await matrix.utils.editNoticeHTML(roomId, reply, arc3Str(refresh));
|
||||
}
|
||||
throw 'sad';
|
||||
} catch (e) {
|
||||
const sad = `<strong>Sad!</strong><br /><code>${`${e}`.replace(/<[^<]+?>/g, '').substr(0, 100)}</code>`;
|
||||
if (reply)
|
||||
editNoticeHTML(matrixClient, roomId, reply, sad, 'sad').catch(() => {});
|
||||
matrix.utils.editNoticeHTML(roomId, reply, sad, 'sad').catch(() => {});
|
||||
else
|
||||
matrixClient.sendHtmlNotice(roomId, 'sad', sad).catch(() => {});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue