forked from mirrors/iceshrimp
[mastodon-client] Rework quote rendering
This commit is contained in:
parent
775d8f6e3a
commit
2830953862
|
@ -87,14 +87,16 @@ export class NoteConverter {
|
||||||
.catch(() => null)))
|
.catch(() => null)))
|
||||||
.then(p => p.filter(m => m)) as Promise<MastodonEntity.Mention[]>;
|
.then(p => p.filter(m => m)) as Promise<MastodonEntity.Mention[]>;
|
||||||
|
|
||||||
const text = Promise.resolve(renote).then(renote => {
|
const quoteUri = Promise.resolve(renote).then(renote => {
|
||||||
if (!renote || note.text === null) return note.text
|
if (!renote || note.text === null) return null;
|
||||||
const uri = renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`;
|
return renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`;
|
||||||
return note.text.includes(uri)
|
|
||||||
? note.text
|
|
||||||
: note.text + `\n\nRE: ${uri}`;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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
|
const isPinned = user && note.userId === user.id
|
||||||
? UserNotePinings.exist({ where: { userId: user.id, noteId: note.id } })
|
? UserNotePinings.exist({ where: { userId: user.id, noteId: note.id } })
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -117,9 +119,9 @@ export class NoteConverter {
|
||||||
in_reply_to_id: note.replyId,
|
in_reply_to_id: note.replyId,
|
||||||
in_reply_to_account_id: note.replyUserId,
|
in_reply_to_account_id: note.replyUserId,
|
||||||
reblog: reblog.then(reblog => note.text === null ? reblog : null),
|
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',
|
content_type: 'text/x.misskeymarkdown',
|
||||||
text: text,
|
text: note.text,
|
||||||
created_at: note.createdAt.toISOString(),
|
created_at: note.createdAt.toISOString(),
|
||||||
emojis: noteEmoji,
|
emojis: noteEmoji,
|
||||||
replies_count: note.repliesCount,
|
replies_count: note.repliesCount,
|
||||||
|
|
|
@ -10,7 +10,8 @@ export class MfmHelpers {
|
||||||
nodes: mfm.MfmNode[] | null,
|
nodes: mfm.MfmNode[] | null,
|
||||||
mentionedRemoteUsers: IMentionedRemoteUsers = [],
|
mentionedRemoteUsers: IMentionedRemoteUsers = [],
|
||||||
objectHost: string | null,
|
objectHost: string | null,
|
||||||
inline: boolean = false
|
inline: boolean = false,
|
||||||
|
quoteUri: string | null = null
|
||||||
) {
|
) {
|
||||||
if (nodes == null) {
|
if (nodes == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -194,6 +195,21 @@ export class MfmHelpers {
|
||||||
|
|
||||||
await appendChildren(nodes, doc.body);
|
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>`;
|
return inline ? doc.body.innerHTML : `<p>${doc.body.innerHTML}</p>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue