Skip to content

Commit

Permalink
Remove unnecessary nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
woxtu committed Oct 17, 2023
1 parent 5a3c657 commit e07efae
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class CustomEmojiService implements OnApplicationShutdown {

const queryOrNull = async () => (await this.emojisRepository.findOneBy({
name,
host: host ?? IsNull(),
host,
})) ?? null;

const emoji = await this.cache.fetch(`${name} ${host}`, queryOrNull);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/HashtagService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class HashtagService {
await this.updateHashtag(user, tag, true, true);
}

for (const tag of (user.tags ?? []).filter(x => !tags.includes(x))) {
for (const tag of user.tags.filter(x => !tags.includes(x))) {
await this.updateHashtag(user, tag, true, false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class NoteCreateService implements OnApplicationShutdown {
data.text = data.text.trim();

if (user.isCat) {
patsedText = patsedText ?? mfm.parse(data.text);
patsedText = mfm.parse(data.text);
function nyaizeNode(node: mfm.MfmNode) {
if (node.type === 'quote') return;
if (node.type === 'text') {
Expand Down Expand Up @@ -359,7 +359,7 @@ export class NoteCreateService implements OnApplicationShutdown {
mentionedUsers = data.apMentions ?? await this.extractMentionedUsers(user, combinedTokens);
}

tags = tags.filter(tag => Array.from(tag ?? '').length <= 128).splice(0, 32);
tags = tags.filter(tag => Array.from(tag).length <= 128).splice(0, 32);

if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {
mentionedUsers.push(await this.usersRepository.findOneByOrFail({ id: data.reply!.userId }));
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/ReactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class ReactionService {
reaction = FALLBACK;
}
} else {
reaction = this.normalize(reaction ?? null);
reaction = this.normalize(reaction);
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/core/entities/DriveFileEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class DriveFileEntityService {
if (file.type.startsWith('video')) {
if (file.thumbnailUrl) return file.thumbnailUrl;

return this.videoProcessingService.getExternalVideoThumbnailUrl(file.webpublicUrl ?? file.url ?? file.uri);
return this.videoProcessingService.getExternalVideoThumbnailUrl(file.webpublicUrl ?? file.url);
} else if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) {
// 動画ではなくリモートかつメディアプロキシ
return this.getProxiedUrl(file.uri, 'static');
Expand Down Expand Up @@ -145,7 +145,7 @@ export class DriveFileEntityService {
.select('SUM(file.size)', 'sum')
.getRawOne();

return parseInt(sum, 10) ?? 0;
return parseInt(sum, 10) || 0;
}

@bindThis
Expand All @@ -157,7 +157,7 @@ export class DriveFileEntityService {
.select('SUM(file.size)', 'sum')
.getRawOne();

return parseInt(sum, 10) ?? 0;
return parseInt(sum, 10) || 0;
}

@bindThis
Expand All @@ -169,7 +169,7 @@ export class DriveFileEntityService {
.select('SUM(file.size)', 'sum')
.getRawOne();

return parseInt(sum, 10) ?? 0;
return parseInt(sum, 10) || 0;
}

@bindThis
Expand All @@ -181,7 +181,7 @@ export class DriveFileEntityService {
.select('SUM(file.size)', 'sum')
.getRawOne();

return parseInt(sum, 10) ?? 0;
return parseInt(sum, 10) || 0;
}

@bindThis
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class NoteEntityService implements OnModuleInit {
text: text,
cw: note.cw,
visibility: note.visibility,
localOnly: note.localOnly ?? undefined,
localOnly: note.localOnly,
reactionAcceptance: note.reactionAcceptance,
visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined,
renoteCount: note.renoteCount,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ export class UserEntityService implements OnModuleInit {
host: user.host,
avatarUrl: user.avatarUrl ?? this.getIdenticonUrl(user),
avatarBlurhash: user.avatarBlurhash,
isBot: user.isBot ?? falsy,
isCat: user.isCat ?? falsy,
isBot: user.isBot,
isCat: user.isCat,
instance: user.host ? this.federatedInstanceService.federatedInstanceCache.fetch(user.host).then(instance => instance ? {
name: instance.name,
softwareName: instance.softwareName,
Expand Down Expand Up @@ -367,7 +367,7 @@ export class UserEntityService implements OnModuleInit {
bannerBlurhash: user.bannerBlurhash,
isLocked: user.isLocked,
isSilenced: this.roleService.getUserPolicies(user.id).then(r => !r.canPublicNote),
isSuspended: user.isSuspended ?? falsy,
isSuspended: user.isSuspended,
description: profile!.description,
location: profile!.location,
birthday: profile!.birthday,
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/daemons/ServerStatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,5 @@ async function net() {

// FS STAT
async function fs() {
const data = await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 }));
return data ?? { rIO_sec: 0, wIO_sec: 0 };
return await si.disksIO().catch(() => ({ rIO_sec: 0, wIO_sec: 0 }));
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class InboxProcessorService {
if (err.isClientError) {
throw new Bull.UnrecoverableError(`skip: Ignored deleted actors on both ends ${activity.actor} - ${err.statusCode}`);
}
throw new Error(`Error in actor ${activity.actor} - ${err.statusCode ?? err}`);
throw new Error(`Error in actor ${activity.actor} - ${err.statusCode}`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HomeTimelineChannel extends Channel {
}

// Ignore notes from instances the user has muted
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances ?? []))) return;
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances))) return;

if (note.visibility === 'followers') {
if (!Object.hasOwn(this.following, note.userId)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HybridTimelineChannel extends Channel {
}

// Ignore notes from instances the user has muted
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances ?? []))) return;
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances))) return;

// 関係ない返信は除外
if (note.reply && !this.following[note.userId]?.withReplies && !this.withReplies) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/web/FeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class FeedService {
date: this.idService.parse(note.id).date,
description: note.cw ?? undefined,
content: note.text ?? undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) ?? undefined : undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined,
});
}

Expand Down

0 comments on commit e07efae

Please sign in to comment.