forked from FoundKeyGang/FoundKey
他のMisskeyインスタンスにリアクション情報を伝えるように
This commit is contained in:
parent
0b99483ccb
commit
02bb99ac02
6 changed files with 31 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
|
import $ from 'cafy';
|
||||||
import deepcopy = require('deepcopy');
|
import deepcopy = require('deepcopy');
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
import Reaction from './note-reaction';
|
import Reaction from './note-reaction';
|
||||||
|
@ -16,6 +17,18 @@ export interface INoteReaction {
|
||||||
reaction: string;
|
reaction: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const validateReaction = $().string().or([
|
||||||
|
'like',
|
||||||
|
'love',
|
||||||
|
'laugh',
|
||||||
|
'hmm',
|
||||||
|
'surprise',
|
||||||
|
'congrats',
|
||||||
|
'angry',
|
||||||
|
'confused',
|
||||||
|
'pudding'
|
||||||
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NoteReactionを物理削除します
|
* NoteReactionを物理削除します
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Note from '../../../models/note';
|
||||||
import { IRemoteUser } from '../../../models/user';
|
import { IRemoteUser } from '../../../models/user';
|
||||||
import { ILike } from '../type';
|
import { ILike } from '../type';
|
||||||
import create from '../../../services/note/reaction/create';
|
import create from '../../../services/note/reaction/create';
|
||||||
|
import { validateReaction } from '../../../models/note-reaction';
|
||||||
|
|
||||||
export default async (actor: IRemoteUser, activity: ILike) => {
|
export default async (actor: IRemoteUser, activity: ILike) => {
|
||||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
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();
|
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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { ILocalUser } from '../../../models/user';
|
import { ILocalUser } from '../../../models/user';
|
||||||
|
|
||||||
export default (user: ILocalUser, note) => ({
|
export default (user: ILocalUser, note, reaction: string) => ({
|
||||||
type: 'Like',
|
type: 'Like',
|
||||||
actor: `${config.url}/users/${user._id}`,
|
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
|
||||||
});
|
});
|
||||||
|
|
|
@ -82,6 +82,7 @@ export interface IAccept extends IActivity {
|
||||||
|
|
||||||
export interface ILike extends IActivity {
|
export interface ILike extends IActivity {
|
||||||
type: 'Like';
|
type: 'Like';
|
||||||
|
_misskey_reaction: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAnnounce extends IActivity {
|
export interface IAnnounce extends IActivity {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import Note from '../../../../../models/note';
|
import Note from '../../../../../models/note';
|
||||||
import create from '../../../../../services/note/reaction/create';
|
import create from '../../../../../services/note/reaction/create';
|
||||||
|
import { validateReaction } from '../../../../../models/note-reaction';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React to a note
|
* React to a note
|
||||||
|
@ -14,17 +15,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
|
||||||
// Get 'reaction' parameter
|
// Get 'reaction' parameter
|
||||||
const [reaction, reactionErr] = $(params.reaction).string().or([
|
const [reaction, reactionErr] = $(params.reaction).string().pipe(validateReaction.ok).$;
|
||||||
'like',
|
|
||||||
'love',
|
|
||||||
'laugh',
|
|
||||||
'hmm',
|
|
||||||
'surprise',
|
|
||||||
'congrats',
|
|
||||||
'angry',
|
|
||||||
'confused',
|
|
||||||
'pudding'
|
|
||||||
]).$;
|
|
||||||
if (reactionErr) return rej('invalid reaction param');
|
if (reactionErr) return rej('invalid reaction param');
|
||||||
|
|
||||||
// Fetch reactee
|
// Fetch reactee
|
||||||
|
|
|
@ -87,7 +87,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
|
||||||
//#region 配信
|
//#region 配信
|
||||||
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
|
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
|
||||||
if (isLocalUser(user) && isRemoteUser(note._user)) {
|
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);
|
deliver(user, content, note._user.inbox);
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
Loading…
Reference in a new issue