* wip

* wip

* wip

* wip

* wip

* Update define.ts

* Update update.ts

* Update user.ts

* wip

* wip

* Update request.ts

* URL

* wip

* wip

* wip

* wip

* Update invite.ts

* Update create.ts
This commit is contained in:
syuilo
2021-03-24 11:05:37 +09:00
committed by GitHub
parent 62cc14c93b
commit ce340aba7a
109 changed files with 252 additions and 201 deletions

View File

@ -9,7 +9,7 @@ export type PackedApp = SchemaType<typeof packedAppSchema>;
export class AppRepository extends Repository<App> {
public async pack(
src: App['id'] | App,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecret?: boolean,

View File

@ -2,12 +2,13 @@ import { EntityRepository, Repository } from 'typeorm';
import { Apps } from '..';
import { AuthSession } from '../entities/auth-session';
import { awaitAll } from '../../prelude/await-all';
import { User } from '../entities/user';
@EntityRepository(AuthSession)
export class AuthSessionRepository extends Repository<AuthSession> {
public async pack(
src: AuthSession['id'] | AuthSession,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const session = typeof src === 'object' ? src : await this.findOneOrFail(src);

View File

@ -3,6 +3,7 @@ import { Users } from '..';
import { Blocking } from '../entities/blocking';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedBlocking = SchemaType<typeof packedBlockingSchema>;
@ -10,7 +11,7 @@ export type PackedBlocking = SchemaType<typeof packedBlockingSchema>;
export class BlockingRepository extends Repository<Blocking> {
public async pack(
src: Blocking['id'] | Blocking,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedBlocking> {
const blocking = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -26,7 +27,7 @@ export class BlockingRepository extends Repository<Blocking> {
public packMany(
blockings: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(blockings.map(x => this.pack(x, me)));
}

View File

@ -10,19 +10,19 @@ export type PackedChannel = SchemaType<typeof packedChannelSchema>;
export class ChannelRepository extends Repository<Channel> {
public async pack(
src: Channel['id'] | Channel,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
): Promise<PackedChannel> {
const channel = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const banner = channel.bannerId ? await DriveFiles.findOne(channel.bannerId) : null;
const hasUnreadNote = me ? (await NoteUnreads.findOne({ noteChannelId: channel.id, userId: meId })) != null : undefined;
const hasUnreadNote = meId ? (await NoteUnreads.findOne({ noteChannelId: channel.id, userId: meId })) != null : undefined;
const following = await ChannelFollowings.findOne({
const following = meId ? await ChannelFollowings.findOne({
followerId: meId,
followeeId: channel.id,
});
}) : null;
return {
id: channel.id,

View File

@ -53,7 +53,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
return thumbnail ? (file.thumbnailUrl || (isImage ? (file.webpublicUrl || file.url) : null)) : (file.webpublicUrl || file.url);
}
public async calcDriveUsageOf(user: User['id'] | User): Promise<number> {
public async calcDriveUsageOf(user: User['id'] | { id: User['id'] }): Promise<number> {
const id = typeof user === 'object' ? user.id : user;
const { sum } = await this

View File

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { FollowRequest } from '../entities/follow-request';
import { Users } from '..';
import { User } from '../entities/user';
@EntityRepository(FollowRequest)
export class FollowRequestRepository extends Repository<FollowRequest> {
public async pack(
src: FollowRequest['id'] | FollowRequest,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const request = typeof src === 'object' ? src : await this.findOneOrFail(src);

View File

@ -3,6 +3,7 @@ import { Users } from '..';
import { Following } from '../entities/following';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
type LocalFollowerFollowing = Following & {
followerHost: null;
@ -50,7 +51,7 @@ export class FollowingRepository extends Repository<Following> {
public async pack(
src: Following['id'] | Following,
me?: any,
me?: { id: User['id'] } | null | undefined,
opts?: {
populateFollowee?: boolean;
populateFollower?: boolean;
@ -76,7 +77,7 @@ export class FollowingRepository extends Repository<Following> {
public packMany(
followings: any[],
me?: any,
me?: { id: User['id'] } | null | undefined,
opts?: {
populateFollowee?: boolean;
populateFollower?: boolean;

View File

@ -1,3 +1,4 @@
import { User } from '@/models/entities/user';
import { EntityRepository, Repository } from 'typeorm';
import { Users } from '../../..';
import { ReversiGame } from '../../../entities/games/reversi/game';
@ -6,7 +7,7 @@ import { ReversiGame } from '../../../entities/games/reversi/game';
export class ReversiGameRepository extends Repository<ReversiGame> {
public async pack(
src: ReversiGame['id'] | ReversiGame,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean
}
@ -16,7 +17,6 @@ export class ReversiGameRepository extends Repository<ReversiGame> {
}, options);
const game = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
return {
id: game.id,
@ -30,10 +30,10 @@ export class ReversiGameRepository extends Repository<ReversiGame> {
user2Accepted: game.user2Accepted,
user1Id: game.user1Id,
user2Id: game.user2Id,
user1: await Users.pack(game.user1Id, meId),
user2: await Users.pack(game.user2Id, meId),
user1: await Users.pack(game.user1Id, me),
user2: await Users.pack(game.user2Id, me),
winnerId: game.winnerId,
winner: game.winnerId ? await Users.pack(game.winnerId, meId) : null,
winner: game.winnerId ? await Users.pack(game.winnerId, me) : null,
surrendered: game.surrendered,
black: game.black,
bw: game.bw,

View File

@ -2,12 +2,13 @@ import { EntityRepository, Repository } from 'typeorm';
import { ReversiMatching } from '../../../entities/games/reversi/matching';
import { Users } from '../../..';
import { awaitAll } from '../../../../prelude/await-all';
import { User } from '@/models/entities/user';
@EntityRepository(ReversiMatching)
export class ReversiMatchingRepository extends Repository<ReversiMatching> {
public async pack(
src: ReversiMatching['id'] | ReversiMatching,
me: any
me: { id: User['id'] }
) {
const matching = typeof src === 'object' ? src : await this.findOneOrFail(src);

View File

@ -2,6 +2,7 @@ import { EntityRepository, Repository } from 'typeorm';
import { MessagingMessage } from '../entities/messaging-message';
import { Users, DriveFiles, UserGroups } from '..';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedMessagingMessage = SchemaType<typeof packedMessagingMessageSchema>;
@ -13,7 +14,7 @@ export class MessagingMessageRepository extends Repository<MessagingMessage> {
public async pack(
src: MessagingMessage['id'] | MessagingMessage,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
populateRecipient?: boolean,
populateGroup?: boolean,

View File

@ -3,6 +3,7 @@ import { Users } from '..';
import { Muting } from '../entities/muting';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedMuting = SchemaType<typeof packedMutingSchema>;
@ -10,7 +11,7 @@ export type PackedMuting = SchemaType<typeof packedMutingSchema>;
export class MutingRepository extends Repository<Muting> {
public async pack(
src: Muting['id'] | Muting,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedMuting> {
const muting = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -26,7 +27,7 @@ export class MutingRepository extends Repository<Muting> {
public packMany(
mutings: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(mutings.map(x => this.pack(x, me)));
}

View File

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { NoteFavorite } from '../entities/note-favorite';
import { Notes } from '..';
import { User } from '../entities/user';
@EntityRepository(NoteFavorite)
export class NoteFavoriteRepository extends Repository<NoteFavorite> {
public async pack(
src: NoteFavorite['id'] | NoteFavorite,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const favorite = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -20,7 +21,7 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> {
public packMany(
favorites: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(favorites.map(x => this.pack(x, me)));
}

View File

@ -3,6 +3,7 @@ import { NoteReaction } from '../entities/note-reaction';
import { Users } from '..';
import { SchemaType } from '@/misc/schema';
import { convertLegacyReaction } from '@/misc/reaction-lib';
import { User } from '../entities/user';
export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
@ -10,7 +11,7 @@ export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
export class NoteReactionRepository extends Repository<NoteReaction> {
public async pack(
src: NoteReaction['id'] | NoteReaction,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedNoteReaction> {
const reaction = typeof src === 'object' ? src : await this.findOneOrFail(src);

View File

@ -79,7 +79,7 @@ export class NoteRepository extends Repository<Note> {
public async pack(
src: Note['id'] | Note,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean;
skipHide?: boolean;
@ -93,7 +93,7 @@ export class NoteRepository extends Repository<Note> {
skipHide: false
}, options);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const note = typeof src === 'object' ? src : await this.findOneOrFail(src);
const host = note.userHost;
@ -174,7 +174,7 @@ export class NoteRepository extends Repository<Note> {
id: note.id,
createdAt: note.createdAt.toISOString(),
userId: note.userId,
user: Users.pack(note.user || note.userId, meId, {
user: Users.pack(note.user || note.userId, me, {
detail: false,
}),
text: text,
@ -204,12 +204,12 @@ export class NoteRepository extends Repository<Note> {
_prId_: (note as any)._prId_ || undefined,
...(opts.detail ? {
reply: note.replyId ? this.pack(note.reply || note.replyId, meId, {
reply: note.replyId ? this.pack(note.reply || note.replyId, me, {
detail: false,
_hint_: options?._hint_
}) : undefined,
renote: note.renoteId ? this.pack(note.renote || note.renoteId, meId, {
renote: note.renoteId ? this.pack(note.renote || note.renoteId, me, {
detail: true,
_hint_: options?._hint_
}) : undefined,
@ -236,7 +236,7 @@ export class NoteRepository extends Repository<Note> {
public async packMany(
notes: Note[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean;
skipHide?: boolean;
@ -244,7 +244,7 @@ export class NoteRepository extends Repository<Note> {
) {
if (notes.length === 0) return [];
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const myReactionsMap = new Map<Note['id'], NoteReaction | null>();
if (meId) {
const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);

View File

@ -31,38 +31,38 @@ export class NotificationRepository extends Repository<Notification> {
userId: notification.notifierId,
user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null,
...(notification.type === 'mention' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'reply' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'renote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'quote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'reaction' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
reaction: notification.reaction
} : {}),
...(notification.type === 'pollVote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),

View File

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { PageLike } from '../entities/page-like';
import { Pages } from '..';
import { User } from '../entities/user';
@EntityRepository(PageLike)
export class PageLikeRepository extends Repository<PageLike> {
public async pack(
src: PageLike['id'] | PageLike,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const like = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -18,7 +19,7 @@ export class PageLikeRepository extends Repository<PageLike> {
public packMany(
likes: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(likes.map(x => this.pack(x, me)));
}

View File

@ -12,9 +12,9 @@ export type PackedPage = SchemaType<typeof packedPageSchema>;
export class PageRepository extends Repository<Page> {
public async pack(
src: Page['id'] | Page,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
): Promise<PackedPage> {
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const page = typeof src === 'object' ? src : await this.findOneOrFail(src);
const attachedFiles: Promise<DriveFile | undefined>[] = [];
@ -84,7 +84,7 @@ export class PageRepository extends Repository<Page> {
public packMany(
pages: Page[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
) {
return Promise.all(pages.map(x => this.pack(x, me)));
}

View File

@ -147,7 +147,7 @@ export class UserRepository extends Repository<User> {
public async pack(
src: User['id'] | User,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecrets?: boolean,
@ -159,7 +159,7 @@ export class UserRepository extends Repository<User> {
}, options);
const user = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
const pins = opts.detail ? await UserNotePinings.createQueryBuilder('pin')
@ -213,11 +213,11 @@ export class UserRepository extends Repository<User> {
followingCount: user.followingCount,
notesCount: user.notesCount,
pinnedNoteIds: pins.map(pin => pin.noteId),
pinnedNotes: Notes.packMany(pins.map(pin => pin.note!), meId, {
pinnedNotes: Notes.packMany(pins.map(pin => pin.note!), me, {
detail: true
}),
pinnedPageId: profile!.pinnedPageId,
pinnedPage: profile!.pinnedPageId ? Pages.pack(profile!.pinnedPageId, meId) : null,
pinnedPage: profile!.pinnedPageId ? Pages.pack(profile!.pinnedPageId, me) : null,
twoFactorEnabled: profile!.twoFactorEnabled,
usePasswordLessLogin: profile!.usePasswordLessLogin,
securityKeys: profile!.twoFactorEnabled
@ -286,7 +286,7 @@ export class UserRepository extends Repository<User> {
public packMany(
users: (User['id'] | User)[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecrets?: boolean,
@ -295,11 +295,15 @@ export class UserRepository extends Repository<User> {
return Promise.all(users.map(u => this.pack(u, me, options)));
}
public isLocalUser(user: User): user is ILocalUser {
public isLocalUser(user: User): user is ILocalUser;
public isLocalUser<T extends { host: User['host'] }>(user: T): user is T & { host: null; };
public isLocalUser(user: User | { host: User['host'] }): boolean {
return user.host == null;
}
public isRemoteUser(user: User): user is IRemoteUser {
public isRemoteUser(user: User): user is IRemoteUser;
public isRemoteUser<T extends { host: User['host'] }>(user: T): user is T & { host: string; };
public isRemoteUser(user: User | { host: User['host'] }): boolean {
return !this.isLocalUser(user);
}