From d83c1c3851addddc8d7ef4093b94e45cfcfa4f91 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 16 Oct 2022 17:49:41 -0400 Subject: [PATCH] backend: use named exports for services/note --- packages/backend/src/remote/activitypub/kernel/like.ts | 4 ++-- packages/backend/src/remote/activitypub/kernel/undo/like.ts | 2 +- packages/backend/src/remote/activitypub/models/note.ts | 2 +- packages/backend/src/server/api/endpoints/antennas/notes.ts | 2 +- .../backend/src/server/api/endpoints/i/notifications.ts | 4 ++-- packages/backend/src/server/api/endpoints/notes/mentions.ts | 4 ++-- .../src/server/api/endpoints/notes/reactions/create.ts | 2 +- .../src/server/api/endpoints/notes/reactions/delete.ts | 2 +- .../src/server/api/endpoints/notes/thread-muting/create.ts | 2 +- .../src/server/api/endpoints/notes/watching/create.ts | 2 +- .../src/server/api/endpoints/notes/watching/delete.ts | 2 +- packages/backend/src/server/api/stream/index.ts | 2 +- packages/backend/src/services/note/polls/vote.ts | 2 +- packages/backend/src/services/note/reaction/create.ts | 6 +++--- packages/backend/src/services/note/reaction/delete.ts | 4 ++-- packages/backend/src/services/note/read.ts | 4 ++-- packages/backend/src/services/note/unwatch.ts | 4 ++-- packages/backend/src/services/note/watch.ts | 4 ++-- 18 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/like.ts b/packages/backend/src/remote/activitypub/kernel/like.ts index b9faa38d1..76272eea7 100644 --- a/packages/backend/src/remote/activitypub/kernel/like.ts +++ b/packages/backend/src/remote/activitypub/kernel/like.ts @@ -1,5 +1,5 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; -import create from '@/services/note/reaction/create.js'; +import { createReaction } from '@/services/note/reaction/create.js'; import { ILike, getApId } from '../type.js'; import { fetchNote, extractEmojis } from '../models/note.js'; @@ -11,7 +11,7 @@ export default async (actor: CacheableRemoteUser, activity: ILike) => { await extractEmojis(activity.tag || [], actor.host).catch(() => null); - return await create(actor, note, activity._misskey_reaction || activity.content || activity.name).catch(e => { + return await createReaction(actor, note, activity._misskey_reaction || activity.content || activity.name).catch(e => { if (e.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') { return 'skip: already reacted'; } else { diff --git a/packages/backend/src/remote/activitypub/kernel/undo/like.ts b/packages/backend/src/remote/activitypub/kernel/undo/like.ts index a7f7e6bc6..6c7b8d18b 100644 --- a/packages/backend/src/remote/activitypub/kernel/undo/like.ts +++ b/packages/backend/src/remote/activitypub/kernel/undo/like.ts @@ -1,5 +1,5 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; -import deleteReaction from '@/services/note/reaction/delete.js'; +import { deleteReaction } from '@/services/note/reaction/delete.js'; import { ILike, getApId } from '@/remote/activitypub/type.js'; import { fetchNote } from '@/remote/activitypub/models/note.js'; diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index e5f8344ff..55989206e 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -4,7 +4,7 @@ import config from '@/config/index.js'; import post from '@/services/note/create.js'; import { CacheableRemoteUser } from '@/models/entities/user.js'; import { unique, toArray, toSingle } from '@/prelude/array.js'; -import vote from '@/services/note/polls/vote.js'; +import { vote } from '@/services/note/polls/vote.js'; import { DriveFile } from '@/models/entities/drive-file.js'; import { deliverQuestionUpdate } from '@/services/note/polls/update.js'; import { extractDbHost, toPuny } from '@/misc/convert-host.js'; diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts index f86b6c7d8..0231fcfd6 100644 --- a/packages/backend/src/server/api/endpoints/antennas/notes.ts +++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts @@ -1,4 +1,4 @@ -import readNote from '@/services/note/read.js'; +import { readNote } from '@/services/note/read.js'; import { Antennas, Notes, AntennaNotes } from '@/models/index.js'; import { makePaginationQuery } from '../../common/make-pagination-query.js'; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js'; diff --git a/packages/backend/src/server/api/endpoints/i/notifications.ts b/packages/backend/src/server/api/endpoints/i/notifications.ts index 237d76da8..4a2ccdc79 100644 --- a/packages/backend/src/server/api/endpoints/i/notifications.ts +++ b/packages/backend/src/server/api/endpoints/i/notifications.ts @@ -1,7 +1,7 @@ import { Brackets } from 'typeorm'; import { notificationTypes } from 'foundkey-js'; import { Notifications, Followings, Mutings, Users, UserProfiles } from '@/models/index.js'; -import read from '@/services/note/read.js'; +import { readNote } from '@/services/note/read.js'; import { readNotification } from '../../common/read-notification.js'; import define from '../../define.js'; import { makePaginationQuery } from '../../common/make-pagination-query.js'; @@ -137,7 +137,7 @@ export default define(meta, paramDef, async (ps, user) => { const notes = notifications.filter(notification => ['mention', 'reply', 'quote'].includes(notification.type)).map(notification => notification.note!); if (notes.length > 0) { - read(user.id, notes); + readNote(user.id, notes); } return await Notifications.packMany(notifications, user.id); diff --git a/packages/backend/src/server/api/endpoints/notes/mentions.ts b/packages/backend/src/server/api/endpoints/notes/mentions.ts index f86465ef6..10d329c9d 100644 --- a/packages/backend/src/server/api/endpoints/notes/mentions.ts +++ b/packages/backend/src/server/api/endpoints/notes/mentions.ts @@ -1,6 +1,6 @@ import { Brackets } from 'typeorm'; import { noteVisibilities } from 'foundkey-js'; -import read from '@/services/note/read.js'; +import { readNote } from '@/services/note/read.js'; import { Notes, Followings } from '@/models/index.js'; import define from '../../define.js'; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js'; @@ -79,7 +79,7 @@ export default define(meta, paramDef, async (ps, user) => { const mentions = await query.take(ps.limit).getMany(); - read(user.id, mentions); + readNote(user.id, mentions); return await Notes.packMany(mentions, user); }); diff --git a/packages/backend/src/server/api/endpoints/notes/reactions/create.ts b/packages/backend/src/server/api/endpoints/notes/reactions/create.ts index b5c0c9d17..5d27ab8fb 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions/create.ts @@ -1,4 +1,4 @@ -import createReaction from '@/services/note/reaction/create.js'; +import { createReaction } from '@/services/note/reaction/create.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; import { ApiError } from '../../../error.js'; diff --git a/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts b/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts index e1bb63197..a5c50e4c2 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts @@ -1,4 +1,4 @@ -import deleteReaction from '@/services/note/reaction/delete.js'; +import { deleteReaction } from '@/services/note/reaction/delete.js'; import { SECOND, HOUR } from '@/const.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; diff --git a/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts b/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts index d7599dc30..efcafe306 100644 --- a/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts @@ -1,7 +1,7 @@ import { noteNotificationTypes } from 'foundkey-js'; import { Notes, NoteThreadMutings, NoteWatchings } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; -import readNote from '@/services/note/read.js'; +import { readNote } from '@/services/note/read.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; import { ApiError } from '../../../error.js'; diff --git a/packages/backend/src/server/api/endpoints/notes/watching/create.ts b/packages/backend/src/server/api/endpoints/notes/watching/create.ts index 6025799fa..07c0517a1 100644 --- a/packages/backend/src/server/api/endpoints/notes/watching/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/watching/create.ts @@ -1,4 +1,4 @@ -import watch from '@/services/note/watch.js'; +import { watch } from '@/services/note/watch.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; import { ApiError } from '../../../error.js'; diff --git a/packages/backend/src/server/api/endpoints/notes/watching/delete.ts b/packages/backend/src/server/api/endpoints/notes/watching/delete.ts index 7021c7970..5949c9cd1 100644 --- a/packages/backend/src/server/api/endpoints/notes/watching/delete.ts +++ b/packages/backend/src/server/api/endpoints/notes/watching/delete.ts @@ -1,4 +1,4 @@ -import unwatch from '@/services/note/unwatch.js'; +import { unwatch } from '@/services/note/unwatch.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; import { ApiError } from '../../../error.js'; diff --git a/packages/backend/src/server/api/stream/index.ts b/packages/backend/src/server/api/stream/index.ts index be67aa226..f3337fbfe 100644 --- a/packages/backend/src/server/api/stream/index.ts +++ b/packages/backend/src/server/api/stream/index.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'events'; import * as websocket from 'websocket'; -import readNote from '@/services/note/read.js'; +import { readNote } from '@/services/note/read.js'; import { User } from '@/models/entities/user.js'; import { Channel as ChannelModel } from '@/models/entities/channel.js'; import { Followings, Mutings, RenoteMutings, UserProfiles, ChannelFollowings, Blockings } from '@/models/index.js'; diff --git a/packages/backend/src/services/note/polls/vote.ts b/packages/backend/src/services/note/polls/vote.ts index 3382e10bd..5e27159e8 100644 --- a/packages/backend/src/services/note/polls/vote.ts +++ b/packages/backend/src/services/note/polls/vote.ts @@ -6,7 +6,7 @@ import { PollVotes, NoteWatchings, Polls, Blockings, NoteThreadMutings } from '@ import { genId } from '@/misc/gen-id.js'; import { createNotification } from '@/services/create-notification.js'; -export default async function(user: CacheableUser, note: Note, choice: number) { +export async function vote(user: CacheableUser, note: Note, choice: number): Promise { const poll = await Polls.findOneBy({ noteId: note.id }); if (poll == null) throw new Error('poll not found'); diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 5cc4f331c..df930c15c 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -13,9 +13,9 @@ import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js import { NoteReaction } from '@/models/entities/note-reaction.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; import { createNotification } from '@/services/create-notification.js'; -import deleteReaction from './delete.js'; +import { deleteReaction } from './delete.js'; -export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => { +export async function createReaction(user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string): Promise { // Check blocking if (note.userId !== user.id) { const block = await Blockings.findOneBy({ @@ -148,4 +148,4 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note, dm.execute(); } //#endregion -}; +} diff --git a/packages/backend/src/services/note/reaction/delete.ts b/packages/backend/src/services/note/reaction/delete.ts index a7cbcb1c1..3fc85a3d1 100644 --- a/packages/backend/src/services/note/reaction/delete.ts +++ b/packages/backend/src/services/note/reaction/delete.ts @@ -9,7 +9,7 @@ import { Note } from '@/models/entities/note.js'; import { NoteReactions, Users, Notes } from '@/models/index.js'; import { decodeReaction } from '@/misc/reaction-lib.js'; -export default async (user: { id: User['id']; host: User['host']; }, note: Note) => { +export async function deleteReaction(user: { id: User['id']; host: User['host']; }, note: Note): Promise { // if already unreacted const exist = await NoteReactions.findOneBy({ noteId: note.id, @@ -55,4 +55,4 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note) dm.execute(); } //#endregion -}; +} diff --git a/packages/backend/src/services/note/read.ts b/packages/backend/src/services/note/read.ts index 0b678893c..6899eccc5 100644 --- a/packages/backend/src/services/note/read.ts +++ b/packages/backend/src/services/note/read.ts @@ -12,14 +12,14 @@ import { Packed } from '@/misc/schema.js'; /** * Mark notes as read */ -export default async function( +export async function readNote( userId: User['id'], notes: (Note | Packed<'Note'>)[], info?: { following: Set; followingChannels: Set; }, -) { +): Promise { const following = info?.following ? info.following : new Set((await Followings.find({ where: { followerId: userId, diff --git a/packages/backend/src/services/note/unwatch.ts b/packages/backend/src/services/note/unwatch.ts index 3964b2ba5..2f779586d 100644 --- a/packages/backend/src/services/note/unwatch.ts +++ b/packages/backend/src/services/note/unwatch.ts @@ -2,9 +2,9 @@ import { User } from '@/models/entities/user.js'; import { NoteWatchings } from '@/models/index.js'; import { Note } from '@/models/entities/note.js'; -export default async (me: User['id'], note: Note) => { +export async function unwatch(me: User['id'], note: Note): Promise { await NoteWatchings.delete({ noteId: note.id, userId: me, }); -}; +} diff --git a/packages/backend/src/services/note/watch.ts b/packages/backend/src/services/note/watch.ts index 2210c44a7..e7217a2c0 100644 --- a/packages/backend/src/services/note/watch.ts +++ b/packages/backend/src/services/note/watch.ts @@ -4,7 +4,7 @@ import { NoteWatchings } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { NoteWatching } from '@/models/entities/note-watching.js'; -export default async (me: User['id'], note: Note) => { +export async function watch(me: User['id'], note: Note): Promise { // 自分の投稿はwatchできない if (me === note.userId) { return; @@ -17,4 +17,4 @@ export default async (me: User['id'], note: Note) => { userId: me, noteUserId: note.userId, } as NoteWatching); -}; +}