mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
remove unused async from toMastoApiHtml / fromMastoApiHtml
This commit is contained in:
parent
8d67a8c9ae
commit
fbdee815da
2 changed files with 37 additions and 37 deletions
|
@ -179,7 +179,7 @@ export class MfmService {
|
|||
break;
|
||||
}
|
||||
|
||||
// this is here only to catch upstream changes!
|
||||
// this is here only to catch upstream changes!
|
||||
case 'ruby--': {
|
||||
let ruby: [string, string][] = [];
|
||||
for (const child of node.childNodes) {
|
||||
|
@ -584,9 +584,10 @@ export class MfmService {
|
|||
}
|
||||
|
||||
// the toMastoApiHtml function was taken from Iceshrimp and written by zotan and modified by marie to work with the current MK version
|
||||
// additionally modified by hazelnoot to remove async
|
||||
|
||||
@bindThis
|
||||
public async toMastoApiHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
|
||||
public toMastoApiHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
|
||||
if (nodes == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -597,50 +598,50 @@ export class MfmService {
|
|||
|
||||
const body = doc.createElement('p');
|
||||
|
||||
async function appendChildren(children: mfm.MfmNode[], targetElement: any): Promise<void> {
|
||||
function appendChildren(children: mfm.MfmNode[], targetElement: any): void {
|
||||
if (children) {
|
||||
for (const child of await Promise.all(children.map(async (x) => await (handlers as any)[x.type](x)))) targetElement.appendChild(child);
|
||||
for (const child of children.map((x) => (handlers as any)[x.type](x))) targetElement.appendChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
const handlers: {
|
||||
[K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any;
|
||||
} = {
|
||||
async bold(node) {
|
||||
bold(node) {
|
||||
const el = doc.createElement('span');
|
||||
el.textContent = '**';
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
el.textContent += '**';
|
||||
return el;
|
||||
},
|
||||
|
||||
async small(node) {
|
||||
small(node) {
|
||||
const el = doc.createElement('small');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
async strike(node) {
|
||||
strike(node) {
|
||||
const el = doc.createElement('span');
|
||||
el.textContent = '~~';
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
el.textContent += '~~';
|
||||
return el;
|
||||
},
|
||||
|
||||
async italic(node) {
|
||||
italic(node) {
|
||||
const el = doc.createElement('span');
|
||||
el.textContent = '*';
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
el.textContent += '*';
|
||||
return el;
|
||||
},
|
||||
|
||||
async fn(node) {
|
||||
fn(node) {
|
||||
switch (node.props.name) {
|
||||
case 'group': { // hack for ruby
|
||||
const el = doc.createElement('span');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
}
|
||||
case 'ruby': {
|
||||
|
@ -666,7 +667,7 @@ export class MfmService {
|
|||
|
||||
if (!rt) {
|
||||
const el = doc.createElement('span');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
}
|
||||
|
||||
|
@ -679,7 +680,7 @@ export class MfmService {
|
|||
const rpEndEl = doc.createElement('rp');
|
||||
rpEndEl.appendChild(doc.createTextNode(')'));
|
||||
|
||||
await appendChildren(node.children.slice(0, node.children.length - 1), rubyEl);
|
||||
appendChildren(node.children.slice(0, node.children.length - 1), rubyEl);
|
||||
rtEl.appendChild(doc.createTextNode(text.trim()));
|
||||
rubyEl.appendChild(rpStartEl);
|
||||
rubyEl.appendChild(rtEl);
|
||||
|
@ -691,7 +692,7 @@ export class MfmService {
|
|||
default: {
|
||||
const el = doc.createElement('span');
|
||||
el.textContent = '*';
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
el.textContent += '*';
|
||||
return el;
|
||||
}
|
||||
|
@ -714,9 +715,9 @@ export class MfmService {
|
|||
return pre;
|
||||
},
|
||||
|
||||
async center(node) {
|
||||
center(node) {
|
||||
const el = doc.createElement('div');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
@ -755,16 +756,16 @@ export class MfmService {
|
|||
return el;
|
||||
},
|
||||
|
||||
async link(node) {
|
||||
link(node) {
|
||||
const a = doc.createElement('a');
|
||||
a.setAttribute('rel', 'nofollow noopener noreferrer');
|
||||
a.setAttribute('target', '_blank');
|
||||
a.setAttribute('href', node.props.url);
|
||||
await appendChildren(node.children, a);
|
||||
appendChildren(node.children, a);
|
||||
return a;
|
||||
},
|
||||
|
||||
async mention(node) {
|
||||
mention(node) {
|
||||
const { username, host, acct } = node.props;
|
||||
const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
||||
|
||||
|
@ -787,9 +788,9 @@ export class MfmService {
|
|||
return el;
|
||||
},
|
||||
|
||||
async quote(node) {
|
||||
quote(node) {
|
||||
const el = doc.createElement('blockquote');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
|
||||
|
@ -822,14 +823,14 @@ export class MfmService {
|
|||
return a;
|
||||
},
|
||||
|
||||
async plain(node) {
|
||||
plain(node) {
|
||||
const el = doc.createElement('span');
|
||||
await appendChildren(node.children, el);
|
||||
appendChildren(node.children, el);
|
||||
return el;
|
||||
},
|
||||
};
|
||||
|
||||
await appendChildren(nodes, body);
|
||||
appendChildren(nodes, body);
|
||||
|
||||
if (quoteUri !== null) {
|
||||
const a = doc.createElement('a');
|
||||
|
|
|
@ -135,10 +135,10 @@ export class MastoConverters {
|
|||
});
|
||||
}
|
||||
|
||||
private async encodeField(f: Entity.Field): Promise<MastodonEntity.Field> {
|
||||
private encodeField(f: Entity.Field): MastodonEntity.Field {
|
||||
return {
|
||||
name: f.name,
|
||||
value: await this.mfmService.toMastoApiHtml(mfm.parse(f.value), [], true) ?? escapeMFM(f.value),
|
||||
value: this.mfmService.toMastoApiHtml(mfm.parse(f.value), [], true) ?? escapeMFM(f.value),
|
||||
verified_at: null,
|
||||
};
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ export class MastoConverters {
|
|||
header_static: user.bannerUrl ? user.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
|
||||
emojis: emoji,
|
||||
moved: null, //FIXME
|
||||
fields: Promise.all(profile?.fields.map(async p => this.encodeField(p)) ?? []),
|
||||
fields: profile?.fields.map(p => this.encodeField(p)) ?? [],
|
||||
bot: user.isBot,
|
||||
discoverable: user.isExplorable,
|
||||
noindex: user.noindex,
|
||||
|
@ -203,23 +203,23 @@ export class MastoConverters {
|
|||
}
|
||||
const noteUser = await this.getUser(note.userId).then(async (p) => await this.convertAccount(p));
|
||||
const edits = await this.noteEditRepository.find({ where: { noteId: note.id }, order: { id: 'ASC' } });
|
||||
const history: Promise<StatusEdit>[] = [];
|
||||
const history: StatusEdit[] = [];
|
||||
|
||||
// TODO this looks wrong, according to mastodon docs
|
||||
let lastDate = this.idService.parse(note.id).date;
|
||||
for (const edit of edits) {
|
||||
const files = this.driveFileEntityService.packManyByIds(edit.fileIds);
|
||||
const files = await this.driveFileEntityService.packManyByIds(edit.fileIds);
|
||||
const item = {
|
||||
account: noteUser,
|
||||
content: this.mfmService.toMastoApiHtml(mfm.parse(edit.newText ?? ''), JSON.parse(note.mentionedRemoteUsers)).then(p => p ?? ''),
|
||||
content: this.mfmService.toMastoApiHtml(mfm.parse(edit.newText ?? ''), JSON.parse(note.mentionedRemoteUsers)) ?? '',
|
||||
created_at: lastDate.toISOString(),
|
||||
emojis: [],
|
||||
sensitive: edit.cw != null && edit.cw.length > 0,
|
||||
spoiler_text: edit.cw ?? '',
|
||||
media_attachments: files.then(files => files.length > 0 ? files.map((f) => this.encodeFile(f)) : []),
|
||||
media_attachments: files.length > 0 ? files.map((f) => this.encodeFile(f)) : [],
|
||||
};
|
||||
lastDate = edit.updatedAt;
|
||||
history.push(awaitAll(item));
|
||||
history.push(item);
|
||||
}
|
||||
|
||||
return await Promise.all(history);
|
||||
|
@ -275,8 +275,7 @@ export class MastoConverters {
|
|||
const text = note.text;
|
||||
const content = text !== null
|
||||
? quoteUri
|
||||
.then(quoteUri => this.mfmService.toMastoApiHtml(mfm.parse(text), mentionedRemoteUsers, false, quoteUri))
|
||||
.then(p => p ?? escapeMFM(text))
|
||||
.then(quoteUri => this.mfmService.toMastoApiHtml(mfm.parse(text), mentionedRemoteUsers, false, quoteUri) ?? escapeMFM(text))
|
||||
: '';
|
||||
|
||||
const reblogged = await this.mastodonDataService.hasReblog(note.id, me);
|
||||
|
|
Loading…
Add table
Reference in a new issue