mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 16:43:09 +02:00
Refactor
This commit is contained in:
parent
6721d27e3f
commit
4cb58c0892
10 changed files with 84 additions and 84 deletions
|
@ -6,12 +6,6 @@ import { awaitAll } from '../../prelude/await-all';
|
|||
|
||||
@EntityRepository(AbuseUserReport)
|
||||
export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
|
||||
public packMany(
|
||||
reports: any[],
|
||||
) {
|
||||
return Promise.all(reports.map(x => this.pack(x)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: AbuseUserReport['id'] | AbuseUserReport,
|
||||
) {
|
||||
|
@ -30,4 +24,10 @@ export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
|
|||
}),
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
reports: any[],
|
||||
) {
|
||||
return Promise.all(reports.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,6 @@ export type PackedBlocking = SchemaType<typeof packedBlockingSchema>;
|
|||
|
||||
@EntityRepository(Blocking)
|
||||
export class BlockingRepository extends Repository<Blocking> {
|
||||
public packMany(
|
||||
blockings: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(blockings.map(x => this.pack(x, me)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Blocking['id'] | Blocking,
|
||||
me?: any
|
||||
|
@ -31,6 +24,13 @@ export class BlockingRepository extends Repository<Blocking> {
|
|||
})
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
blockings: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(blockings.map(x => this.pack(x, me)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedBlockingSchema = {
|
||||
|
|
|
@ -67,17 +67,6 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
|||
return parseInt(sum, 10) || 0;
|
||||
}
|
||||
|
||||
public packMany(
|
||||
files: any[],
|
||||
options?: {
|
||||
detail?: boolean
|
||||
self?: boolean,
|
||||
withUser?: boolean,
|
||||
}
|
||||
) {
|
||||
return Promise.all(files.map(f => this.pack(f, options)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: DriveFile['id'] | DriveFile,
|
||||
options?: {
|
||||
|
@ -111,6 +100,17 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
|||
user: opts.withUser ? Users.pack(file.userId!) : null
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
files: any[],
|
||||
options?: {
|
||||
detail?: boolean
|
||||
self?: boolean,
|
||||
withUser?: boolean,
|
||||
}
|
||||
) {
|
||||
return Promise.all(files.map(f => this.pack(f, options)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedDriveFileSchema = {
|
||||
|
|
|
@ -49,17 +49,6 @@ export class FollowingRepository extends Repository<Following> {
|
|||
return following.followeeHost != null;
|
||||
}
|
||||
|
||||
public packMany(
|
||||
followings: any[],
|
||||
me?: any,
|
||||
opts?: {
|
||||
populateFollowee?: boolean;
|
||||
populateFollower?: boolean;
|
||||
}
|
||||
) {
|
||||
return Promise.all(followings.map(x => this.pack(x, me, opts)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Following['id'] | Following,
|
||||
me?: any,
|
||||
|
@ -85,6 +74,17 @@ export class FollowingRepository extends Repository<Following> {
|
|||
}) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
followings: any[],
|
||||
me?: any,
|
||||
opts?: {
|
||||
populateFollowee?: boolean;
|
||||
populateFollower?: boolean;
|
||||
}
|
||||
) {
|
||||
return Promise.all(followings.map(x => this.pack(x, me, opts)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedFollowingSchema = {
|
||||
|
|
|
@ -6,12 +6,6 @@ export type PackedHashtag = SchemaType<typeof packedHashtagSchema>;
|
|||
|
||||
@EntityRepository(Hashtag)
|
||||
export class HashtagRepository extends Repository<Hashtag> {
|
||||
public packMany(
|
||||
hashtags: Hashtag[],
|
||||
) {
|
||||
return Promise.all(hashtags.map(x => this.pack(x)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Hashtag,
|
||||
): Promise<PackedHashtag> {
|
||||
|
@ -25,6 +19,12 @@ export class HashtagRepository extends Repository<Hashtag> {
|
|||
attachedRemoteUsersCount: src.attachedRemoteUsersCount,
|
||||
};
|
||||
}
|
||||
|
||||
public packMany(
|
||||
hashtags: Hashtag[],
|
||||
) {
|
||||
return Promise.all(hashtags.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedHashtagSchema = {
|
||||
|
|
|
@ -9,13 +9,6 @@ export type PackedMuting = SchemaType<typeof packedMutingSchema>;
|
|||
|
||||
@EntityRepository(Muting)
|
||||
export class MutingRepository extends Repository<Muting> {
|
||||
public packMany(
|
||||
mutings: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(mutings.map(x => this.pack(x, me)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Muting['id'] | Muting,
|
||||
me?: any
|
||||
|
@ -31,6 +24,13 @@ export class MutingRepository extends Repository<Muting> {
|
|||
})
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
mutings: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(mutings.map(x => this.pack(x, me)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedMutingSchema = {
|
||||
|
|
|
@ -5,13 +5,6 @@ import { ensure } from '../../prelude/ensure';
|
|||
|
||||
@EntityRepository(NoteFavorite)
|
||||
export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
||||
public packMany(
|
||||
favorites: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(favorites.map(x => this.pack(x, me)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: NoteFavorite['id'] | NoteFavorite,
|
||||
me?: any
|
||||
|
@ -23,4 +16,11 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
|||
note: await Notes.pack(favorite.note || favorite.noteId, me),
|
||||
};
|
||||
}
|
||||
|
||||
public packMany(
|
||||
favorites: any[],
|
||||
me: any
|
||||
) {
|
||||
return Promise.all(favorites.map(x => this.pack(x, me)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,17 +76,6 @@ export class NoteRepository extends Repository<Note> {
|
|||
}
|
||||
}
|
||||
|
||||
public packMany(
|
||||
notes: (Note['id'] | Note)[],
|
||||
me?: User['id'] | User | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean;
|
||||
skipHide?: boolean;
|
||||
}
|
||||
) {
|
||||
return Promise.all(notes.map(n => this.pack(n, me, options)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Note['id'] | Note,
|
||||
me?: User['id'] | User | null | undefined,
|
||||
|
@ -214,6 +203,17 @@ export class NoteRepository extends Repository<Note> {
|
|||
|
||||
return packed;
|
||||
}
|
||||
|
||||
public packMany(
|
||||
notes: (Note['id'] | Note)[],
|
||||
me?: User['id'] | User | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean;
|
||||
skipHide?: boolean;
|
||||
}
|
||||
) {
|
||||
return Promise.all(notes.map(n => this.pack(n, me, options)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedNoteSchema = {
|
||||
|
|
|
@ -9,12 +9,6 @@ export type PackedNotification = SchemaType<typeof packedNotificationSchema>;
|
|||
|
||||
@EntityRepository(Notification)
|
||||
export class NotificationRepository extends Repository<Notification> {
|
||||
public packMany(
|
||||
notifications: any[],
|
||||
) {
|
||||
return Promise.all(notifications.map(x => this.pack(x)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: Notification['id'] | Notification,
|
||||
): Promise<PackedNotification> {
|
||||
|
@ -48,6 +42,12 @@ export class NotificationRepository extends Repository<Notification> {
|
|||
} : {})
|
||||
});
|
||||
}
|
||||
|
||||
public packMany(
|
||||
notifications: any[],
|
||||
) {
|
||||
return Promise.all(notifications.map(x => this.pack(x)));
|
||||
}
|
||||
}
|
||||
|
||||
export const packedNotificationSchema = {
|
||||
|
|
|
@ -54,18 +54,6 @@ export class UserRepository extends Repository<User> {
|
|||
};
|
||||
}
|
||||
|
||||
public packMany(
|
||||
users: (User['id'] | User)[],
|
||||
me?: User['id'] | User | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean,
|
||||
includeSecrets?: boolean,
|
||||
includeHasUnreadNotes?: boolean
|
||||
}
|
||||
) {
|
||||
return Promise.all(users.map(u => this.pack(u, me, options)));
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: User['id'] | User,
|
||||
me?: User['id'] | User | null | undefined,
|
||||
|
@ -187,6 +175,18 @@ export class UserRepository extends Repository<User> {
|
|||
return await awaitAll(packed);
|
||||
}
|
||||
|
||||
public packMany(
|
||||
users: (User['id'] | User)[],
|
||||
me?: User['id'] | User | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean,
|
||||
includeSecrets?: boolean,
|
||||
includeHasUnreadNotes?: boolean
|
||||
}
|
||||
) {
|
||||
return Promise.all(users.map(u => this.pack(u, me, options)));
|
||||
}
|
||||
|
||||
public isLocalUser(user: User): user is ILocalUser {
|
||||
return user.host == null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue