mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-01 08:18:05 +09:00
[mastodon-client] Fix mentions
This commit is contained in:
parent
f906ec1d55
commit
81b08bebd0
@ -1,19 +1,23 @@
|
|||||||
import { User } from "@/models/entities/user.js";
|
import { User } from "@/models/entities/user.js";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
|
import { IMentionedRemoteUsers } from "@/models/entities/note.js";
|
||||||
|
|
||||||
export class MentionConverter {
|
export class MentionConverter {
|
||||||
public static encode(u: User): MastodonEntity.Mention {
|
public static encode(u: User, m: IMentionedRemoteUsers): MastodonEntity.Mention {
|
||||||
let acct = u.username;
|
let acct = u.username;
|
||||||
let acctUrl = `https://${u.host || config.host}/@${u.username}`;
|
let acctUrl = `https://${u.host || config.host}/@${u.username}`;
|
||||||
|
let url: string | null = null;
|
||||||
if (u.host) {
|
if (u.host) {
|
||||||
|
const info = m.find(r => r.username === u.username && r.host === u.host);
|
||||||
acct = `${u.username}@${u.host}`;
|
acct = `${u.username}@${u.host}`;
|
||||||
acctUrl = `https://${u.host}/@${u.username}`;
|
acctUrl = `https://${u.host}/@${u.username}`;
|
||||||
|
if (info) url = info.url ?? info.uri;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id: u.id,
|
id: u.id,
|
||||||
username: u.username,
|
username: u.username,
|
||||||
acct: acct,
|
acct: acct,
|
||||||
url: u.uri ?? acctUrl,
|
url: url ?? acctUrl,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ export class NoteConverter {
|
|||||||
|
|
||||||
const mentions = Promise.all(note.mentions.map(p =>
|
const mentions = Promise.all(note.mentions.map(p =>
|
||||||
getUser(p)
|
getUser(p)
|
||||||
.then(u => MentionConverter.encode(u))
|
.then(u => MentionConverter.encode(u, JSON.parse(note.mentionedRemoteUsers)))
|
||||||
.catch(() => null)))
|
.catch(() => null)))
|
||||||
.then(p => p.filter(m => m)) as Promise<MastodonEntity.Mention[]>;
|
.then(p => p.filter(m => m)) as Promise<MastodonEntity.Mention[]>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user