feat(fediverse): automatically attach mentions to reply. refactor(mentions): clean-up.
This commit is contained in:
parent
f37e2471c0
commit
1e8577f865
2 changed files with 9 additions and 9 deletions
|
@ -47,6 +47,7 @@ const run = async (roomId, content, replyId, mediaURL, subject) => {
|
||||||
const media = await mediaDownload(mediaURL, config.fediverse.mimetypes);
|
const media = await mediaDownload(mediaURL, config.fediverse.mimetypes);
|
||||||
mediaId = await mediaUpload(config.fediverse, media);
|
mediaId = await mediaUpload(config.fediverse, media);
|
||||||
}
|
}
|
||||||
|
if (replyId) content = await fediverse.utils.getStatusMentions(replyId).then(m => m.concat(content));
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||||
|
|
|
@ -142,20 +142,19 @@ module.exports.unfollow = (roomId, account, event, original) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getStatusMentions = (notice, event, original) => {
|
module.exports.getStatusMentions = (notice, event) => {
|
||||||
const posters = [];
|
|
||||||
const prefix = '@';
|
|
||||||
const users = axios({
|
const users = axios({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: `${config.fediverse.domain}/api/v1/statuses/${notice}`,
|
url: `${config.fediverse.domain}/api/v1/statuses/${notice}`,
|
||||||
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
headers: { Authorization: `Bearer ${fediverse.auth.access_token}` },
|
||||||
}).then((notice) => {
|
}).then((notice) => {
|
||||||
const citizens = [];
|
const users = [];
|
||||||
citizens.push(notice.data.account.acct);
|
users.push('@' + notice.data.account.acct);
|
||||||
for (let i = 0; i < notice.data.mentions.length; i++) citizens.push(notice.data.mentions[i].acct);
|
for(let i = 0; i < notice.data.mentions.length; i++) {
|
||||||
const filtered = citizens.filter(users => !config.fediverse.username.includes(users))
|
if(!config.fediverse.username.includes(notice.data.mentions[i].acct))
|
||||||
for (let i = 0; i < filtered.length; i++) posters.push(prefix.concat(filtered[i]));
|
users.push('@' + notice.data.mentions[i].acct)
|
||||||
return posters;
|
}
|
||||||
|
return users;
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
matrix.utils.addReact(event, '❌');
|
matrix.utils.addReact(event, '❌');
|
||||||
|
|
Loading…
Reference in a new issue