mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is here only to catch upstream changes!
|
// this is here only to catch upstream changes!
|
||||||
case 'ruby--': {
|
case 'ruby--': {
|
||||||
let ruby: [string, string][] = [];
|
let ruby: [string, string][] = [];
|
||||||
for (const child of node.childNodes) {
|
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
|
// 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
|
@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) {
|
if (nodes == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -597,50 +598,50 @@ export class MfmService {
|
||||||
|
|
||||||
const body = doc.createElement('p');
|
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) {
|
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: {
|
const handlers: {
|
||||||
[K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any;
|
[K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any;
|
||||||
} = {
|
} = {
|
||||||
async bold(node) {
|
bold(node) {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
el.textContent = '**';
|
el.textContent = '**';
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
el.textContent += '**';
|
el.textContent += '**';
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async small(node) {
|
small(node) {
|
||||||
const el = doc.createElement('small');
|
const el = doc.createElement('small');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async strike(node) {
|
strike(node) {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
el.textContent = '~~';
|
el.textContent = '~~';
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
el.textContent += '~~';
|
el.textContent += '~~';
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async italic(node) {
|
italic(node) {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
el.textContent = '*';
|
el.textContent = '*';
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
el.textContent += '*';
|
el.textContent += '*';
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async fn(node) {
|
fn(node) {
|
||||||
switch (node.props.name) {
|
switch (node.props.name) {
|
||||||
case 'group': { // hack for ruby
|
case 'group': { // hack for ruby
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
case 'ruby': {
|
case 'ruby': {
|
||||||
|
@ -666,7 +667,7 @@ export class MfmService {
|
||||||
|
|
||||||
if (!rt) {
|
if (!rt) {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,7 +680,7 @@ export class MfmService {
|
||||||
const rpEndEl = doc.createElement('rp');
|
const rpEndEl = doc.createElement('rp');
|
||||||
rpEndEl.appendChild(doc.createTextNode(')'));
|
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()));
|
rtEl.appendChild(doc.createTextNode(text.trim()));
|
||||||
rubyEl.appendChild(rpStartEl);
|
rubyEl.appendChild(rpStartEl);
|
||||||
rubyEl.appendChild(rtEl);
|
rubyEl.appendChild(rtEl);
|
||||||
|
@ -691,7 +692,7 @@ export class MfmService {
|
||||||
default: {
|
default: {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
el.textContent = '*';
|
el.textContent = '*';
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
el.textContent += '*';
|
el.textContent += '*';
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
@ -714,9 +715,9 @@ export class MfmService {
|
||||||
return pre;
|
return pre;
|
||||||
},
|
},
|
||||||
|
|
||||||
async center(node) {
|
center(node) {
|
||||||
const el = doc.createElement('div');
|
const el = doc.createElement('div');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -755,16 +756,16 @@ export class MfmService {
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async link(node) {
|
link(node) {
|
||||||
const a = doc.createElement('a');
|
const a = doc.createElement('a');
|
||||||
a.setAttribute('rel', 'nofollow noopener noreferrer');
|
a.setAttribute('rel', 'nofollow noopener noreferrer');
|
||||||
a.setAttribute('target', '_blank');
|
a.setAttribute('target', '_blank');
|
||||||
a.setAttribute('href', node.props.url);
|
a.setAttribute('href', node.props.url);
|
||||||
await appendChildren(node.children, a);
|
appendChildren(node.children, a);
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
||||||
async mention(node) {
|
mention(node) {
|
||||||
const { username, host, acct } = node.props;
|
const { username, host, acct } = node.props;
|
||||||
const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
||||||
|
|
||||||
|
@ -787,9 +788,9 @@ export class MfmService {
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
async quote(node) {
|
quote(node) {
|
||||||
const el = doc.createElement('blockquote');
|
const el = doc.createElement('blockquote');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -822,14 +823,14 @@ export class MfmService {
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
||||||
async plain(node) {
|
plain(node) {
|
||||||
const el = doc.createElement('span');
|
const el = doc.createElement('span');
|
||||||
await appendChildren(node.children, el);
|
appendChildren(node.children, el);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await appendChildren(nodes, body);
|
appendChildren(nodes, body);
|
||||||
|
|
||||||
if (quoteUri !== null) {
|
if (quoteUri !== null) {
|
||||||
const a = doc.createElement('a');
|
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 {
|
return {
|
||||||
name: f.name,
|
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,
|
verified_at: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ export class MastoConverters {
|
||||||
header_static: user.bannerUrl ? user.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
|
header_static: user.bannerUrl ? user.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
|
||||||
emojis: emoji,
|
emojis: emoji,
|
||||||
moved: null, //FIXME
|
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,
|
bot: user.isBot,
|
||||||
discoverable: user.isExplorable,
|
discoverable: user.isExplorable,
|
||||||
noindex: user.noindex,
|
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 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 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
|
// TODO this looks wrong, according to mastodon docs
|
||||||
let lastDate = this.idService.parse(note.id).date;
|
let lastDate = this.idService.parse(note.id).date;
|
||||||
for (const edit of edits) {
|
for (const edit of edits) {
|
||||||
const files = this.driveFileEntityService.packManyByIds(edit.fileIds);
|
const files = await this.driveFileEntityService.packManyByIds(edit.fileIds);
|
||||||
const item = {
|
const item = {
|
||||||
account: noteUser,
|
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(),
|
created_at: lastDate.toISOString(),
|
||||||
emojis: [],
|
emojis: [],
|
||||||
sensitive: edit.cw != null && edit.cw.length > 0,
|
sensitive: edit.cw != null && edit.cw.length > 0,
|
||||||
spoiler_text: edit.cw ?? '',
|
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;
|
lastDate = edit.updatedAt;
|
||||||
history.push(awaitAll(item));
|
history.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Promise.all(history);
|
return await Promise.all(history);
|
||||||
|
@ -275,8 +275,7 @@ export class MastoConverters {
|
||||||
const text = note.text;
|
const text = note.text;
|
||||||
const content = text !== null
|
const content = text !== null
|
||||||
? quoteUri
|
? quoteUri
|
||||||
.then(quoteUri => this.mfmService.toMastoApiHtml(mfm.parse(text), mentionedRemoteUsers, false, quoteUri))
|
.then(quoteUri => this.mfmService.toMastoApiHtml(mfm.parse(text), mentionedRemoteUsers, false, quoteUri) ?? escapeMFM(text))
|
||||||
.then(p => p ?? escapeMFM(text))
|
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const reblogged = await this.mastodonDataService.hasReblog(note.id, me);
|
const reblogged = await this.mastodonDataService.hasReblog(note.id, me);
|
||||||
|
|
Loading…
Add table
Reference in a new issue