mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-28 09:36:43 -06:00
refactor(backend): remove unnecessary isNotNull sugar
This commit is contained in:
parent
1df90cef4c
commit
bf33382082
22 changed files with 36 additions and 65 deletions
|
@ -10,7 +10,6 @@ import sanitizeHtml from 'sanitize-html';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { GlobalEvents, GlobalEventService } from '@/core/GlobalEventService.js';
|
import { GlobalEvents, GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import type {
|
import type {
|
||||||
AbuseReportNotificationRecipientRepository,
|
AbuseReportNotificationRecipientRepository,
|
||||||
MiAbuseReportNotificationRecipient,
|
MiAbuseReportNotificationRecipient,
|
||||||
|
@ -91,7 +90,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
const recipientEMailAddresses = await this.fetchEMailRecipients().then(it => it
|
const recipientEMailAddresses = await this.fetchEMailRecipients().then(it => it
|
||||||
.filter(it => it.isActive && it.userProfile?.emailVerified)
|
.filter(it => it.isActive && it.userProfile?.emailVerified)
|
||||||
.map(it => it.userProfile?.email)
|
.map(it => it.userProfile?.email)
|
||||||
.filter(isNotNull),
|
.filter(x => x != null),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 送信先の鮮度を保つため、毎回取得する
|
// 送信先の鮮度を保つため、毎回取得する
|
||||||
|
@ -138,7 +137,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
.then(it => it
|
.then(it => it
|
||||||
.filter(it => it.isActive && it.systemWebhookId && it.method === 'webhook')
|
.filter(it => it.isActive && it.systemWebhookId && it.method === 'webhook')
|
||||||
.map(it => it.systemWebhookId)
|
.map(it => it.systemWebhookId)
|
||||||
.filter(isNotNull));
|
.filter(x => x != null));
|
||||||
for (const webhookId of recipientWebhookIds) {
|
for (const webhookId of recipientWebhookIds) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
abuseReports.map(it => {
|
abuseReports.map(it => {
|
||||||
|
@ -340,7 +339,7 @@ export class AbuseReportNotificationService implements OnApplicationShutdown {
|
||||||
@bindThis
|
@bindThis
|
||||||
private async removeUnauthorizedRecipientUsers(recipients: MiAbuseReportNotificationRecipient[]): Promise<MiAbuseReportNotificationRecipient[]> {
|
private async removeUnauthorizedRecipientUsers(recipients: MiAbuseReportNotificationRecipient[]): Promise<MiAbuseReportNotificationRecipient[]> {
|
||||||
const userRecipients = recipients.filter(it => it.userId !== null);
|
const userRecipients = recipients.filter(it => it.userId !== null);
|
||||||
const recipientUserIds = new Set(userRecipients.map(it => it.userId).filter(isNotNull));
|
const recipientUserIds = new Set(userRecipients.map(it => it.userId).filter(x => x != null));
|
||||||
if (recipientUserIds.size <= 0) {
|
if (recipientUserIds.size <= 0) {
|
||||||
// ユーザが通知先として設定されていない場合、この関数での処理を行うべきレコードが無い
|
// ユーザが通知先として設定されていない場合、この関数での処理を行うべきレコードが無い
|
||||||
return recipients;
|
return recipients;
|
||||||
|
|
|
@ -59,7 +59,6 @@ import { UtilityService } from '@/core/UtilityService.js';
|
||||||
import { UserBlockingService } from '@/core/UserBlockingService.js';
|
import { UserBlockingService } from '@/core/UserBlockingService.js';
|
||||||
import { isReply } from '@/misc/is-reply.js';
|
import { isReply } from '@/misc/is-reply.js';
|
||||||
import { trackPromise } from '@/misc/promise-tracker.js';
|
import { trackPromise } from '@/misc/promise-tracker.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
|
|
||||||
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
|
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
|
||||||
|
@ -839,7 +838,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
||||||
const mentions = extractMentions(tokens);
|
const mentions = extractMentions(tokens);
|
||||||
let mentionedUsers = (await Promise.all(mentions.map(m =>
|
let mentionedUsers = (await Promise.all(mentions.map(m =>
|
||||||
this.remoteUserResolveService.resolveUser(m.username, m.host ?? user.host).catch(() => null),
|
this.remoteUserResolveService.resolveUser(m.username, m.host ?? user.host).catch(() => null),
|
||||||
))).filter(isNotNull);
|
))).filter(x => x != null);
|
||||||
|
|
||||||
// Drop duplicate users
|
// Drop duplicate users
|
||||||
mentionedUsers = mentionedUsers.filter((u, i, self) =>
|
mentionedUsers = mentionedUsers.filter((u, i, self) =>
|
||||||
|
|
|
@ -8,7 +8,6 @@ import promiseLimit from 'promise-limit';
|
||||||
import type { MiRemoteUser, MiUser } from '@/models/User.js';
|
import type { MiRemoteUser, MiUser } from '@/models/User.js';
|
||||||
import { concat, unique } from '@/misc/prelude/array.js';
|
import { concat, unique } from '@/misc/prelude/array.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { getApIds } from './type.js';
|
import { getApIds } from './type.js';
|
||||||
import { ApPersonService } from './models/ApPersonService.js';
|
import { ApPersonService } from './models/ApPersonService.js';
|
||||||
import type { ApObject } from './type.js';
|
import type { ApObject } from './type.js';
|
||||||
|
@ -41,7 +40,7 @@ export class ApAudienceService {
|
||||||
const limit = promiseLimit<MiUser | null>(2);
|
const limit = promiseLimit<MiUser | null>(2);
|
||||||
const mentionedUsers = (await Promise.all(
|
const mentionedUsers = (await Promise.all(
|
||||||
others.map(id => limit(() => this.apPersonService.resolvePerson(id, resolver).catch(() => null))),
|
others.map(id => limit(() => this.apPersonService.resolvePerson(id, resolver).catch(() => null))),
|
||||||
)).filter(isNotNull);
|
)).filter(x => x != null);
|
||||||
|
|
||||||
if (toGroups.public.length > 0) {
|
if (toGroups.public.length > 0) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -27,7 +27,6 @@ import { QueueService } from '@/core/QueueService.js';
|
||||||
import type { UsersRepository, NotesRepository, FollowingsRepository, AbuseUserReportsRepository, FollowRequestsRepository } from '@/models/_.js';
|
import type { UsersRepository, NotesRepository, FollowingsRepository, AbuseUserReportsRepository, FollowRequestsRepository } from '@/models/_.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import type { MiRemoteUser } from '@/models/User.js';
|
import type { MiRemoteUser } from '@/models/User.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
import { AbuseReportService } from '@/core/AbuseReportService.js';
|
import { AbuseReportService } from '@/core/AbuseReportService.js';
|
||||||
import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js';
|
import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js';
|
||||||
|
@ -538,7 +537,7 @@ export class ApInboxService {
|
||||||
const userIds = uris
|
const userIds = uris
|
||||||
.filter(uri => uri.startsWith(this.config.url + '/users/'))
|
.filter(uri => uri.startsWith(this.config.url + '/users/'))
|
||||||
.map(uri => uri.split('/').at(-1))
|
.map(uri => uri.split('/').at(-1))
|
||||||
.filter(isNotNull);
|
.filter(x => x != null);
|
||||||
const users = await this.usersRepository.findBy({
|
const users = await this.usersRepository.findBy({
|
||||||
id: In(userIds),
|
id: In(userIds),
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,7 +26,6 @@ import type { MiUserKeypair } from '@/models/UserKeypair.js';
|
||||||
import type { UsersRepository, UserProfilesRepository, NotesRepository, DriveFilesRepository, PollsRepository } from '@/models/_.js';
|
import type { UsersRepository, UserProfilesRepository, NotesRepository, DriveFilesRepository, PollsRepository } from '@/models/_.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { JsonLdService } from './JsonLdService.js';
|
import { JsonLdService } from './JsonLdService.js';
|
||||||
import { ApMfmService } from './ApMfmService.js';
|
import { ApMfmService } from './ApMfmService.js';
|
||||||
|
@ -317,7 +316,7 @@ export class ApRendererService {
|
||||||
const getPromisedFiles = async (ids: string[]): Promise<MiDriveFile[]> => {
|
const getPromisedFiles = async (ids: string[]): Promise<MiDriveFile[]> => {
|
||||||
if (ids.length === 0) return [];
|
if (ids.length === 0) return [];
|
||||||
const items = await this.driveFilesRepository.findBy({ id: In(ids) });
|
const items = await this.driveFilesRepository.findBy({ id: In(ids) });
|
||||||
return ids.map(id => items.find(item => item.id === id)).filter(isNotNull);
|
return ids.map(id => items.find(item => item.id === id)).filter(x => x != null);
|
||||||
};
|
};
|
||||||
|
|
||||||
let inReplyTo;
|
let inReplyTo;
|
||||||
|
@ -686,7 +685,7 @@ export class ApRendererService {
|
||||||
if (names.length === 0) return [];
|
if (names.length === 0) return [];
|
||||||
|
|
||||||
const allEmojis = await this.customEmojiService.localEmojisCache.fetch();
|
const allEmojis = await this.customEmojiService.localEmojisCache.fetch();
|
||||||
const emojis = names.map(name => allEmojis.get(name)).filter(isNotNull);
|
const emojis = names.map(name => allEmojis.get(name)).filter(x => x != null);
|
||||||
|
|
||||||
return emojis;
|
return emojis;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import promiseLimit from 'promise-limit';
|
||||||
import type { MiUser } from '@/models/_.js';
|
import type { MiUser } from '@/models/_.js';
|
||||||
import { toArray, unique } from '@/misc/prelude/array.js';
|
import { toArray, unique } from '@/misc/prelude/array.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { isMention } from '../type.js';
|
import { isMention } from '../type.js';
|
||||||
import { Resolver } from '../ApResolverService.js';
|
import { Resolver } from '../ApResolverService.js';
|
||||||
import { ApPersonService } from './ApPersonService.js';
|
import { ApPersonService } from './ApPersonService.js';
|
||||||
|
@ -28,7 +27,7 @@ export class ApMentionService {
|
||||||
const limit = promiseLimit<MiUser | null>(2);
|
const limit = promiseLimit<MiUser | null>(2);
|
||||||
const mentionedUsers = (await Promise.all(
|
const mentionedUsers = (await Promise.all(
|
||||||
hrefs.map(x => limit(() => this.apPersonService.resolvePerson(x, resolver).catch(() => null))),
|
hrefs.map(x => limit(() => this.apPersonService.resolvePerson(x, resolver).catch(() => null))),
|
||||||
)).filter(isNotNull);
|
)).filter(x => x != null);
|
||||||
|
|
||||||
return mentionedUsers;
|
return mentionedUsers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import { UtilityService } from '@/core/UtilityService.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { checkHttps } from '@/misc/check-https.js';
|
import { checkHttps } from '@/misc/check-https.js';
|
||||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType } from '../type.js';
|
import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType } from '../type.js';
|
||||||
import { ApLoggerService } from '../ApLoggerService.js';
|
import { ApLoggerService } from '../ApLoggerService.js';
|
||||||
import { ApMfmService } from '../ApMfmService.js';
|
import { ApMfmService } from '../ApMfmService.js';
|
||||||
|
@ -253,7 +252,7 @@ export class ApNoteService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const uris = unique([note._misskey_quote, note.quoteUrl].filter(isNotNull));
|
const uris = unique([note._misskey_quote, note.quoteUrl].filter(x => x != null));
|
||||||
const results = await Promise.all(uris.map(tryResolveNote));
|
const results = await Promise.all(uris.map(tryResolveNote));
|
||||||
|
|
||||||
quote = results.filter((x): x is { status: 'ok', res: MiNote } => x.status === 'ok').map(x => x.res).at(0);
|
quote = results.filter((x): x is { status: 'ok', res: MiNote } => x.status === 'ok').map(x => x.res).at(0);
|
||||||
|
|
|
@ -38,7 +38,6 @@ import { MetaService } from '@/core/MetaService.js';
|
||||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
||||||
import type { AccountMoveService } from '@/core/AccountMoveService.js';
|
import type { AccountMoveService } from '@/core/AccountMoveService.js';
|
||||||
import { checkHttps } from '@/misc/check-https.js';
|
import { checkHttps } from '@/misc/check-https.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
|
import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
|
||||||
import { extractApHashtags } from './tag.js';
|
import { extractApHashtags } from './tag.js';
|
||||||
import type { OnModuleInit } from '@nestjs/common';
|
import type { OnModuleInit } from '@nestjs/common';
|
||||||
|
@ -637,7 +636,7 @@ export class ApPersonService implements OnModuleInit {
|
||||||
|
|
||||||
// とりあえずidを別の時間で生成して順番を維持
|
// とりあえずidを別の時間で生成して順番を維持
|
||||||
let td = 0;
|
let td = 0;
|
||||||
for (const note of featuredNotes.filter(isNotNull)) {
|
for (const note of featuredNotes.filter(x => x != null)) {
|
||||||
td -= 1000;
|
td -= 1000;
|
||||||
transactionalEntityManager.insert(MiUserNotePining, {
|
transactionalEntityManager.insert(MiUserNotePining, {
|
||||||
id: this.idService.gen(Date.now() + td),
|
id: this.idService.gen(Date.now() + td),
|
||||||
|
|
|
@ -10,7 +10,6 @@ import type { Config } from '@/config.js';
|
||||||
import type { IPoll } from '@/models/Poll.js';
|
import type { IPoll } from '@/models/Poll.js';
|
||||||
import type Logger from '@/logger.js';
|
import type Logger from '@/logger.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { isQuestion } from '../type.js';
|
import { isQuestion } from '../type.js';
|
||||||
import { ApLoggerService } from '../ApLoggerService.js';
|
import { ApLoggerService } from '../ApLoggerService.js';
|
||||||
import { ApResolverService } from '../ApResolverService.js';
|
import { ApResolverService } from '../ApResolverService.js';
|
||||||
|
@ -52,7 +51,7 @@ export class ApQuestionService {
|
||||||
|
|
||||||
const choices = question[multiple ? 'anyOf' : 'oneOf']
|
const choices = question[multiple ? 'anyOf' : 'oneOf']
|
||||||
?.map((x) => x.name)
|
?.map((x) => x.name)
|
||||||
.filter(isNotNull)
|
.filter(x => x != null)
|
||||||
?? [];
|
?? [];
|
||||||
|
|
||||||
const votes = question[multiple ? 'anyOf' : 'oneOf']?.map((x) => x.replies?.totalItems ?? x._misskey_votes ?? 0);
|
const votes = question[multiple ? 'anyOf' : 'oneOf']?.map((x) => x.replies?.totalItems ?? x._misskey_votes ?? 0);
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { toArray } from '@/misc/prelude/array.js';
|
import { toArray } from '@/misc/prelude/array.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { isHashtag } from '../type.js';
|
import { isHashtag } from '../type.js';
|
||||||
import type { IObject, IApHashtag } from '../type.js';
|
import type { IObject, IApHashtag } from '../type.js';
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ export function extractApHashtags(tags: IObject | IObject[] | null | undefined):
|
||||||
return hashtags.map(tag => {
|
return hashtags.map(tag => {
|
||||||
const m = tag.name.match(/^#(.+)/);
|
const m = tag.name.match(/^#(.+)/);
|
||||||
return m ? m[1] : null;
|
return m ? m[1] : null;
|
||||||
}).filter(isNotNull);
|
}).filter(x => x != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractApHashtagObjects(tags: IObject | IObject[] | null | undefined): IApHashtag[] {
|
export function extractApHashtagObjects(tags: IObject | IObject[] | null | undefined): IApHashtag[] {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import { bindThis } from '@/decorators.js';
|
||||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||||
import { Packed } from '@/misc/json-schema.js';
|
import { Packed } from '@/misc/json-schema.js';
|
||||||
import { SystemWebhookEntityService } from '@/core/entities/SystemWebhookEntityService.js';
|
import { SystemWebhookEntityService } from '@/core/entities/SystemWebhookEntityService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AbuseReportNotificationRecipientEntityService {
|
export class AbuseReportNotificationRecipientEntityService {
|
||||||
|
@ -66,13 +65,13 @@ export class AbuseReportNotificationRecipientEntityService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userIds = objs.map(it => it.userId).filter(isNotNull);
|
const userIds = objs.map(it => it.userId).filter(x => x != null);
|
||||||
const users: Map<string, Packed<'UserLite'>> = (userIds.length > 0)
|
const users: Map<string, Packed<'UserLite'>> = (userIds.length > 0)
|
||||||
? await this.userEntityService.packMany(userIds)
|
? await this.userEntityService.packMany(userIds)
|
||||||
.then(it => new Map(it.map(it => [it.id, it])))
|
.then(it => new Map(it.map(it => [it.id, it])))
|
||||||
: new Map();
|
: new Map();
|
||||||
|
|
||||||
const systemWebhookIds = objs.map(it => it.systemWebhookId).filter(isNotNull);
|
const systemWebhookIds = objs.map(it => it.systemWebhookId).filter(x => x != null);
|
||||||
const systemWebhooks: Map<string, Packed<'SystemWebhook'>> = (systemWebhookIds.length > 0)
|
const systemWebhooks: Map<string, Packed<'SystemWebhook'>> = (systemWebhookIds.length > 0)
|
||||||
? await this.systemWebhookEntityService.packMany(systemWebhookIds)
|
? await this.systemWebhookEntityService.packMany(systemWebhookIds)
|
||||||
.then(it => new Map(it.map(it => [it.id, it])))
|
.then(it => new Map(it.map(it => [it.id, it])))
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||||
import type { MiAbuseUserReport } from '@/models/AbuseUserReport.js';
|
import type { MiAbuseUserReport } from '@/models/AbuseUserReport.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import type { Packed } from '@/misc/json-schema.js';
|
import type { Packed } from '@/misc/json-schema.js';
|
||||||
import { UserEntityService } from './UserEntityService.js';
|
import { UserEntityService } from './UserEntityService.js';
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ export class AbuseUserReportEntityService {
|
||||||
) {
|
) {
|
||||||
const _reporters = reports.map(({ reporter, reporterId }) => reporter ?? reporterId);
|
const _reporters = reports.map(({ reporter, reporterId }) => reporter ?? reporterId);
|
||||||
const _targetUsers = reports.map(({ targetUser, targetUserId }) => targetUser ?? targetUserId);
|
const _targetUsers = reports.map(({ targetUser, targetUserId }) => targetUser ?? targetUserId);
|
||||||
const _assignees = reports.map(({ assignee, assigneeId }) => assignee ?? assigneeId).filter(isNotNull);
|
const _assignees = reports.map(({ assignee, assigneeId }) => assignee ?? assigneeId).filter(x => x != null);
|
||||||
const _userMap = await this.userEntityService.packMany(
|
const _userMap = await this.userEntityService.packMany(
|
||||||
[..._reporters, ..._targetUsers, ..._assignees],
|
[..._reporters, ..._targetUsers, ..._assignees],
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { appendQuery, query } from '@/misc/prelude/url.js';
|
||||||
import { deepClone } from '@/misc/clone.js';
|
import { deepClone } from '@/misc/clone.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isMimeImage } from '@/misc/is-mime-image.js';
|
import { isMimeImage } from '@/misc/is-mime-image.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { UtilityService } from '../UtilityService.js';
|
import { UtilityService } from '../UtilityService.js';
|
||||||
import { VideoProcessingService } from '../VideoProcessingService.js';
|
import { VideoProcessingService } from '../VideoProcessingService.js';
|
||||||
|
@ -261,11 +260,11 @@ export class DriveFileEntityService {
|
||||||
files: MiDriveFile[],
|
files: MiDriveFile[],
|
||||||
options?: PackOptions,
|
options?: PackOptions,
|
||||||
): Promise<Packed<'DriveFile'>[]> {
|
): Promise<Packed<'DriveFile'>[]> {
|
||||||
const _user = files.map(({ user, userId }) => user ?? userId).filter(isNotNull);
|
const _user = files.map(({ user, userId }) => user ?? userId).filter(x => x != null);
|
||||||
const _userMap = await this.userEntityService.packMany(_user)
|
const _userMap = await this.userEntityService.packMany(_user)
|
||||||
.then(users => new Map(users.map(user => [user.id, user])));
|
.then(users => new Map(users.map(user => [user.id, user])));
|
||||||
const items = await Promise.all(files.map(f => this.packNullable(f, options, f.userId ? { packedUser: _userMap.get(f.userId) } : {})));
|
const items = await Promise.all(files.map(f => this.packNullable(f, options, f.userId ? { packedUser: _userMap.get(f.userId) } : {})));
|
||||||
return items.filter(isNotNull);
|
return items.filter(x => x != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -290,6 +289,6 @@ export class DriveFileEntityService {
|
||||||
): Promise<Packed<'DriveFile'>[]> {
|
): Promise<Packed<'DriveFile'>[]> {
|
||||||
if (fileIds.length === 0) return [];
|
if (fileIds.length === 0) return [];
|
||||||
const filesMap = await this.packManyByIdsMap(fileIds, options);
|
const filesMap = await this.packManyByIdsMap(fileIds, options);
|
||||||
return fileIds.map(id => filesMap.get(id)).filter(isNotNull);
|
return fileIds.map(id => filesMap.get(id)).filter(x => x != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import type { MiUser } from '@/models/User.js';
|
||||||
import type { MiRegistrationTicket } from '@/models/RegistrationTicket.js';
|
import type { MiRegistrationTicket } from '@/models/RegistrationTicket.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { UserEntityService } from './UserEntityService.js';
|
import { UserEntityService } from './UserEntityService.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -59,8 +58,8 @@ export class InviteCodeEntityService {
|
||||||
tickets: MiRegistrationTicket[],
|
tickets: MiRegistrationTicket[],
|
||||||
me: { id: MiUser['id'] },
|
me: { id: MiUser['id'] },
|
||||||
) {
|
) {
|
||||||
const _createdBys = tickets.map(({ createdBy, createdById }) => createdBy ?? createdById).filter(isNotNull);
|
const _createdBys = tickets.map(({ createdBy, createdById }) => createdBy ?? createdById).filter(x => x != null);
|
||||||
const _usedBys = tickets.map(({ usedBy, usedById }) => usedBy ?? usedById).filter(isNotNull);
|
const _usedBys = tickets.map(({ usedBy, usedById }) => usedBy ?? usedById).filter(x => x != null);
|
||||||
const _userMap = await this.userEntityService.packMany([..._createdBys, ..._usedBys], me)
|
const _userMap = await this.userEntityService.packMany([..._createdBys, ..._usedBys], me)
|
||||||
.then(users => new Map(users.map(u => [u.id, u])));
|
.then(users => new Map(users.map(u => [u.id, u])));
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
|
|
|
@ -14,7 +14,6 @@ import type { MiNote } from '@/models/Note.js';
|
||||||
import type { MiNoteReaction } from '@/models/NoteReaction.js';
|
import type { MiNoteReaction } from '@/models/NoteReaction.js';
|
||||||
import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepository, PollVotesRepository, NoteReactionsRepository, ChannelsRepository } from '@/models/_.js';
|
import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepository, PollVotesRepository, NoteReactionsRepository, ChannelsRepository } from '@/models/_.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { DebounceLoader } from '@/misc/loader.js';
|
import { DebounceLoader } from '@/misc/loader.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import type { OnModuleInit } from '@nestjs/common';
|
import type { OnModuleInit } from '@nestjs/common';
|
||||||
|
@ -276,7 +275,7 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
packedFiles.set(k, v);
|
packedFiles.set(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileIds.map(id => packedFiles.get(id)).filter(isNotNull);
|
return fileIds.map(id => packedFiles.get(id)).filter(x => x != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -449,12 +448,12 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
|
|
||||||
await this.customEmojiService.prefetchEmojis(this.aggregateNoteEmojis(notes));
|
await this.customEmojiService.prefetchEmojis(this.aggregateNoteEmojis(notes));
|
||||||
// TODO: 本当は renote とか reply がないのに renoteId とか replyId があったらここで解決しておく
|
// TODO: 本当は renote とか reply がないのに renoteId とか replyId があったらここで解決しておく
|
||||||
const fileIds = notes.map(n => [n.fileIds, n.renote?.fileIds, n.reply?.fileIds]).flat(2).filter(isNotNull);
|
const fileIds = notes.map(n => [n.fileIds, n.renote?.fileIds, n.reply?.fileIds]).flat(2).filter(x => x != null);
|
||||||
const packedFiles = fileIds.length > 0 ? await this.driveFileEntityService.packManyByIdsMap(fileIds) : new Map();
|
const packedFiles = fileIds.length > 0 ? await this.driveFileEntityService.packManyByIdsMap(fileIds) : new Map();
|
||||||
const users = [
|
const users = [
|
||||||
...notes.map(({ user, userId }) => user ?? userId),
|
...notes.map(({ user, userId }) => user ?? userId),
|
||||||
...notes.map(({ replyUserId }) => replyUserId).filter(isNotNull),
|
...notes.map(({ replyUserId }) => replyUserId).filter(x => x != null),
|
||||||
...notes.map(({ renoteUserId }) => renoteUserId).filter(isNotNull),
|
...notes.map(({ renoteUserId }) => renoteUserId).filter(x => x != null),
|
||||||
];
|
];
|
||||||
const packedUsers = await this.userEntityService.packMany(users, me)
|
const packedUsers = await this.userEntityService.packMany(users, me)
|
||||||
.then(users => new Map(users.map(u => [u.id, u])));
|
.then(users => new Map(users.map(u => [u.id, u])));
|
||||||
|
|
|
@ -13,7 +13,6 @@ import type { MiGroupedNotification, MiNotification } from '@/models/Notificatio
|
||||||
import type { MiNote } from '@/models/Note.js';
|
import type { MiNote } from '@/models/Note.js';
|
||||||
import type { Packed } from '@/misc/json-schema.js';
|
import type { Packed } from '@/misc/json-schema.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { FilterUnionByProperty, groupedNotificationTypes } from '@/types.js';
|
import { FilterUnionByProperty, groupedNotificationTypes } from '@/types.js';
|
||||||
import { CacheService } from '@/core/CacheService.js';
|
import { CacheService } from '@/core/CacheService.js';
|
||||||
import { RoleEntityService } from './RoleEntityService.js';
|
import { RoleEntityService } from './RoleEntityService.js';
|
||||||
|
@ -103,7 +102,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
user,
|
user,
|
||||||
reaction: reaction.reaction,
|
reaction: reaction.reaction,
|
||||||
};
|
};
|
||||||
}))).filter(r => isNotNull(r.user));
|
}))).filter(r => r.user != null);
|
||||||
// if all users have been deleted, don't show this notification
|
// if all users have been deleted, don't show this notification
|
||||||
if (reactions.length === 0) {
|
if (reactions.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -124,7 +123,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.userEntityService.pack(userId, { id: meId });
|
return this.userEntityService.pack(userId, { id: meId });
|
||||||
}))).filter(isNotNull);
|
}))).filter(x => x != null);
|
||||||
// if all users have been deleted, don't show this notification
|
// if all users have been deleted, don't show this notification
|
||||||
if (users.length === 0) {
|
if (users.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -181,7 +180,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
|
|
||||||
validNotifications = await this.#filterValidNotifier(validNotifications, meId);
|
validNotifications = await this.#filterValidNotifier(validNotifications, meId);
|
||||||
|
|
||||||
const noteIds = validNotifications.map(x => 'noteId' in x ? x.noteId : null).filter(isNotNull);
|
const noteIds = validNotifications.map(x => 'noteId' in x ? x.noteId : null).filter(x => x != null);
|
||||||
const notes = noteIds.length > 0 ? await this.notesRepository.find({
|
const notes = noteIds.length > 0 ? await this.notesRepository.find({
|
||||||
where: { id: In(noteIds) },
|
where: { id: In(noteIds) },
|
||||||
relations: ['user', 'reply', 'reply.user', 'renote', 'renote.user'],
|
relations: ['user', 'reply', 'reply.user', 'renote', 'renote.user'],
|
||||||
|
@ -223,7 +222,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (await Promise.all(packPromises)).filter(isNotNull);
|
return (await Promise.all(packPromises)).filter(x => x != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -305,7 +304,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)),
|
this.cacheService.userProfileCache.fetch(meId).then(p => new Set(p.mutedInstances)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const notifierIds = notifications.map(notification => 'notifierId' in notification ? notification.notifierId : null).filter(isNotNull);
|
const notifierIds = notifications.map(notification => 'notifierId' in notification ? notification.notifierId : null).filter(x => x != null);
|
||||||
const notifiers = notifierIds.length > 0 ? await this.usersRepository.find({
|
const notifiers = notifierIds.length > 0 ? await this.usersRepository.find({
|
||||||
where: { id: In(notifierIds) },
|
where: { id: In(notifierIds) },
|
||||||
}) : [];
|
}) : [];
|
||||||
|
@ -313,7 +312,7 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
const filteredNotifications = ((await Promise.all(notifications.map(async (notification) => {
|
const filteredNotifications = ((await Promise.all(notifications.map(async (notification) => {
|
||||||
const isValid = this.#validateNotifier(notification, userIdsWhoMeMuting, userMutedInstances, notifiers);
|
const isValid = this.#validateNotifier(notification, userIdsWhoMeMuting, userMutedInstances, notifiers);
|
||||||
return isValid ? notification : null;
|
return isValid ? notification : null;
|
||||||
}))) as [T | null] ).filter(isNotNull);
|
}))) as [T | null] ).filter(x => x != null);
|
||||||
|
|
||||||
return filteredNotifications;
|
return filteredNotifications;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import type { MiPage } from '@/models/Page.js';
|
||||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import { UserEntityService } from './UserEntityService.js';
|
import { UserEntityService } from './UserEntityService.js';
|
||||||
import { DriveFileEntityService } from './DriveFileEntityService.js';
|
import { DriveFileEntityService } from './DriveFileEntityService.js';
|
||||||
|
|
||||||
|
@ -106,7 +105,7 @@ export class PageEntityService {
|
||||||
script: page.script,
|
script: page.script,
|
||||||
eyeCatchingImageId: page.eyeCatchingImageId,
|
eyeCatchingImageId: page.eyeCatchingImageId,
|
||||||
eyeCatchingImage: page.eyeCatchingImageId ? await this.driveFileEntityService.pack(page.eyeCatchingImageId) : null,
|
eyeCatchingImage: page.eyeCatchingImageId ? await this.driveFileEntityService.pack(page.eyeCatchingImageId) : null,
|
||||||
attachedFiles: this.driveFileEntityService.packMany((await Promise.all(attachedFiles)).filter(isNotNull)),
|
attachedFiles: this.driveFileEntityService.packMany((await Promise.all(attachedFiles)).filter(x => x != null)),
|
||||||
likedCount: page.likedCount,
|
likedCount: page.likedCount,
|
||||||
isLiked: meId ? await this.pageLikesRepository.exists({ where: { pageId: page.id, userId: meId } }) : undefined,
|
isLiked: meId ? await this.pageLikesRepository.exists({ where: { pageId: page.id, userId: meId } }) : undefined,
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,7 +47,6 @@ import { IdService } from '@/core/IdService.js';
|
||||||
import type { AnnouncementService } from '@/core/AnnouncementService.js';
|
import type { AnnouncementService } from '@/core/AnnouncementService.js';
|
||||||
import type { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
import type { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||||
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
|
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
import type { OnModuleInit } from '@nestjs/common';
|
import type { OnModuleInit } from '@nestjs/common';
|
||||||
import type { NoteEntityService } from './NoteEntityService.js';
|
import type { NoteEntityService } from './NoteEntityService.js';
|
||||||
import type { DriveFileEntityService } from './DriveFileEntityService.js';
|
import type { DriveFileEntityService } from './DriveFileEntityService.js';
|
||||||
|
@ -514,7 +513,7 @@ export class UserEntityService implements OnModuleInit {
|
||||||
movedTo: user.movedToUri ? this.apPersonService.resolvePerson(user.movedToUri).then(user => user.id).catch(() => null) : null,
|
movedTo: user.movedToUri ? this.apPersonService.resolvePerson(user.movedToUri).then(user => user.id).catch(() => null) : null,
|
||||||
alsoKnownAs: user.alsoKnownAs
|
alsoKnownAs: user.alsoKnownAs
|
||||||
? Promise.all(user.alsoKnownAs.map(uri => this.apPersonService.fetchPerson(uri).then(user => user?.id).catch(() => null)))
|
? Promise.all(user.alsoKnownAs.map(uri => this.apPersonService.fetchPerson(uri).then(user => user?.id).catch(() => null)))
|
||||||
.then(xs => xs.length === 0 ? null : xs.filter(isNotNull))
|
.then(xs => xs.length === 0 ? null : xs.filter(x => x != null))
|
||||||
: null,
|
: null,
|
||||||
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,
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function isNotNull<T extends NonNullable<unknown>>(input: T | undefined | null): input is T {
|
|
||||||
return input != null;
|
|
||||||
}
|
|
|
@ -12,7 +12,6 @@ import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js';
|
import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['gallery'],
|
tags: ['gallery'],
|
||||||
|
@ -70,7 +69,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
id: fileId,
|
id: fileId,
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
}),
|
}),
|
||||||
))).filter(isNotNull);
|
))).filter(x => x != null);
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
|
|
@ -10,7 +10,6 @@ import type { DriveFilesRepository, GalleryPostsRepository } from '@/models/_.js
|
||||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||||
import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js';
|
import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityService.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['gallery'],
|
tags: ['gallery'],
|
||||||
|
@ -68,7 +67,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
id: fileId,
|
id: fileId,
|
||||||
userId: me.id,
|
userId: me.id,
|
||||||
}),
|
}),
|
||||||
))).filter(isNotNull);
|
))).filter(x => x != null);
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
|
|
@ -12,7 +12,6 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { MetaService } from '@/core/MetaService.js';
|
import { MetaService } from '@/core/MetaService.js';
|
||||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { isNotNull } from '@/misc/is-not-null.js';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['users'],
|
tags: ['users'],
|
||||||
|
@ -53,7 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
host: acct.host ?? IsNull(),
|
host: acct.host ?? IsNull(),
|
||||||
})));
|
})));
|
||||||
|
|
||||||
return await this.userEntityService.packMany(users.filter(isNotNull), me, { schema: 'UserDetailed' });
|
return await this.userEntityService.packMany(users.filter(x => x != null), me, { schema: 'UserDetailed' });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue