mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-25 23:45:13 +00:00
On remote notes, not use content for detecting mentions (#3170)
* On remote note, detect mentioned users from to/cc * fix
This commit is contained in:
parent
5ef8a8b5f0
commit
5b684c6deb
2 changed files with 23 additions and 1 deletions
|
@ -13,6 +13,7 @@ import htmlToMFM from '../../../mfm/html-to-mfm';
|
|||
import Emoji from '../../../models/emoji';
|
||||
import { ITag } from './tag';
|
||||
import { toUnicode } from 'punycode';
|
||||
import { unique } from '../../../prelude/array';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
|
||||
|
@ -81,6 +82,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
|||
}
|
||||
//#endergion
|
||||
|
||||
const apMentions = await extractMentionedUsers(actor, note.to, note.cc, resolver);
|
||||
|
||||
// 添付ファイル
|
||||
// TODO: attachmentは必ずしもImageではない
|
||||
// TODO: attachmentは必ずしも配列ではない
|
||||
|
@ -116,6 +119,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
|||
geo: undefined,
|
||||
visibility,
|
||||
visibleUsers,
|
||||
apMentions,
|
||||
uri: note.id
|
||||
}, silent);
|
||||
}
|
||||
|
@ -174,3 +178,20 @@ async function extractEmojis(tags: ITag[], host_: string) {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: string[], resolver: Resolver ) {
|
||||
let uris = [] as string[];
|
||||
|
||||
if (to) uris.concat(to);
|
||||
if (cc) uris.concat(cc);
|
||||
|
||||
uris = uris.filter(x => x !== 'https://www.w3.org/ns/activitystreams#Public');
|
||||
uris = uris.filter(x => x !== `${actor.uri}/followers`);
|
||||
uris = unique(uris);
|
||||
|
||||
const users = await Promise.all(
|
||||
uris.map(async uri => await resolvePerson(uri, null, resolver).catch(() => null))
|
||||
);
|
||||
|
||||
return users.filter(x => x != null);
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ type Option = {
|
|||
cw?: string;
|
||||
visibility?: string;
|
||||
visibleUsers?: IUser[];
|
||||
apMentions?: IUser[];
|
||||
uri?: string;
|
||||
app?: IApp;
|
||||
};
|
||||
|
@ -149,7 +150,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
|
|||
|
||||
const emojis = extractEmojis(tokens);
|
||||
|
||||
const mentionedUsers = await extractMentionedUsers(tokens);
|
||||
const mentionedUsers = data.apMentions || await extractMentionedUsers(tokens);
|
||||
|
||||
if (data.reply && !user._id.equals(data.reply.userId) && !mentionedUsers.some(u => u._id.equals(data.reply.userId))) {
|
||||
mentionedUsers.push(await User.findOne({ _id: data.reply.userId }));
|
||||
|
|
Loading…
Reference in a new issue