feat(fediverse): automatically attach mentions to reply. refactor(mentions): clean-up.

This commit is contained in:
vulet 2021-02-26 12:21:41 +08:00
parent f37e2471c0
commit 1e8577f865
2 changed files with 9 additions and 9 deletions

View file

@ -47,6 +47,7 @@ const run = async (roomId, content, replyId, mediaURL, subject) => {
const media = await mediaDownload(mediaURL, config.fediverse.mimetypes);
mediaId = await mediaUpload(config.fediverse, media);
}
if (replyId) content = await fediverse.utils.getStatusMentions(replyId).then(m => m.concat(content));
const response = await axios({
method: 'POST',
url: `${config.fediverse.domain}/api/v1/statuses`,

View file

@ -142,20 +142,19 @@ module.exports.unfollow = (roomId, account, event, original) => {
});
};
module.exports.getStatusMentions = (notice, event, original) => {
const posters = [];
const prefix = '@';
module.exports.getStatusMentions = (notice, event) => {
const users = axios({
method: 'GET',
url: `${config.fediverse.domain}/api/v1/statuses/${notice}`,
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
}).then((notice) => {
const citizens = [];
citizens.push(notice.data.account.acct);
for (let i = 0; i < notice.data.mentions.length; i++) citizens.push(notice.data.mentions[i].acct);
const filtered = citizens.filter(users => !config.fediverse.username.includes(users))
for (let i = 0; i < filtered.length; i++) posters.push(prefix.concat(filtered[i]));
return posters;
const users = [];
users.push('@' + notice.data.account.acct);
for(let i = 0; i < notice.data.mentions.length; i++) {
if(!config.fediverse.username.includes(notice.data.mentions[i].acct))
users.push('@' + notice.data.mentions[i].acct)
}
return users;
})
.catch((e) => {
matrix.utils.addReact(event, '❌');