forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
8 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}; |