summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/models/note.ts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2019-12-15 03:37:54 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-12-15 03:37:54 +0900
commitc012f4f880fb3bf70607f2ab49e8638c0ac87713 (patch)
tree986c010c9f5bdea61132a4d8a9de3ca6e2d07371 /src/remote/activitypub/models/note.ts
parentImplement Talk has read federation (#5636) (diff)
downloadsharkey-c012f4f880fb3bf70607f2ab49e8638c0ac87713.tar.gz
sharkey-c012f4f880fb3bf70607f2ab49e8638c0ac87713.tar.bz2
sharkey-c012f4f880fb3bf70607f2ab49e8638c0ac87713.zip
AP引用でquoteUrlに対応 (#5632)
* Supports quoteUrl * Quote resolveをリトライする * Update src/remote/activitypub/models/note.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * Update src/remote/activitypub/models/note.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * Update src/remote/activitypub/models/note.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * Update src/remote/activitypub/models/note.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
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;