Merge branch 'develop' into merge/2024-02-03

This commit is contained in:
Hazelnoot 2025-02-11 10:52:52 -05:00
commit feb80ee992
42 changed files with 1707 additions and 1351 deletions

View file

@ -185,7 +185,7 @@ export class ApRequestService {
* @param url URL to fetch
*/
@bindThis
public async signedGet(url: string, user: { id: MiUser['id'] }, followAlternate?: boolean): Promise<unknown> {
public async signedGet(url: string, user: { id: MiUser['id'] }, followAlternate?: boolean): Promise<object> {
const _followAlternate = followAlternate ?? true;
const keypair = await this.userKeypairService.getUserKeypair(user.id);
@ -239,7 +239,18 @@ export class ApRequestService {
try {
document.documentElement.innerHTML = html;
const alternate = document.querySelector('head > link[rel="alternate"][type="application/activity+json"]');
// Search for any matching value in priority order:
// 1. Type=AP > Type=none > Type=anything
// 2. Alternate > Canonical
// 3. Page order (fallback)
const alternate =
document.querySelector('head > link[href][rel="alternate"][type="application/activity+json"]') ??
document.querySelector('head > link[href][rel="canonical"][type="application/activity+json"]') ??
document.querySelector('head > link[href][rel="alternate"]:not([type])') ??
document.querySelector('head > link[href][rel="canonical"]:not([type])') ??
document.querySelector('head > link[href][rel="alternate"]') ??
document.querySelector('head > link[href][rel="canonical"]');
if (alternate) {
const href = alternate.getAttribute('href');
if (href && this.utilityService.punyHostPSLDomain(url) === this.utilityService.punyHostPSLDomain(href)) {

View file

@ -56,10 +56,17 @@ export function getOneApId(value: ApObject): string {
return getApId(firstOne);
}
/**
* Minimal AP payload - just an object with optional ID.
*/
export interface ObjectWithId {
id?: string;
}
/**
* Get ActivityStreams Object id
*/
export function getApId(value: string | IObject | [string | IObject]): string {
export function getApId(value: string | ObjectWithId | [string | ObjectWithId]): string {
// eslint-disable-next-line no-param-reassign
value = fromTuple(value);
@ -71,7 +78,7 @@ export function getApId(value: string | IObject | [string | IObject]): string {
/**
* Get ActivityStreams Object id, or null if not present
*/
export function getNullableApId(value: string | IObject | [string | IObject]): string | null {
export function getNullableApId(value: string | ObjectWithId | [string | ObjectWithId]): string | null {
// eslint-disable-next-line no-param-reassign
value = fromTuple(value);

View file

@ -83,6 +83,8 @@ export type UserRelation = {
isBlocked: boolean
isMuted: boolean
isRenoteMuted: boolean
isInstanceMuted?: boolean
memo?: string | null
}
@Injectable()
@ -182,6 +184,9 @@ export class UserEntityService implements OnModuleInit {
isBlocked,
isMuted,
isRenoteMuted,
host,
memo,
mutedInstances,
] = await Promise.all([
this.followingsRepository.findOneBy({
followerId: me,
@ -229,8 +234,25 @@ export class UserEntityService implements OnModuleInit {
muteeId: target,
},
}),
this.usersRepository.createQueryBuilder('u')
.select('u.host')
.where({ id: target })
.getRawOne<{ u_host: string }>()
.then(it => it?.u_host ?? null),
this.userMemosRepository.createQueryBuilder('m')
.select('m.memo')
.where({ userId: me, targetUserId: target })
.getRawOne<{ m_memo: string | null }>()
.then(it => it?.m_memo ?? null),
this.userProfilesRepository.createQueryBuilder('p')
.select('p.mutedInstances')
.where({ userId: me })
.getRawOne<{ p_mutedInstances: string[] }>()
.then(it => it?.p_mutedInstances ?? []),
]);
const isInstanceMuted = !!host && mutedInstances.includes(host);
return {
id: target,
following,
@ -242,6 +264,8 @@ export class UserEntityService implements OnModuleInit {
isBlocked,
isMuted,
isRenoteMuted,
isInstanceMuted,
memo,
};
}
@ -256,6 +280,9 @@ export class UserEntityService implements OnModuleInit {
blockees,
muters,
renoteMuters,
hosts,
memos,
mutedInstances,
] = await Promise.all([
this.followingsRepository.findBy({ followerId: me })
.then(f => new Map(f.map(it => [it.followeeId, it]))),
@ -294,6 +321,27 @@ export class UserEntityService implements OnModuleInit {
.where('m.muterId = :me', { me })
.getRawMany<{ m_muteeId: string }>()
.then(it => it.map(it => it.m_muteeId)),
this.usersRepository.createQueryBuilder('u')
.select(['u.id', 'u.host'])
.where({ id: In(targets) } )
.getRawMany<{ m_id: string, m_host: string }>()
.then(it => it.reduce((map, it) => {
map[it.m_id] = it.m_host;
return map;
}, {} as Record<string, string>)),
this.userMemosRepository.createQueryBuilder('m')
.select(['m.targetUserId', 'm.memo'])
.where({ userId: me, targetUserId: In(targets) })
.getRawMany<{ m_targetUserId: string, m_memo: string | null }>()
.then(it => it.reduce((map, it) => {
map[it.m_targetUserId] = it.m_memo;
return map;
}, {} as Record<string, string | null>)),
this.userProfilesRepository.createQueryBuilder('p')
.select('p.mutedInstances')
.where({ userId: me })
.getRawOne<{ p_mutedInstances: string[] }>()
.then(it => it?.p_mutedInstances ?? []),
]);
return new Map(
@ -313,6 +361,8 @@ export class UserEntityService implements OnModuleInit {
isBlocked: blockees.includes(target),
isMuted: muters.includes(target),
isRenoteMuted: renoteMuters.includes(target),
isInstanceMuted: mutedInstances.includes(hosts[target]),
memo: memos[target] ?? null,
},
];
}),