2018-10-29 11:32:42 +00:00
|
|
|
import { isLocalUser, isRemoteUser, IUser } from '../../models/user';
|
|
|
|
import Blocking from '../../models/blocking';
|
2019-01-30 17:29:36 +00:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-10-29 11:32:42 +00:00
|
|
|
import renderBlock from '../../remote/activitypub/renderer/block';
|
|
|
|
import renderUndo from '../../remote/activitypub/renderer/undo';
|
|
|
|
import { deliver } from '../../queue';
|
2019-03-02 09:51:59 +00:00
|
|
|
import Logger from '../logger';
|
2019-02-03 09:16:57 +00:00
|
|
|
|
|
|
|
const logger = new Logger('blocking/delete');
|
2018-10-29 11:32:42 +00:00
|
|
|
|
|
|
|
export default async function(blocker: IUser, blockee: IUser) {
|
|
|
|
const blocking = await Blocking.findOne({
|
|
|
|
blockerId: blocker._id,
|
|
|
|
blockeeId: blockee._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (blocking == null) {
|
2019-02-03 09:16:57 +00:00
|
|
|
logger.warn('ブロック解除がリクエストされましたがブロックしていませんでした');
|
2018-10-29 11:32:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Blocking.remove({
|
|
|
|
_id: blocking._id
|
|
|
|
});
|
|
|
|
|
|
|
|
// deliver if remote bloking
|
|
|
|
if (isLocalUser(blocker) && isRemoteUser(blockee)) {
|
2019-01-30 17:29:36 +00:00
|
|
|
const content = renderActivity(renderUndo(renderBlock(blocker, blockee), blocker));
|
2018-10-29 11:32:42 +00:00
|
|
|
deliver(blocker, content, blockee.inbox);
|
|
|
|
}
|
|
|
|
}
|