upd: add quoteUri resolving and correct reblog/quote handling

This commit is contained in:
Mar0xy 2023-10-29 12:49:41 +01:00
parent c53323d237
commit b596a4978f
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828

View file

@ -192,6 +192,11 @@ export class MastoConverters {
return await Promise.all(history); return await Promise.all(history);
} }
private async convertReblog(status: Entity.Status | null): Promise<any> {
if (!status) return null;
return await this.convertStatus(status);
}
public async convertStatus(status: Entity.Status) { public async convertStatus(status: Entity.Status) {
const convertedAccount = this.convertAccount(status.account); const convertedAccount = this.convertAccount(status.account);
const note = await this.getterService.getNote(status.id); const note = await this.getterService.getNote(status.id);
@ -216,11 +221,6 @@ export class MastoConverters {
.catch(() => null))) .catch(() => null)))
.then(p => p.filter(m => m)) as Promise<Entity.Mention[]>; .then(p => p.filter(m => m)) as Promise<Entity.Mention[]>;
const content = note.text !== null
? this.mfmService.toMastoHtml(mfm.parse(note.text!), JSON.parse(note.mentionedRemoteUsers), false, null)
.then(p => p ?? escapeMFM(note.text!))
: '';
const tags = note.tags.map(tag => { const tags = note.tags.map(tag => {
return { return {
name: tag, name: tag,
@ -228,6 +228,20 @@ export class MastoConverters {
} as Entity.Tag; } as Entity.Tag;
}); });
const isQuote = note.renoteId && note.text ? true : false;
const renote = note.renoteId ? this.getterService.getNote(note.renoteId) : null;
const quoteUri = Promise.resolve(renote).then(renote => {
if (!renote || !isQuote) return null;
return renote.url ?? renote.uri ?? `${this.config.url}/notes/${renote.id}`;
});
const content = note.text !== null
? quoteUri.then(quoteUri => this.mfmService.toMastoHtml(mfm.parse(note.text!), JSON.parse(note.mentionedRemoteUsers), false, quoteUri))
.then(p => p ?? escapeMFM(note.text!))
: '';
// noinspection ES6MissingAwait // noinspection ES6MissingAwait
return await awaitAll({ return await awaitAll({
id: note.id, id: note.id,
@ -236,7 +250,7 @@ export class MastoConverters {
account: convertedAccount, account: convertedAccount,
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: status.reblog, reblog: !isQuote ? await this.convertReblog(status.reblog) : null,
content: content, content: content,
content_type: 'text/x.misskeymarkdown', content_type: 'text/x.misskeymarkdown',
text: note.text, text: note.text,
@ -262,7 +276,7 @@ export class MastoConverters {
reactions: status.emoji_reactions, reactions: status.emoji_reactions,
emoji_reactions: status.emoji_reactions, emoji_reactions: status.emoji_reactions,
bookmarked: false, bookmarked: false,
quote: false, quote: isQuote ? await this.convertReblog(status.reblog) : null,
edited_at: note.updatedAt?.toISOString(), edited_at: note.updatedAt?.toISOString(),
}); });
} }