forked from FoundKeyGang/FoundKey
server: refactor packing User
This commit is contained in:
parent
3a7e8cfe50
commit
c9d395961e
1 changed files with 9 additions and 11 deletions
|
@ -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,
|
||||||
} : {}),
|
} : {}),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue