mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 08:33:09 +02:00
29 lines
912 B
TypeScript
29 lines
912 B
TypeScript
|
import { isLocalUser, isRemoteUser, IUser } from '../../models/user';
|
||
|
import Blocking from '../../models/blocking';
|
||
|
import pack from '../../remote/activitypub/renderer';
|
||
|
import renderBlock from '../../remote/activitypub/renderer/block';
|
||
|
import renderUndo from '../../remote/activitypub/renderer/undo';
|
||
|
import { deliver } from '../../queue';
|
||
|
|
||
|
export default async function(blocker: IUser, blockee: IUser) {
|
||
|
const blocking = await Blocking.findOne({
|
||
|
blockerId: blocker._id,
|
||
|
blockeeId: blockee._id
|
||
|
});
|
||
|
|
||
|
if (blocking == null) {
|
||
|
console.warn('ブロック解除がリクエストされましたがブロックしていませんでした');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Blocking.remove({
|
||
|
_id: blocking._id
|
||
|
});
|
||
|
|
||
|
// deliver if remote bloking
|
||
|
if (isLocalUser(blocker) && isRemoteUser(blockee)) {
|
||
|
const content = pack(renderUndo(renderBlock(blocker, blockee), blocker));
|
||
|
deliver(blocker, content, blockee.inbox);
|
||
|
}
|
||
|
}
|