mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	add memo and isInstanceMuted to UserRelation API entity
				
					
				
			This commit is contained in:
		
							parent
							
								
									02e90e23b7
								
							
						
					
					
						commit
						5a1d1394d4
					
				
					 2 changed files with 66 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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,
 | 
			
		||||
					},
 | 
			
		||||
				];
 | 
			
		||||
			}),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue