summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-31 11:12:00 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-08 13:17:47 -0500
commit5a1d1394d42d116ae5bcdbda3670a9047158d42b (patch)
tree9dcaecae4156346071b7403a126a8a93c2309b77
parentfix build target for megalodon (diff)
downloadsharkey-5a1d1394d42d116ae5bcdbda3670a9047158d42b.tar.gz
sharkey-5a1d1394d42d116ae5bcdbda3670a9047158d42b.tar.bz2
sharkey-5a1d1394d42d116ae5bcdbda3670a9047158d42b.zip
add `memo` and `isInstanceMuted` to UserRelation API entity
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts50
-rw-r--r--packages/backend/src/server/api/endpoints/users/relation.ts16
2 files changed, 66 insertions, 0 deletions
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,
},
];
}),
diff --git a/packages/backend/src/server/api/endpoints/users/relation.ts b/packages/backend/src/server/api/endpoints/users/relation.ts
index e659c46713..c7016d8d32 100644
--- a/packages/backend/src/server/api/endpoints/users/relation.ts
+++ b/packages/backend/src/server/api/endpoints/users/relation.ts
@@ -58,6 +58,14 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
+ isInstanceMuted: {
+ type: 'boolean',
+ optional: true, nullable: false,
+ },
+ memo: {
+ type: 'string',
+ optional: true, nullable: true,
+ },
},
},
{
@@ -103,6 +111,14 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
+ isInstanceMuted: {
+ type: 'boolean',
+ optional: true, nullable: false,
+ },
+ memo: {
+ type: 'string',
+ optional: true, nullable: true,
+ },
},
},
},