backend: use named exports for services/note

This commit is contained in:
Norm 2022-10-16 17:49:41 -04:00
parent 3da7221eec
commit d83c1c3851
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE
18 changed files with 27 additions and 27 deletions

View file

@ -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 {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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);

View file

@ -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);
});

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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<void> {
const poll = await Polls.findOneBy({ noteId: note.id });
if (poll == null) throw new Error('poll not found');

View file

@ -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<void> {
// 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
};
}

View file

@ -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<void> {
// 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
};
}

View file

@ -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<User['id']>;
followingChannels: Set<Channel['id']>;
},
) {
): Promise<void> {
const following = info?.following ? info.following : new Set<string>((await Followings.find({
where: {
followerId: userId,

View file

@ -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<void> {
await NoteWatchings.delete({
noteId: note.id,
userId: me,
});
};
}

View file

@ -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<void> {
// 自分の投稿は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);
};
}