mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[mastodon-client] Rework quote rendering
This commit is contained in:
parent
775d8f6e3a
commit
2830953862
@ -87,14 +87,16 @@ export class NoteConverter {
|
||||
.catch(() => null)))
|
||||
.then(p => p.filter(m => m)) as Promise<MastodonEntity.Mention[]>;
|
||||
|
||||
const text = Promise.resolve(renote).then(renote => {
|
||||
if (!renote || note.text === null) return note.text
|
||||
const uri = renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`;
|
||||
return note.text.includes(uri)
|
||||
? note.text
|
||||
: note.text + `\n\nRE: ${uri}`;
|
||||
const quoteUri = Promise.resolve(renote).then(renote => {
|
||||
if (!renote || note.text === null) return null;
|
||||
return renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`;
|
||||
});
|
||||
|
||||
const content = note.text !== null
|
||||
? quoteUri.then(quoteUri => MfmHelpers.toHtml(mfm.parse(note.text!), JSON.parse(note.mentionedRemoteUsers), note.userHost, false, quoteUri)
|
||||
.then(p => p ?? escapeMFM(note.text!)))
|
||||
: "";
|
||||
|
||||
const isPinned = user && note.userId === user.id
|
||||
? UserNotePinings.exist({ where: { userId: user.id, noteId: note.id } })
|
||||
: undefined;
|
||||
@ -117,9 +119,9 @@ export class NoteConverter {
|
||||
in_reply_to_id: note.replyId,
|
||||
in_reply_to_account_id: note.replyUserId,
|
||||
reblog: reblog.then(reblog => note.text === null ? reblog : null),
|
||||
content: text.then(async text => text !== null ? MfmHelpers.toHtml(mfm.parse(text), JSON.parse(note.mentionedRemoteUsers), note.userHost).then(p => p ?? escapeMFM(text)) : ""),
|
||||
content: content,
|
||||
content_type: 'text/x.misskeymarkdown',
|
||||
text: text,
|
||||
text: note.text,
|
||||
created_at: note.createdAt.toISOString(),
|
||||
emojis: noteEmoji,
|
||||
replies_count: note.repliesCount,
|
||||
|
@ -10,7 +10,8 @@ export class MfmHelpers {
|
||||
nodes: mfm.MfmNode[] | null,
|
||||
mentionedRemoteUsers: IMentionedRemoteUsers = [],
|
||||
objectHost: string | null,
|
||||
inline: boolean = false
|
||||
inline: boolean = false,
|
||||
quoteUri: string | null = null
|
||||
) {
|
||||
if (nodes == null) {
|
||||
return null;
|
||||
@ -194,6 +195,21 @@ export class MfmHelpers {
|
||||
|
||||
await appendChildren(nodes, doc.body);
|
||||
|
||||
if (quoteUri !== null) {
|
||||
const a = doc.createElement("a");
|
||||
a.href = quoteUri;
|
||||
a.textContent = quoteUri.replace(/^https?:\/\//, '');
|
||||
|
||||
const quote = doc.createElement("span");
|
||||
quote.setAttribute("class", "quote-inline");
|
||||
quote.appendChild(doc.createElement("br"));
|
||||
quote.appendChild(doc.createElement("br"));
|
||||
quote.innerHTML += 'RE: ';
|
||||
quote.appendChild(a);
|
||||
|
||||
doc.body.appendChild(quote);
|
||||
}
|
||||
|
||||
return inline ? doc.body.innerHTML : `<p>${doc.body.innerHTML}</p>`;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user