Skip to content

Commit

Permalink
Undo Announce処理をシンプルに
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Mar 31, 2024
1 parent 410ec34 commit 2799da0
Showing 1 changed file with 8 additions and 38 deletions.
46 changes: 8 additions & 38 deletions src/remote/activitypub/kernel/undo/announce.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,18 @@
import * as mongo from 'mongodb';
import { IRemoteUser } from '../../../../models/user';
import { IAnnounce, getApId } from '../../type';
import deleteNote from '../../../../services/note/delete';
import Note, { INote } from '../../../../models/note';
import { isSelfOrigin } from '../../../../misc/convert-host';
import Note from '../../../../models/note';

export const undoAnnounce = async (actor: IRemoteUser, activity: IAnnounce): Promise<string> => {
const targetUri = getApId(activity.object);
const uri = getApId(activity);

let note: INote | undefined;
const note = await Note.findOne({
uri
});

if (isSelfOrigin(targetUri)) {
// 対象がローカルの場合
const id = new mongo.ObjectID(targetUri.split('/').pop());
note = await Note.findOne({
userId: actor._id,
renoteId: id,
deletedAt: { $exists: false }
});

if (!note) {
return `skip: target renote is not found`;
}
} else {
// 対象がリモートの場合
const targetNote = await Note.findOne({
uri: targetUri
});

if (!targetNote) {
return `skip: target note is not found`;
}

note = await Note.findOne({
userId: actor._id,
renoteId: targetNote._id,
deletedAt: { $exists: false }
});

if (!note) {
return `skip: target renote is not found`;
}
}
if (!note) return 'skip: no such Announce';

await deleteNote(actor, note);
return `ok`;

return 'ok: deleted';
};

0 comments on commit 2799da0

Please sign in to comment.