From 20e77196f28178c869402985761bd4c2fa74bf0a Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 22 Apr 2018 10:44:17 +0900 Subject: AP: 投票をレンダリング MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote/activitypub/renderer/note.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/remote/activitypub/renderer') diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index c364b13249..a05c12b388 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -4,6 +4,7 @@ import config from '../../../config'; import DriveFile from '../../../models/drive-file'; import Note, { INote } from '../../../models/note'; import User from '../../../models/user'; +import toHtml from '../misc/get-note-html'; export default async function renderNote(note: INote, dive = true) { const promisedFiles = note.mediaIds @@ -48,7 +49,7 @@ export default async function renderNote(note: INote, dive = true) { id: `${config.url}/notes/${note._id}`, type: 'Note', attributedTo, - content: note.textHtml, + content: toHtml(note), published: note.createdAt.toISOString(), to: 'https://www.w3.org/ns/activitystreams#Public', cc: `${attributedTo}/followers`, -- cgit v1.2.3-freya From 02bb99ac029e8fc12aec384717341f603052d7c0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 23 Apr 2018 15:27:01 +0900 Subject: 他のMisskeyインスタンスにリアクション情報を伝えるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/note-reaction.ts | 13 +++++++++++++ src/remote/activitypub/kernel/like.ts | 12 +++++++++++- src/remote/activitypub/renderer/like.ts | 5 +++-- src/remote/activitypub/type.ts | 1 + src/server/api/endpoints/notes/reactions/create.ts | 13 ++----------- src/services/note/reaction/create.ts | 2 +- 6 files changed, 31 insertions(+), 15 deletions(-) (limited to 'src/remote/activitypub/renderer') diff --git a/src/models/note-reaction.ts b/src/models/note-reaction.ts index 9bf467f222..7891ebdf17 100644 --- a/src/models/note-reaction.ts +++ b/src/models/note-reaction.ts @@ -1,4 +1,5 @@ import * as mongo from 'mongodb'; +import $ from 'cafy'; import deepcopy = require('deepcopy'); import db from '../db/mongodb'; import Reaction from './note-reaction'; @@ -16,6 +17,18 @@ export interface INoteReaction { reaction: string; } +export const validateReaction = $().string().or([ + 'like', + 'love', + 'laugh', + 'hmm', + 'surprise', + 'congrats', + 'angry', + 'confused', + 'pudding' +]); + /** * NoteReactionを物理削除します */ diff --git a/src/remote/activitypub/kernel/like.ts b/src/remote/activitypub/kernel/like.ts index fc5d0a2f61..17ec73f12b 100644 --- a/src/remote/activitypub/kernel/like.ts +++ b/src/remote/activitypub/kernel/like.ts @@ -3,6 +3,7 @@ import Note from '../../../models/note'; import { IRemoteUser } from '../../../models/user'; import { ILike } from '../type'; import create from '../../../services/note/reaction/create'; +import { validateReaction } from '../../../models/note-reaction'; export default async (actor: IRemoteUser, activity: ILike) => { const id = typeof activity.object == 'string' ? activity.object : activity.object.id; @@ -17,5 +18,14 @@ export default async (actor: IRemoteUser, activity: ILike) => { throw new Error(); } - await create(actor, note, 'pudding'); + let reaction = 'pudding'; + + // 他のMisskeyインスタンスからのリアクション + if (activity._misskey_reaction) { + if (validateReaction.ok(activity._misskey_reaction)) { + reaction = activity._misskey_reaction; + } + } + + await create(actor, note, reaction); }; diff --git a/src/remote/activitypub/renderer/like.ts b/src/remote/activitypub/renderer/like.ts index 061a10ba84..33e1341a20 100644 --- a/src/remote/activitypub/renderer/like.ts +++ b/src/remote/activitypub/renderer/like.ts @@ -1,8 +1,9 @@ import config from '../../../config'; import { ILocalUser } from '../../../models/user'; -export default (user: ILocalUser, note) => ({ +export default (user: ILocalUser, note, reaction: string) => ({ type: 'Like', actor: `${config.url}/users/${user._id}`, - object: note.uri ? note.uri : `${config.url}/notes/${note._id}` + object: note.uri ? note.uri : `${config.url}/notes/${note._id}`, + _misskey_reaction: reaction }); diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 08e5493dd4..6018ac29c4 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -82,6 +82,7 @@ export interface IAccept extends IActivity { export interface ILike extends IActivity { type: 'Like'; + _misskey_reaction: string; } export interface IAnnounce extends IActivity { diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts index c80c5416b1..9e217cc3e0 100644 --- a/src/server/api/endpoints/notes/reactions/create.ts +++ b/src/server/api/endpoints/notes/reactions/create.ts @@ -4,6 +4,7 @@ import $ from 'cafy'; import Note from '../../../../../models/note'; import create from '../../../../../services/note/reaction/create'; +import { validateReaction } from '../../../../../models/note-reaction'; /** * React to a note @@ -14,17 +15,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (noteIdErr) return rej('invalid noteId param'); // Get 'reaction' parameter - const [reaction, reactionErr] = $(params.reaction).string().or([ - 'like', - 'love', - 'laugh', - 'hmm', - 'surprise', - 'congrats', - 'angry', - 'confused', - 'pudding' - ]).$; + const [reaction, reactionErr] = $(params.reaction).string().pipe(validateReaction.ok).$; if (reactionErr) return rej('invalid reaction param'); // Fetch reactee diff --git a/src/services/note/reaction/create.ts b/src/services/note/reaction/create.ts index 06fd6c0576..123c091c85 100644 --- a/src/services/note/reaction/create.ts +++ b/src/services/note/reaction/create.ts @@ -87,7 +87,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise //#region 配信 // リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送 if (isLocalUser(user) && isRemoteUser(note._user)) { - const content = pack(renderLike(user, note)); + const content = pack(renderLike(user, note, reaction)); deliver(user, content, note._user.inbox); } //#endregion -- cgit v1.2.3-freya From 1131ce8a716b2cd2b4ed1253af40b26ae0631297 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 23 Apr 2018 15:37:27 +0900 Subject: sharedInboxを提供 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/remote/activitypub/renderer/person.ts | 1 + src/server/activitypub.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/remote/activitypub/renderer') diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts index f1c8056a75..424305f8d3 100644 --- a/src/remote/activitypub/renderer/person.ts +++ b/src/remote/activitypub/renderer/person.ts @@ -10,6 +10,7 @@ export default user => { id, inbox: `${id}/inbox`, outbox: `${id}/outbox`, + sharedInbox: `${config.url}/inbox`, url: `${config.url}/@${user.username}`, preferredUsername: user.username, name: user.name, diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 73ed43406d..3c07a3e2f2 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -1,4 +1,5 @@ import * as mongo from 'mongodb'; +import * as Koa from 'koa'; import * as Router from 'koa-router'; const json = require('koa-json-body'); const httpSignature = require('http-signature'); @@ -19,8 +20,7 @@ const router = new Router(); //#region Routing -// inbox -router.post('/users/:user/inbox', json(), ctx => { +function inbox(ctx: Koa.Context) { let signature; ctx.req.headers.authorization = 'Signature ' + ctx.req.headers.signature; @@ -39,7 +39,11 @@ router.post('/users/:user/inbox', json(), ctx => { }).save(); ctx.status = 202; -}); +} + +// inbox +router.post('/inbox', json(), inbox); +router.post('/users/:user/inbox', json(), inbox); // note router.get('/notes/:note', async (ctx, next) => { -- cgit v1.2.3-freya