server: refactor packing User

This commit is contained in:
Johann150 2023-02-11 19:17:11 +01:00
parent 3a7e8cfe50
commit c9d395961e
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -270,16 +270,14 @@ export const UserRepository = db.getRepository(User).extend({
const followingCount = profile == null ? null : const followingCount = profile == null ? null :
(profile.ffVisibility === 'public') || isMe ? user.followingCount : (profile.ffVisibility === 'public') || isMe ? user.followingCount :
(profile.ffVisibility === 'followers') && (relation && relation.isFollowing) ? user.followingCount : (profile.ffVisibility === 'followers') && relation?.isFollowing ? user.followingCount :
null; null;
const followersCount = profile == null ? null : const followersCount = profile == null ? null :
(profile.ffVisibility === 'public') || isMe ? user.followersCount : (profile.ffVisibility === 'public') || isMe ? user.followersCount :
(profile.ffVisibility === 'followers') && (relation && relation.isFollowing) ? user.followersCount : (profile.ffVisibility === 'followers') && relation?.isFollowing ? user.followersCount :
null; null;
const falsy = opts.detail ? false : undefined;
const packed = { const packed = {
id: user.id, id: user.id,
name: user.name, name: user.name,
@ -287,10 +285,10 @@ export const UserRepository = db.getRepository(User).extend({
host: user.host, host: user.host,
avatarUrl: this.getAvatarUrlSync(user), avatarUrl: this.getAvatarUrlSync(user),
avatarBlurhash: user.avatar?.blurhash || null, avatarBlurhash: user.avatar?.blurhash || null,
isAdmin: user.isAdmin || falsy, isAdmin: user.isAdmin,
isModerator: user.isModerator || falsy, isModerator: user.isModerator,
isBot: user.isBot || falsy, isBot: user.isBot,
isCat: user.isCat || falsy, isCat: user.isCat,
instance: !user.host ? undefined : userInstanceCache.fetch(user.host) instance: !user.host ? undefined : userInstanceCache.fetch(user.host)
.then(instance => !instance ? undefined : { .then(instance => !instance ? undefined : {
name: instance.name, name: instance.name,
@ -312,8 +310,8 @@ export const UserRepository = db.getRepository(User).extend({
bannerUrl: user.banner ? DriveFiles.getPublicUrl(user.banner, false) : null, bannerUrl: user.banner ? DriveFiles.getPublicUrl(user.banner, false) : null,
bannerBlurhash: user.banner?.blurhash || null, bannerBlurhash: user.banner?.blurhash || null,
isLocked: user.isLocked, isLocked: user.isLocked,
isSilenced: user.isSilenced || falsy, isSilenced: user.isSilenced,
isSuspended: user.isSuspended || falsy, isSuspended: user.isSuspended,
description: profile!.description, description: profile!.description,
location: profile!.location, location: profile!.location,
birthday: profile!.birthday, birthday: profile!.birthday,
@ -369,7 +367,7 @@ export const UserRepository = db.getRepository(User).extend({
mutedInstances: profile!.mutedInstances, mutedInstances: profile!.mutedInstances,
mutingNotificationTypes: profile!.mutingNotificationTypes, mutingNotificationTypes: profile!.mutingNotificationTypes,
emailNotificationTypes: profile!.emailNotificationTypes, emailNotificationTypes: profile!.emailNotificationTypes,
showTimelineReplies: user.showTimelineReplies || falsy, showTimelineReplies: user.showTimelineReplies,
federateBlocks: user!.federateBlocks, federateBlocks: user!.federateBlocks,
} : {}), } : {}),