feat(MSC3440): implement threads for feed and notifications.
fix(sendHtmlNotice): possibly MSC1767 related.
This commit is contained in:
parent
3122361c6c
commit
5924009154
8 changed files with 56 additions and 10 deletions
|
@ -44,7 +44,7 @@ const run = async (roomId, userInput, rearchive) => {
|
||||||
|
|
||||||
let reply = null;
|
let reply = null;
|
||||||
try {
|
try {
|
||||||
reply = await matrixClient.sendHtmlNotice(roomId, '', reqStr(userInput));
|
reply = await matrixClient.sendHtmlNotice(roomId, ' ', reqStr(userInput));
|
||||||
const { refresh, id, title, date } = await archive(instance, userInput, rearchive);
|
const { refresh, id, title, date } = await archive(instance, userInput, rearchive);
|
||||||
if (id)
|
if (id)
|
||||||
return await matrix.utils.editNoticeHTML(roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
return await matrix.utils.editNoticeHTML(roomId, reply, arc2Str(`${config.archive.domain}${id}`, title, date));
|
||||||
|
|
26
commands/fediverse/unroll.js
Normal file
26
commands/fediverse/unroll.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
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 = [];
|
||||||
|
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();
|
||||||
|
await fediverse.utils.thread(roomId, event, '<br><hr><h3>...Beginning thread...</h3><hr><br>');
|
||||||
|
for (const [i, entry] of book.entries()) {
|
||||||
|
entry.label = 'thread';
|
||||||
|
fediverse.utils.formatter(entry, roomId, event)
|
||||||
|
}
|
||||||
|
await fediverse.utils.thread(roomId, event, '<br><hr><h3>...Thread ended...</h3><hr><br>');
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
matrix.utils.addReact(event, '❌');
|
||||||
|
matrix.utils.sendError(event, roomId, e);
|
||||||
|
});
|
||||||
|
};
|
|
@ -8,6 +8,20 @@ const sendEventWithMeta = async (roomId, content, meta) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const thread = async (roomId, event, content, meta) => {
|
||||||
|
await matrixClient.sendEvent(roomId, 'm.room.message', {
|
||||||
|
body: content.replace(/<[^<]+?>/g, ''),
|
||||||
|
msgtype: 'm.notice',
|
||||||
|
formatted_body: content,
|
||||||
|
meta: meta,
|
||||||
|
format: 'org.matrix.custom.html',
|
||||||
|
'm.relates_to': {
|
||||||
|
rel_type: 'm.thread',
|
||||||
|
event_id: event['event']['content']['m.relates_to']['event_id'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
const hasAttachment = (res) => {
|
const hasAttachment = (res) => {
|
||||||
if (res.status) res = res.status;
|
if (res.status) res = res.status;
|
||||||
if (!res.media_attachments) return '<br>';
|
if (!res.media_attachments) return '<br>';
|
||||||
|
@ -69,7 +83,7 @@ const notifyFormatter = (res, roomId) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isOriginal = (res, roomId) => {
|
const isOriginal = (res, roomId, event) => {
|
||||||
if (res.data) res = res.data;
|
if (res.data) res = res.data;
|
||||||
userDetails = `<b><a href="${config.fediverse.domain}/notice/${res.id}">
|
userDetails = `<b><a href="${config.fediverse.domain}/notice/${res.id}">
|
||||||
${res.account.acct}</a>`;
|
${res.account.acct}</a>`;
|
||||||
|
@ -80,7 +94,8 @@ const isOriginal = (res, roomId) => {
|
||||||
${hasAttachment(res)}
|
${hasAttachment(res)}
|
||||||
<br>(id: ${res.id}) ${registrar.post.visibilityEmoji(res.visibility)}
|
<br>(id: ${res.id}) ${registrar.post.visibilityEmoji(res.visibility)}
|
||||||
</blockquote>`;
|
</blockquote>`;
|
||||||
sendEventWithMeta(roomId, content, meta);
|
if (res.label == 'thread') thread(roomId, event, content, meta);
|
||||||
|
else sendEventWithMeta(roomId, content, meta);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isReblog = (res, roomId) => {
|
const isReblog = (res, roomId) => {
|
||||||
|
@ -101,11 +116,13 @@ const isReblog = (res, roomId) => {
|
||||||
|
|
||||||
module.exports.sendEventWithMeta = sendEventWithMeta;
|
module.exports.sendEventWithMeta = sendEventWithMeta;
|
||||||
|
|
||||||
module.exports.formatter = (res, roomId) => {
|
module.exports.thread = thread;
|
||||||
|
|
||||||
|
module.exports.formatter = (res, roomId, event) => {
|
||||||
const filtered = (res.label === 'notifications')
|
const filtered = (res.label === 'notifications')
|
||||||
? notifyFormatter(res, roomId)
|
? notifyFormatter(res, roomId)
|
||||||
: (res.reblog == null)
|
: (res.reblog == null)
|
||||||
? isOriginal(res, roomId)
|
? isOriginal(res, roomId, event)
|
||||||
: isReblog(res, roomId);
|
: isReblog(res, roomId);
|
||||||
return filtered;
|
return filtered;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
exports.runQuery = function (roomId) {
|
exports.runQuery = function (roomId) {
|
||||||
matrixClient.sendHtmlNotice(roomId,
|
matrixClient.sendHtmlNotice(roomId,
|
||||||
'',
|
' ',
|
||||||
'<blockquote><b>fediverse commands<br>'
|
'<blockquote><b>fediverse commands<br>'
|
||||||
+ '+post [your message] : post<br>'
|
+ '+post [your message] : post<br>'
|
||||||
+ '+redact [post id] : delete post<br>'
|
+ '+redact [post id] : delete post<br>'
|
||||||
|
|
|
@ -40,7 +40,7 @@ const getInstance = (domain, config) =>
|
||||||
const run = async (roomId, userInput) => {
|
const run = async (roomId, userInput) => {
|
||||||
const cfg = config.invidious;
|
const cfg = config.invidious;
|
||||||
const video = await matrix.utils.retryPromise(cfg.domains.redirect, domain => invidious(getInstance(domain, cfg), userInput));
|
const video = await matrix.utils.retryPromise(cfg.domains.redirect, domain => invidious(getInstance(domain, cfg), userInput));
|
||||||
return matrixClient.sendHtmlNotice(roomId, '', card(video, userInput));
|
return matrixClient.sendHtmlNotice(roomId, ' ', card(video, userInput));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.runQuery = async (roomId, event, userInput) => {
|
exports.runQuery = async (roomId, event, userInput) => {
|
||||||
|
|
|
@ -66,7 +66,7 @@ const getInstance = (domain, config) =>
|
||||||
const run = async (roomId, userInput) => {
|
const run = async (roomId, userInput) => {
|
||||||
const cfg = config.nitter;
|
const cfg = config.nitter;
|
||||||
const tweet = await matrix.utils.retryPromise(cfg.domains.redirect, domain => nitter(getInstance(domain, cfg), userInput));
|
const tweet = await matrix.utils.retryPromise(cfg.domains.redirect, domain => nitter(getInstance(domain, cfg), userInput));
|
||||||
return matrixClient.sendHtmlNotice(roomId, '', card(tweet, cfg.check, userInput));
|
return matrixClient.sendHtmlNotice(roomId, ' ', card(tweet, cfg.check, userInput));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.runQuery = async (roomId, event, userInput) => {
|
exports.runQuery = async (roomId, event, userInput) => {
|
||||||
|
|
|
@ -47,5 +47,6 @@ module.exports = {
|
||||||
tip: require('./commands/fediverse/tip.js'),
|
tip: require('./commands/fediverse/tip.js'),
|
||||||
unfollow: require('./commands/fediverse/unfollow.js'),
|
unfollow: require('./commands/fediverse/unfollow.js'),
|
||||||
unpin: require('./commands/fediverse/unpin.js'),
|
unpin: require('./commands/fediverse/unpin.js'),
|
||||||
unreblog: require('./commands/fediverse/unreblog.js')
|
unreblog: require('./commands/fediverse/unreblog.js'),
|
||||||
|
unroll: require('./commands/fediverse/unroll.js')
|
||||||
};
|
};
|
||||||
|
|
4
utils.js
4
utils.js
|
@ -5,7 +5,7 @@ const sendError = async (event, roomId, e) => {
|
||||||
: e.data ? error = `Error(${e.errcode}): ${e.data.error}`
|
: e.data ? error = `Error(${e.errcode}): ${e.data.error}`
|
||||||
: error = `Error: ${e.syscall}, ${e.code}`;
|
: error = `Error: ${e.syscall}, ${e.code}`;
|
||||||
return matrixClient.sendHtmlNotice(roomId,
|
return matrixClient.sendHtmlNotice(roomId,
|
||||||
'', error);
|
' ', error);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addReact = async (event, key) => {
|
const addReact = async (event, key) => {
|
||||||
|
@ -124,6 +124,7 @@ module.exports.handleReact = async (event) => {
|
||||||
if (reaction.key === '👏') command = 'clap';
|
if (reaction.key === '👏') command = 'clap';
|
||||||
if (reaction.key === '🗑️️') command = 'redact';
|
if (reaction.key === '🗑️️') command = 'redact';
|
||||||
if (reaction.key === '🌧️') command = 'makeitrain';
|
if (reaction.key === '🌧️') command = 'makeitrain';
|
||||||
|
if (reaction.key === '➕') command = 'unroll';
|
||||||
eventHandler(args, roomId, command, event);
|
eventHandler(args, roomId, command, event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,6 +151,7 @@ module.exports.selfReact = async (event) => {
|
||||||
const type = meta.split(' ')[0];
|
const type = meta.split(' ')[0];
|
||||||
if (type === 'redact' || type === 'unreblog') addReact(event, '🗑️️');
|
if (type === 'redact' || type === 'unreblog') addReact(event, '🗑️️');
|
||||||
if (type === 'status' || type === 'reblog' || type === 'mention') {
|
if (type === 'status' || type === 'reblog' || type === 'mention') {
|
||||||
|
addReact(event, '➕');
|
||||||
addReact(event, '🔁');
|
addReact(event, '🔁');
|
||||||
addReact(event, '👏');
|
addReact(event, '👏');
|
||||||
if (config.fediverse.tipping === true) addReact(event, '🌧️');
|
if (config.fediverse.tipping === true) addReact(event, '🌧️');
|
||||||
|
|
Loading…
Reference in a new issue