summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/models/note.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/remote/activitypub/models/note.ts')
-rw-r--r--src/remote/activitypub/models/note.ts44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts
index 7ce0b6a11f..74d764e5e4 100644
--- a/src/remote/activitypub/models/note.ts
+++ b/src/remote/activitypub/models/note.ts
@@ -162,16 +162,42 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
// 引用
let quote: Note | undefined | null;
- if (note._misskey_quote && typeof note._misskey_quote == 'string') {
- quote = await resolveNote(note._misskey_quote).catch(e => {
- // 4xxの場合は引用してないことにする
- if (e.statusCode >= 400 && e.statusCode < 500) {
- logger.warn(`Ignored quote target ${note.inReplyTo} - ${e.statusCode} `);
- return null;
+ if (note._misskey_quote || note.quoteUrl) {
+ const tryResolveNote = async (uri: string): Promise<{
+ status: 'ok';
+ res: Note | null;
+ } | {
+ status: 'permerror' | 'temperror';
+ }> => {
+ if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
+ try {
+ const res = await resolveNote(uri);
+ if (res) {
+ return {
+ status: 'ok',
+ res
+ };
+ } else {
+ return {
+ status: 'permerror'
+ };
+ }
+ } catch (e) {
+ return {
+ status: e.statusCode >= 400 && e.statusCode < 500 ? 'permerror' : 'temperror'
+ };
}
- logger.warn(`Error in quote target ${note.inReplyTo} - ${e.statusCode || e}`);
- throw e;
- });
+ };
+
+ const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string'));
+ const results = await Promise.all(uris.map(uri => tryResolveNote(uri)));
+
+ quote = results.filter((x): x is { status: 'ok', res: Note | null } => x.status === 'ok').map(x => x.res).find(x => x);
+ if (!quote) {
+ if (results.some(x => x.status === 'temperror')) {
+ throw 'quote resolve failed';
+ }
+ }
}
const cw = note.summary === '' ? null : note.summary;