diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-04-05 01:57:18 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-04-05 01:57:18 +0900 |
| commit | ced6b9a76f71e95a376dc4cb37b6b5617a0321d9 (patch) | |
| tree | 203f3fd18fd6bf093082c4e49d9720faf8ccecca /src | |
| parent | Implement Hashtag object (diff) | |
| download | sharkey-ced6b9a76f71e95a376dc4cb37b6b5617a0321d9.tar.gz sharkey-ced6b9a76f71e95a376dc4cb37b6b5617a0321d9.tar.bz2 sharkey-ced6b9a76f71e95a376dc4cb37b6b5617a0321d9.zip | |
Handle inReplyTo property
Diffstat (limited to 'src')
| -rw-r--r-- | src/remote/activitypub/create.ts | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/remote/activitypub/create.ts b/src/remote/activitypub/create.ts index 31e9dba863..3bc0c66f35 100644 --- a/src/remote/activitypub/create.ts +++ b/src/remote/activitypub/create.ts @@ -48,11 +48,6 @@ class Creator { throw new Error(); } - const mediaIds = 'attachment' in note && - (await Promise.all(await this.create(resolver, note.attachment))) - .filter(media => media !== null && media.object.$ref === 'driveFiles.files') - .map(({ object }) => object.$id); - const { window } = new JSDOM(note.content); const mentions = []; const tags = []; @@ -71,13 +66,27 @@ class Creator { } } + const [mediaIds, reply] = await Promise.all([ + 'attachment' in note && this.create(resolver, note.attachment) + .then(collection => Promise.all(collection)) + .then(collection => collection + .filter(media => media !== null && media.object.$ref === 'driveFiles.files') + .map(({ object }: IResult) => object.$id)), + + 'inReplyTo' in note && this.create(resolver, note.inReplyTo) + .then(collection => Promise.all(collection.map(promise => promise.then(result => { + if (result !== null && result.object.$ref === 'posts') { + throw result.object; + } + }, () => { })))) + .then(() => null, ({ $id }) => Post.findOne({ _id: $id })) + ]); + const inserted = await createPost({ channelId: undefined, index: undefined, createdAt: new Date(note.published), mediaIds, - replyId: undefined, - repostId: undefined, poll: undefined, text: window.document.body.textContent, textHtml: note.content && createDOMPurify(window).sanitize(note.content), @@ -87,7 +96,7 @@ class Creator { geo: undefined, uri: note.id, tags - }, null, null, await Promise.all(mentions)); + }, reply, null, await Promise.all(mentions)); const promises = []; |