2022-02-27 03:07:39 +01:00
|
|
|
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
|
2022-06-04 06:52:42 +02:00
|
|
|
import { renderBlock } from '@/remote/activitypub/renderer/block.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import renderUndo from '@/remote/activitypub/renderer/undo.js';
|
|
|
|
import { deliver } from '@/queue/index.js';
|
|
|
|
import Logger from '../logger.js';
|
2022-03-26 11:09:57 +01:00
|
|
|
import { CacheableUser, User } from '@/models/entities/user.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
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
|
|
|
|
2022-03-26 11:09:57 +01:00
|
|
|
export default async function(blocker: CacheableUser, blockee: CacheableUser) {
|
2022-03-26 07:34:00 +01:00
|
|
|
const blocking = await Blockings.findOneBy({
|
2019-04-07 14:50:36 +02:00
|
|
|
blockerId: blocker.id,
|
2021-12-09 15:58:30 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-06-04 06:52:42 +02:00
|
|
|
// Since we already have the blocker and blockee, we do not need to fetch
|
|
|
|
// them in the query above and can just manually insert them here.
|
|
|
|
blocking.blocker = blocker;
|
|
|
|
blocking.blockee = blockee;
|
|
|
|
|
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)) {
|
2022-06-04 06:52:42 +02:00
|
|
|
const content = renderActivity(renderUndo(renderBlock(blocking), blocker));
|
2018-10-29 12:32:42 +01:00
|
|
|
deliver(blocker, content, blockee.inbox);
|
|
|
|
}
|
|
|
|
}
|