summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-02-11 10:52:52 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-11 10:52:52 -0500
commitfeb80ee992c8cf2d719b089023b1352052aaad2d (patch)
treed4559dc61e763b8b431abeaa8e0a3c30663dadaf /packages/backend/src/core
parentMerge branch 'develop' into merge/2024-02-03 (diff)
parentmerge: Cleanup and bulk fixes to Mastodon API (resolves #495, #509, #707, #7... (diff)
downloadsharkey-feb80ee992c8cf2d719b089023b1352052aaad2d.tar.gz
sharkey-feb80ee992c8cf2d719b089023b1352052aaad2d.tar.bz2
sharkey-feb80ee992c8cf2d719b089023b1352052aaad2d.zip
Merge branch 'develop' into merge/2024-02-03
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/activitypub/ApRequestService.ts15
-rw-r--r--packages/backend/src/core/activitypub/type.ts11
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts50
3 files changed, 72 insertions, 4 deletions
diff --git a/packages/backend/src/core/activitypub/ApRequestService.ts b/packages/backend/src/core/activitypub/ApRequestService.ts
index bcd0ce9043..6291768e8c 100644
--- a/packages/backend/src/core/activitypub/ApRequestService.ts
+++ b/packages/backend/src/core/activitypub/ApRequestService.ts
@@ -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)) {
diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts
index 21eff4ddb7..4e0f131647 100644
--- a/packages/backend/src/core/activitypub/type.ts
+++ b/packages/backend/src/core/activitypub/type.ts
@@ -57,9 +57,16 @@ export function getOneApId(value: ApObject): string {
}
/**
+ * 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);
diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts
index 6ea2d6629a..ef0b5213c8 100644
--- a/packages/backend/src/core/entities/UserEntityService.ts
+++ b/packages/backend/src/core/entities/UserEntityService.ts
@@ -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,
},
];
}),