forked from FoundKeyGang/FoundKey
add check if ids.length > 0 before executing query
This commit is contained in:
parent
19e29c3465
commit
199622b415
1 changed files with 21 additions and 19 deletions
|
@ -105,26 +105,28 @@ export async function toHtml(mfmText: string, mentions?: string[]): Promise<stri
|
||||||
async mention(node): Promise<HTMLElement | Text> {
|
async mention(node): Promise<HTMLElement | Text> {
|
||||||
const { username, host, acct } = node.props;
|
const { username, host, acct } = node.props;
|
||||||
const ids = mentions ?? extractMentions(nodes);
|
const ids = mentions ?? extractMentions(nodes);
|
||||||
const mentionedUsers = await UserProfiles.createQueryBuilder('user_profile')
|
if (ids.length > 0) {
|
||||||
.leftJoin('user_profile.user', 'user')
|
const mentionedUsers = await UserProfiles.createQueryBuilder('user_profile')
|
||||||
.select('user.username')
|
.leftJoin('user_profile.user', 'user')
|
||||||
.addSelect('user.host')
|
.select('user.username')
|
||||||
// links should preferably use user friendly urls, only fall back to AP ids
|
.addSelect('user.host')
|
||||||
.addSelect('COALESCE(user_profile.url, user.uri)', 'url')
|
// links should preferably use user friendly urls, only fall back to AP ids
|
||||||
.where('userId IN (:...ids)', { ids })
|
.addSelect('COALESCE(user_profile.url, user.uri)', 'url')
|
||||||
.getMany();
|
.where('"userId" IN (:...ids)', { ids })
|
||||||
const userInfo = mentionedUsers.find(user => user.user?.username === username && user.userHost === host);
|
.getMany();
|
||||||
if (userInfo != null) {
|
const userInfo = mentionedUsers.find(user => user.user?.username === username && user.userHost === host);
|
||||||
// Mastodon microformat: span.h-card > a.u-url.mention
|
if (userInfo != null) {
|
||||||
const a = doc.createElement('a');
|
// Mastodon microformat: span.h-card > a.u-url.mention
|
||||||
a.href = userInfo.url ?? `${config.url}/${acct}`;
|
const a = doc.createElement('a');
|
||||||
a.className = 'u-url mention';
|
a.href = userInfo.url ?? `${config.url}/${acct}`;
|
||||||
a.textContent = acct;
|
a.className = 'u-url mention';
|
||||||
|
a.textContent = acct;
|
||||||
|
|
||||||
const card = doc.createElement('span');
|
const card = doc.createElement('span');
|
||||||
card.className = 'h-card';
|
card.className = 'h-card';
|
||||||
card.appendChild(a);
|
card.appendChild(a);
|
||||||
return card;
|
return card;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// this user does not actually exist
|
// this user does not actually exist
|
||||||
return doc.createTextNode(acct);
|
return doc.createTextNode(acct);
|
||||||
|
|
Loading…
Reference in a new issue