User blocking (Following part) (#3035)
* block wip * UndoBlock * UnBlock * wip * follow * UI * fix
This commit is contained in:
34
src/remote/activitypub/kernel/block/index.ts
Normal file
34
src/remote/activitypub/kernel/block/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import User, { IRemoteUser } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
import * as debug from 'debug';
|
||||
import { IBlock } from '../../type';
|
||||
import block from '../../../../services/blocking/create';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
|
||||
const uri = activity.id || activity;
|
||||
|
||||
log(`Block: ${uri}`);
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockee = await User.findOne({
|
||||
_id: new mongo.ObjectID(id.split('/').pop())
|
||||
});
|
||||
|
||||
if (blockee === null) {
|
||||
throw new Error('blockee not found');
|
||||
}
|
||||
|
||||
if (blockee.host != null) {
|
||||
throw new Error('ブロックしようとしているユーザーはローカルユーザーではありません');
|
||||
}
|
||||
|
||||
block(actor, blockee);
|
||||
};
|
@@ -10,6 +10,7 @@ import accept from './accept';
|
||||
import reject from './reject';
|
||||
import add from './add';
|
||||
import remove from './remove';
|
||||
import block from './block';
|
||||
|
||||
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||
switch (activity.type) {
|
||||
@@ -53,6 +54,10 @@ const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||
await undo(actor, activity);
|
||||
break;
|
||||
|
||||
case 'Block':
|
||||
await block(actor, activity);
|
||||
break;
|
||||
|
||||
case 'Collection':
|
||||
case 'OrderedCollection':
|
||||
// TODO
|
||||
|
34
src/remote/activitypub/kernel/undo/block.ts
Normal file
34
src/remote/activitypub/kernel/undo/block.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import User, { IRemoteUser } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
import * as debug from 'debug';
|
||||
import { IBlock } from '../../type';
|
||||
import unblock from '../../../../services/blocking/delete';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
|
||||
const uri = activity.id || activity;
|
||||
|
||||
log(`UnBlock: ${uri}`);
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const blockee = await User.findOne({
|
||||
_id: new mongo.ObjectID(id.split('/').pop())
|
||||
});
|
||||
|
||||
if (blockee === null) {
|
||||
throw new Error('blockee not found');
|
||||
}
|
||||
|
||||
if (blockee.host != null) {
|
||||
throw new Error('ブロック解除しようとしているユーザーはローカルユーザーではありません');
|
||||
}
|
||||
|
||||
unblock(actor, blockee);
|
||||
};
|
@@ -1,8 +1,9 @@
|
||||
import * as debug from 'debug';
|
||||
|
||||
import { IRemoteUser } from '../../../../models/user';
|
||||
import { IUndo, IFollow } from '../../type';
|
||||
import { IUndo, IFollow, IBlock } from '../../type';
|
||||
import unfollow from './follow';
|
||||
import unblock from './block';
|
||||
import Resolver from '../../resolver';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
@@ -31,6 +32,9 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
|
||||
case 'Follow':
|
||||
unfollow(actor, object as IFollow);
|
||||
break;
|
||||
case 'Block':
|
||||
unblock(actor, object as IBlock);
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user