mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									6061937996
								
							
						
					
					
						commit
						81109b14b5
					
				
					 2 changed files with 5 additions and 7 deletions
				
			
		| 
						 | 
					@ -3,8 +3,6 @@ import { Note } from '@/models/entities/note.js';
 | 
				
			||||||
import { toHtml } from '../../../mfm/to-html.js';
 | 
					import { toHtml } from '../../../mfm/to-html.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function(note: Note) {
 | 
					export default function(note: Note) {
 | 
				
			||||||
	let html = note.text ? toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers)) : null;
 | 
						if (!note.text) return '';
 | 
				
			||||||
	if (html == null) html = '<p>.</p>';
 | 
						return toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers));
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return html;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,15 +82,15 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const files = await getPromisedFiles(note.fileIds);
 | 
						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;
 | 
						let poll: Poll | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (note.hasPoll) {
 | 
						if (note.hasPoll) {
 | 
				
			||||||
		poll = await Polls.findOneBy({ noteId: note.id });
 | 
							poll = await Polls.findOneBy({ noteId: note.id });
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let apText = text;
 | 
						let apText = text ?? '';
 | 
				
			||||||
	if (apText == null) apText = '';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (quote) {
 | 
						if (quote) {
 | 
				
			||||||
		apText += `\n\nRE: ${quote}`;
 | 
							apText += `\n\nRE: ${quote}`;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue