summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-03-22 18:18:10 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-03-27 19:51:43 -0400
commitfbdee815dabd5444c9e6b0b91d2a9b5b21b1ca6e (patch)
tree8fc2e7efc176739dcb6ceb767553a1e2575a3586
parentdon't log query parameters from mastodon API (diff)
downloadsharkey-fbdee815dabd5444c9e6b0b91d2a9b5b21b1ca6e.tar.gz
sharkey-fbdee815dabd5444c9e6b0b91d2a9b5b21b1ca6e.tar.bz2
sharkey-fbdee815dabd5444c9e6b0b91d2a9b5b21b1ca6e.zip
remove unused async from toMastoApiHtml / fromMastoApiHtml
-rw-r--r--packages/backend/src/core/MfmService.ts55
-rw-r--r--packages/backend/src/server/api/mastodon/converters.ts19
2 files changed, 37 insertions, 37 deletions
diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts
index 6c2f673217..dcec71805e 100644
--- a/packages/backend/src/core/MfmService.ts
+++ b/packages/backend/src/core/MfmService.ts
@@ -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');
diff --git a/packages/backend/src/server/api/mastodon/converters.ts b/packages/backend/src/server/api/mastodon/converters.ts
index 9d8e031831..0e468f9377 100644
--- a/packages/backend/src/server/api/mastodon/converters.ts
+++ b/packages/backend/src/server/api/mastodon/converters.ts
@@ -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);