activitypub: properly render CW only quotes

Changelog: Fixed
This commit is contained in:
Johann150 2023-02-04 00:13:43 +01:00
parent 0bb4a6af50
commit 85a68a5eee
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 6 additions and 14 deletions

View file

@ -1,8 +1,9 @@
import { Note } from '@/models/entities/note.js';
export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, fileIds: null | never[], hasPoll: false } {
export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, cw: null, fileIds: null | never[], hasPoll: false } {
return note.renoteId != null
&& note.text == null
&& note.cw == null
&& (
note.fileIds == null
|| note.fileIds.length === 0

View file

@ -102,7 +102,7 @@ export default async (ctx: Router.RouterContext) => {
export async function packActivity(note: Note): Promise<any> {
if (isPureRenote(note)) {
const renote = await Notes.findOneByOrFail({ id: note.renoteId });
return renderAnnounce(renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`, note);
return renderAnnounce(renote.uri ?? `${config.url}/notes/${renote.id}`, note);
} else {
return renderCreate(await renderNote(note, false), note);
}

View file

@ -36,6 +36,7 @@ import { Cache } from '@/misc/cache.js';
import { UserProfile } from '@/models/entities/user-profile.js';
import { getActiveWebhooks } from '@/misc/webhook-cache.js';
import { IActivity } from '@/remote/activitypub/type.js';
import { packActivity } from '@/server/activitypub/outbox.js';
import { MINUTE } from '@/const.js';
import { updateHashtags } from '../update-hashtag.js';
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
@ -428,9 +429,9 @@ export default async (user: { id: User['id']; username: User['username']; host:
});
//#region AP deliver
if (Users.isLocalUser(user)) {
if (Users.isLocalUser(user) && !data.localOnly) {
(async () => {
const noteActivity = await renderNoteOrRenoteActivity(data, note);
const noteActivity = renderActivity(await packActivity(note));
const dm = new DeliverManager(user, noteActivity);
// Delivered to remote users who have been mentioned
@ -487,16 +488,6 @@ export default async (user: { id: User['id']; username: User['username']; host:
index(note);
});
async function renderNoteOrRenoteActivity(data: Option, note: Note): Promise<IActivity | null> {
if (data.localOnly) return null;
const content = data.renote && data.text == null && data.poll == null && (data.files == null || data.files.length === 0)
? renderAnnounce(data.renote.uri ? data.renote.uri : `${config.url}/notes/${data.renote.id}`, note)
: renderCreate(await renderNote(note, false), note);
return renderActivity(content);
}
function incRenoteCount(renote: Note): void {
Notes.createQueryBuilder().update()
.set({