diff --git a/packages/backend/src/services/add-note-to-antenna.ts b/packages/backend/src/services/add-note-to-antenna.ts index 99bf1630d..b5bcd2304 100644 --- a/packages/backend/src/services/add-note-to-antenna.ts +++ b/packages/backend/src/services/add-note-to-antenna.ts @@ -6,7 +6,7 @@ import { isUserRelated } from '@/misc/is-user-related.js'; import { publishAntennaStream, publishMainStream } from '@/services/stream.js'; import { User } from '@/models/entities/user.js'; -export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }) { +export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }): Promise { // 通知しない設定になっているか、自分自身の投稿なら既読にする const read = !antenna.notify || (antenna.userId === noteUser.id); diff --git a/packages/backend/src/services/create-notification.ts b/packages/backend/src/services/create-notification.ts index 7b27c0261..ab4fbfa10 100644 --- a/packages/backend/src/services/create-notification.ts +++ b/packages/backend/src/services/create-notification.ts @@ -9,7 +9,7 @@ export async function createNotification( notifieeId: User['id'], type: Notification['type'], data: Partial, -) { +): Promise { if (data.notifierId && (notifieeId === data.notifierId)) { return null; } diff --git a/packages/backend/src/services/fetch-instance-metadata.ts b/packages/backend/src/services/fetch-instance-metadata.ts index d7f551d93..ad312c3c8 100644 --- a/packages/backend/src/services/fetch-instance-metadata.ts +++ b/packages/backend/src/services/fetch-instance-metadata.ts @@ -81,6 +81,7 @@ type NodeInfo = { nodeName?: any; nodeDescription?: any; description?: any; + themeColor?: any; maintainer?: { name?: any; email?: any; @@ -125,7 +126,8 @@ async function fetchNodeinfo(instance: Instance): Promise { return info as NodeInfo; } catch (e) { - logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${e.message}`); + const message = e instanceof Error ? e.message : e; + logger.error(`Failed to fetch nodeinfo of ${instance.host}: ${message}`); throw e; } diff --git a/packages/backend/src/services/insert-moderation-log.ts b/packages/backend/src/services/insert-moderation-log.ts index 821199962..6c225eb5b 100644 --- a/packages/backend/src/services/insert-moderation-log.ts +++ b/packages/backend/src/services/insert-moderation-log.ts @@ -2,7 +2,7 @@ import { ModerationLogs } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { User } from '@/models/entities/user.js'; -export async function insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record) { +export async function insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record): Promise { await ModerationLogs.insert({ id: genId(), createdAt: new Date(), diff --git a/packages/backend/src/services/push-notification.ts b/packages/backend/src/services/push-notification.ts index e258c217a..6607c05d9 100644 --- a/packages/backend/src/services/push-notification.ts +++ b/packages/backend/src/services/push-notification.ts @@ -16,7 +16,7 @@ type pushNotificationsTypes = { }; // Reduce the content of the push message because of the character limit -function truncateNotification(notification: Packed<'Notification'>): any { +function truncateNotification(notification: Packed<'Notification'>): Record { if (notification.note) { return { ...notification, @@ -37,7 +37,7 @@ function truncateNotification(notification: Packed<'Notification'>): any { return notification; } -export async function pushNotification(userId: string, type: T, body: pushNotificationsTypes[T]) { +export async function pushNotification(userId: string, type: T, body: pushNotificationsTypes[T]): Promise { const meta = await fetchMeta(); // Register key pair information diff --git a/packages/backend/src/services/relay.ts b/packages/backend/src/services/relay.ts index 36bf88b9c..725ce30ce 100644 --- a/packages/backend/src/services/relay.ts +++ b/packages/backend/src/services/relay.ts @@ -36,7 +36,7 @@ export async function getRelayActor(): Promise { return created as ILocalUser; } -export async function addRelay(inbox: string) { +export async function addRelay(inbox: string): Promise { const relay = await Relays.insert({ id: genId(), inbox, @@ -51,7 +51,7 @@ export async function addRelay(inbox: string) { return relay; } -export async function removeRelay(inbox: string) { +export async function removeRelay(inbox: string): Promise { const relay = await Relays.findOneBy({ inbox, }); @@ -69,12 +69,12 @@ export async function removeRelay(inbox: string) { await Relays.delete(relay.id); } -export async function listRelay() { +export async function listRelay(): Promise { const relays = await Relays.find(); return relays; } -export async function relayAccepted(id: string) { +export async function relayAccepted(id: string): Promise { const result = await Relays.update(id, { status: 'accepted', }); @@ -82,7 +82,7 @@ export async function relayAccepted(id: string) { return JSON.stringify(result); } -export async function relayRejected(id: string) { +export async function relayRejected(id: string): Promise { const result = await Relays.update(id, { status: 'rejected', }); @@ -90,11 +90,11 @@ export async function relayRejected(id: string) { return JSON.stringify(result); } -export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any) { +export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise { if (activity == null) return; const relays = await relaysCache.fetch(null); - if (relays.length === 0) return; + if (relays == null || relays.length === 0) return; // TODO //const copy = structuredClone(activity); diff --git a/packages/backend/src/services/unsuspend-user.ts b/packages/backend/src/services/unsuspend-user.ts index 3ed7ce850..766b10f21 100644 --- a/packages/backend/src/services/unsuspend-user.ts +++ b/packages/backend/src/services/unsuspend-user.ts @@ -8,7 +8,7 @@ import { User } from '@/models/entities/user.js'; import { Users, Followings } from '@/models/index.js'; import { publishInternalEvent } from '@/services/stream.js'; -export async function doPostUnsuspend(user: User) { +export async function doPostUnsuspend(user: User): Promise { publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false }); if (Users.isLocalUser(user)) { diff --git a/packages/backend/src/services/update-hashtag.ts b/packages/backend/src/services/update-hashtag.ts index 9f549c3f4..7a77cb124 100644 --- a/packages/backend/src/services/update-hashtag.ts +++ b/packages/backend/src/services/update-hashtag.ts @@ -16,7 +16,7 @@ export async function updateUsertags(user: User, tags: string[]): Promise await 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 updateHashtag(user, tag, true, false); } } diff --git a/packages/backend/src/services/user-cache.ts b/packages/backend/src/services/user-cache.ts index d30b76a24..d67931c2c 100644 --- a/packages/backend/src/services/user-cache.ts +++ b/packages/backend/src/services/user-cache.ts @@ -1,3 +1,4 @@ +import { IsNull } from 'typeorm'; import { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/entities/user.js'; import { Users } from '@/models/index.js'; import { Cache } from '@/misc/cache.js'; @@ -5,15 +6,15 @@ import { subscriber } from '@/db/redis.js'; export const userByIdCache = new Cache( Infinity, - (id) => Users.findOneBy({ id }).then(x => x ?? undefined), + async (id) => id ? (await Users.findOneBy({ id }) ?? undefined) : undefined, ); export const localUserByNativeTokenCache = new Cache( Infinity, - (token) => Users.findOneBy({ token }).then(x => x ?? undefined), + async (token) => token ? (await Users.findOneBy({ token, host: IsNull() }) as ILocalUser | null ?? undefined) : undefined, ); export const uriPersonCache = new Cache( Infinity, - (uri) => Users.findOneBy({ uri }).then(x => x ?? undefined), + async (uri) => uri ? (await Users.findOneBy({ uri }) ?? undefined) : undefined, ); subscriber.on('message', async (_, data) => {