summaryrefslogtreecommitdiff
path: root/packages/backend/src/remote
diff options
context:
space:
mode:
authorJohann150 <johann.galle@protonmail.com>2022-06-03 16:18:44 +0200
committerGitHub <noreply@github.com>2022-06-03 23:18:44 +0900
commit81109b14b585b2ca6ba85ebedcb41f9b8cca5382 (patch)
tree0ceac5e4729b67280a2c48649a43792664a1ff9a /packages/backend/src/remote
parentUser moderation details (#8762) (diff)
downloadmisskey-81109b14b585b2ca6ba85ebedcb41f9b8cca5382.tar.gz
misskey-81109b14b585b2ca6ba85ebedcb41f9b8cca5382.tar.bz2
misskey-81109b14b585b2ca6ba85ebedcb41f9b8cca5382.zip
fix: correctly render empty note text (#8746)
Ensure that the _misskey_content attribute will always exist. Because the API endpoint does not require the existence of the `text` field, that field may be `undefined`. By using `?? null` it can be ensured that the value is at least `null`. Furthermore, the rendered HTML of a note with empty text will also be the empty string. From git blame it seems that this behaviour was added because of a Mastodon bug that might have previously existed. Hoever, this seems to be no longer the case as I can find mastodon posts that have empty content. The code could be made a bit more succinct by using the null coercion operator.
Diffstat (limited to 'packages/backend/src/remote')
-rw-r--r--packages/backend/src/remote/activitypub/misc/get-note-html.ts6
-rw-r--r--packages/backend/src/remote/activitypub/renderer/note.ts6
2 files changed, 5 insertions, 7 deletions
diff --git a/packages/backend/src/remote/activitypub/misc/get-note-html.ts b/packages/backend/src/remote/activitypub/misc/get-note-html.ts
index 3800b40608..389039ebed 100644
--- a/packages/backend/src/remote/activitypub/misc/get-note-html.ts
+++ b/packages/backend/src/remote/activitypub/misc/get-note-html.ts
@@ -3,8 +3,6 @@ import { Note } from '@/models/entities/note.js';
import { toHtml } from '../../../mfm/to-html.js';
export default function(note: Note) {
- let html = note.text ? toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers)) : null;
- if (html == null) html = '<p>.</p>';
-
- return html;
+ if (!note.text) return '';
+ return toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers));
}
diff --git a/packages/backend/src/remote/activitypub/renderer/note.ts b/packages/backend/src/remote/activitypub/renderer/note.ts
index e8d429e5de..b7df0e9a39 100644
--- a/packages/backend/src/remote/activitypub/renderer/note.ts
+++ b/packages/backend/src/remote/activitypub/renderer/note.ts
@@ -82,15 +82,15 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
const files = await getPromisedFiles(note.fileIds);
- const text = note.text;
+ // text should never be undefined
+ const text = note.text ?? null;
let poll: Poll | null = null;
if (note.hasPoll) {
poll = await Polls.findOneBy({ noteId: note.id });
}
- let apText = text;
- if (apText == null) apText = '';
+ let apText = text ?? '';
if (quote) {
apText += `\n\nRE: ${quote}`;