AP Undo Announce (#5400)

* AP Undo Announce

* Use activity id
This commit is contained in:
MeiMei 2019-09-08 11:30:44 +09:00 committed by syuilo
parent 3ef6305c76
commit c033464b92
3 changed files with 34 additions and 2 deletions

View file

@ -0,0 +1,16 @@
import { Notes } from '../../../../models';
import { IRemoteUser } from '../../../../models/entities/user';
import { IAnnounce, getApId } from '../../type';
import deleteNote from '../../../../services/note/delete';
export const undoAnnounce = async (actor: IRemoteUser, activity: IAnnounce): Promise<void> => {
const uri = getApId(activity);
const note = await Notes.findOne({
uri
});
if (!note) return;
await deleteNote(actor, note);
};

View file

@ -1,8 +1,9 @@
import { IRemoteUser } from '../../../../models/entities/user'; import { IRemoteUser } from '../../../../models/entities/user';
import { IUndo, IFollow, IBlock, ILike } from '../../type'; import { IUndo, IFollow, IBlock, ILike, IAnnounce } from '../../type';
import unfollow from './follow'; import unfollow from './follow';
import unblock from './block'; import unblock from './block';
import undoLike from './like'; import undoLike from './like';
import { undoAnnounce } from './announce';
import Resolver from '../../resolver'; import Resolver from '../../resolver';
import { apLogger } from '../../logger'; import { apLogger } from '../../logger';
@ -38,5 +39,8 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
case 'Like': case 'Like':
undoLike(actor, object as ILike); undoLike(actor, object as ILike);
break; break;
case 'Announce':
undoAnnounce(actor, object as IAnnounce);
break;
} }
}; };

View file

@ -1,5 +1,7 @@
import { publishNoteStream } from '../stream'; import { publishNoteStream } from '../stream';
import renderDelete from '../../remote/activitypub/renderer/delete'; import renderDelete from '../../remote/activitypub/renderer/delete';
import renderAnnounce from '../../remote/activitypub/renderer/announce';
import renderUndo from '../../remote/activitypub/renderer/undo';
import { renderActivity } from '../../remote/activitypub/renderer'; import { renderActivity } from '../../remote/activitypub/renderer';
import { deliver } from '../../queue'; import { deliver } from '../../queue';
import renderTombstone from '../../remote/activitypub/renderer/tombstone'; import renderTombstone from '../../remote/activitypub/renderer/tombstone';
@ -35,7 +37,17 @@ export default async function(user: User, note: Note, quiet = false) {
//#region ローカルの投稿なら削除アクティビティを配送 //#region ローカルの投稿なら削除アクティビティを配送
if (Users.isLocalUser(user)) { if (Users.isLocalUser(user)) {
const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user)); let renote: Note | undefined;
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length == 0)) {
renote = await Notes.findOne({
id: note.renoteId
});
}
const content = renderActivity(renote
? renderUndo(renderAnnounce(renote.uri || `${config.url}/notes/${renote.id}`, note), user)
: renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user));
const queue: string[] = []; const queue: string[] = [];