fix: avatarId が null のときにも avatarUrl が non null 担ってることがある問題 (#15833)

This commit is contained in:
anatawa12 2025-04-15 16:10:17 +09:00 committed by GitHub
parent 6bd45a27b1
commit d5fe6e36ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 11 deletions

View File

@ -411,8 +411,8 @@ export class WebhookTestService {
name: user.name, name: user.name,
username: user.username, username: user.username,
host: user.host, host: user.host,
avatarUrl: user.avatarUrl, avatarUrl: user.avatarId == null ? null : user.avatarUrl,
avatarBlurhash: user.avatarBlurhash, avatarBlurhash: user.avatarId == null ? null : user.avatarBlurhash,
avatarDecorations: user.avatarDecorations.map(it => ({ avatarDecorations: user.avatarDecorations.map(it => ({
id: it.id, id: it.id,
angle: it.angle, angle: it.angle,
@ -441,8 +441,8 @@ export class WebhookTestService {
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
updatedAt: user.updatedAt?.toISOString() ?? null, updatedAt: user.updatedAt?.toISOString() ?? null,
lastFetchedAt: user.lastFetchedAt?.toISOString() ?? null, lastFetchedAt: user.lastFetchedAt?.toISOString() ?? null,
bannerUrl: user.bannerUrl, bannerUrl: user.bannerId == null ? null : user.bannerUrl,
bannerBlurhash: user.bannerBlurhash, bannerBlurhash: user.bannerId == null ? null : user.bannerBlurhash,
isLocked: user.isLocked, isLocked: user.isLocked,
isSilenced: false, isSilenced: false,
isSuspended: user.isSuspended, isSuspended: user.isSuspended,

View File

@ -486,8 +486,8 @@ export class UserEntityService implements OnModuleInit {
name: user.name, name: user.name,
username: user.username, username: user.username,
host: user.host, host: user.host,
avatarUrl: user.avatarUrl ?? this.getIdenticonUrl(user), avatarUrl: (user.avatarId == null ? null : user.avatarUrl) ?? this.getIdenticonUrl(user),
avatarBlurhash: user.avatarBlurhash, avatarBlurhash: (user.avatarId == null ? null : user.avatarBlurhash),
avatarDecorations: user.avatarDecorations.length > 0 ? this.avatarDecorationService.getAll().then(decorations => user.avatarDecorations.filter(ud => decorations.some(d => d.id === ud.id)).map(ud => ({ avatarDecorations: user.avatarDecorations.length > 0 ? this.avatarDecorationService.getAll().then(decorations => user.avatarDecorations.filter(ud => decorations.some(d => d.id === ud.id)).map(ud => ({
id: ud.id, id: ud.id,
angle: ud.angle || undefined, angle: ud.angle || undefined,
@ -533,8 +533,8 @@ export class UserEntityService implements OnModuleInit {
createdAt: this.idService.parse(user.id).date.toISOString(), createdAt: this.idService.parse(user.id).date.toISOString(),
updatedAt: user.updatedAt ? user.updatedAt.toISOString() : null, updatedAt: user.updatedAt ? user.updatedAt.toISOString() : null,
lastFetchedAt: user.lastFetchedAt ? user.lastFetchedAt.toISOString() : null, lastFetchedAt: user.lastFetchedAt ? user.lastFetchedAt.toISOString() : null,
bannerUrl: user.bannerUrl, bannerUrl: user.bannerId == null ? null : user.bannerUrl,
bannerBlurhash: user.bannerBlurhash, bannerBlurhash: user.bannerId == null ? null : user.bannerBlurhash,
isLocked: user.isLocked, isLocked: user.isLocked,
isSilenced: this.roleService.getUserPolicies(user.id).then(r => !r.canPublicNote), isSilenced: this.roleService.getUserPolicies(user.id).then(r => !r.canPublicNote),
isSuspended: user.isSuspended, isSuspended: user.isSuspended,

View File

@ -118,21 +118,25 @@ export class MiUser {
@JoinColumn() @JoinColumn()
public banner: MiDriveFile | null; public banner: MiDriveFile | null;
// avatarId が null になったとしてもこれが null でない可能性があるため、このフィールドを使うときは avatarId の non-null チェックをすること
@Column('varchar', { @Column('varchar', {
length: 512, nullable: true, length: 512, nullable: true,
}) })
public avatarUrl: string | null; public avatarUrl: string | null;
// bannerId が null になったとしてもこれが null でない可能性があるため、このフィールドを使うときは bannerId の non-null チェックをすること
@Column('varchar', { @Column('varchar', {
length: 512, nullable: true, length: 512, nullable: true,
}) })
public bannerUrl: string | null; public bannerUrl: string | null;
// avatarId が null になったとしてもこれが null でない可能性があるため、このフィールドを使うときは avatarId の non-null チェックをすること
@Column('varchar', { @Column('varchar', {
length: 128, nullable: true, length: 128, nullable: true,
}) })
public avatarBlurhash: string | null; public avatarBlurhash: string | null;
// bannerId が null になったとしてもこれが null でない可能性があるため、このフィールドを使うときは bannerId の non-null チェックをすること
@Column('varchar', { @Column('varchar', {
length: 128, nullable: true, length: 128, nullable: true,
}) })

View File

@ -221,7 +221,7 @@ export class ServerService implements OnApplicationShutdown {
reply.header('Cache-Control', 'public, max-age=86400'); reply.header('Cache-Control', 'public, max-age=86400');
if (user) { if (user) {
reply.redirect(user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user)); reply.redirect((user.avatarId == null ? null : user.avatarUrl) ?? this.userEntityService.getIdenticonUrl(user));
} else { } else {
reply.redirect('/static-assets/user-unknown.png'); reply.redirect('/static-assets/user-unknown.png');
} }

View File

@ -534,7 +534,7 @@ export class ClientServerService {
return await reply.view('user', { return await reply.view('user', {
user, profile, me, user, profile, me,
avatarUrl: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user), avatarUrl: _user.avatarUrl,
sub: request.params.sub, sub: request.params.sub,
...await this.generateCommonPugData(this.meta), ...await this.generateCommonPugData(this.meta),
clientCtx: htmlSafeJsonStringify({ clientCtx: htmlSafeJsonStringify({

View File

@ -65,7 +65,7 @@ export class FeedService {
generator: 'Misskey', generator: 'Misskey',
description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`, description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
link: author.link, link: author.link,
image: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user), image: (user.avatarId == null ? null : user.avatarUrl) ?? this.userEntityService.getIdenticonUrl(user),
feedLinks: { feedLinks: {
json: `${author.link}.json`, json: `${author.link}.json`,
atom: `${author.link}.atom`, atom: `${author.link}.atom`,