2021-08-19 11:33:41 +02:00
|
|
|
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
|
|
|
|
import renderBlock from '@/remote/activitypub/renderer/block.js';
|
|
|
|
import renderUndo from '@/remote/activitypub/renderer/undo.js';
|
|
|
|
import { deliver } from '@/queue/index.js';
|
|
|
|
import Logger from '../logger.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { Blockings, Users } from '@/models/index.js';
|
2019-02-03 10:16:57 +01:00
|
|
|
|
|
|
|
const logger = new Logger('blocking/delete');
|
2018-10-29 12:32:42 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
export default async function(blocker: User, blockee: User) {
|
|
|
|
const blocking = await Blockings.findOne({
|
|
|
|
blockerId: blocker.id,
|
|
|
|
blockeeId: blockee.id
|
2018-10-29 12:32:42 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (blocking == null) {
|
2019-02-03 10:16:57 +01:00
|
|
|
logger.warn('ブロック解除がリクエストされましたがブロックしていませんでした');
|
2018-10-29 12:32:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
Blockings.delete(blocking.id);
|
2018-10-29 12:32:42 +01:00
|
|
|
|
|
|
|
// deliver if remote bloking
|
2019-04-07 14:50:36 +02:00
|
|
|
if (Users.isLocalUser(blocker) && Users.isRemoteUser(blockee)) {
|
2019-01-30 18:29:36 +01:00
|
|
|
const content = renderActivity(renderUndo(renderBlock(blocker, blockee), blocker));
|
2018-10-29 12:32:42 +01:00
|
|
|
deliver(blocker, content, blockee.inbox);
|
|
|
|
}
|
|
|
|
}
|