リモートのピン留め投稿取得対応 (#2798)
* Fetch featured * Handle featured change * Fix typo
This commit is contained in:
22
src/remote/activitypub/kernel/add/index.ts
Normal file
22
src/remote/activitypub/kernel/add/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
import { IAdd } from '../../type';
|
||||
import { resolveNote } from '../../models/note';
|
||||
import { addPinned } from '../../../../services/i/pin';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IAdd): Promise<void> => {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
}
|
||||
|
||||
if (activity.target == null) {
|
||||
throw new Error('target is null');
|
||||
}
|
||||
|
||||
if (activity.target === actor.featured) {
|
||||
const note = await resolveNote(activity.object);
|
||||
await addPinned(actor, note._id);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`unknown target: ${activity.target}`);
|
||||
};
|
@@ -8,6 +8,8 @@ import like from './like';
|
||||
import announce from './announce';
|
||||
import accept from './accept';
|
||||
import reject from './reject';
|
||||
import add from './add';
|
||||
import remove from './remove';
|
||||
|
||||
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||
switch (activity.type) {
|
||||
@@ -31,6 +33,14 @@ const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||
await reject(actor, activity);
|
||||
break;
|
||||
|
||||
case 'Add':
|
||||
await add(actor, activity).catch(err => console.log(err));
|
||||
break;
|
||||
|
||||
case 'Remove':
|
||||
await remove(actor, activity).catch(err => console.log(err));
|
||||
break;
|
||||
|
||||
case 'Announce':
|
||||
await announce(actor, activity);
|
||||
break;
|
||||
|
22
src/remote/activitypub/kernel/remove/index.ts
Normal file
22
src/remote/activitypub/kernel/remove/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
import { IRemove } from '../../type';
|
||||
import { resolveNote } from '../../models/note';
|
||||
import { removePinned } from '../../../../services/i/pin';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IRemove): Promise<void> => {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
}
|
||||
|
||||
if (activity.target == null) {
|
||||
throw new Error('target is null');
|
||||
}
|
||||
|
||||
if (activity.target === actor.featured) {
|
||||
const note = await resolveNote(activity.object);
|
||||
await removePinned(actor, note._id);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`unknown target: ${activity.target}`);
|
||||
};
|
Reference in New Issue
Block a user