mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-23 06:25:14 +00: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)
|
@EntityRepository(AbuseUserReport)
|
||||||
export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
|
export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
|
||||||
public packMany(
|
|
||||||
reports: any[],
|
|
||||||
) {
|
|
||||||
return Promise.all(reports.map(x => this.pack(x)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async pack(
|
public async pack(
|
||||||
src: AbuseUserReport['id'] | AbuseUserReport,
|
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)
|
@EntityRepository(Blocking)
|
||||||
export class BlockingRepository extends Repository<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(
|
public async pack(
|
||||||
src: Blocking['id'] | Blocking,
|
src: Blocking['id'] | Blocking,
|
||||||
me?: any
|
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 = {
|
export const packedBlockingSchema = {
|
||||||
|
|
|
@ -67,17 +67,6 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||||
return parseInt(sum, 10) || 0;
|
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(
|
public async pack(
|
||||||
src: DriveFile['id'] | DriveFile,
|
src: DriveFile['id'] | DriveFile,
|
||||||
options?: {
|
options?: {
|
||||||
|
@ -111,6 +100,17 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||||
user: opts.withUser ? Users.pack(file.userId!) : null
|
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 = {
|
export const packedDriveFileSchema = {
|
||||||
|
|
|
@ -49,17 +49,6 @@ export class FollowingRepository extends Repository<Following> {
|
||||||
return following.followeeHost != null;
|
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(
|
public async pack(
|
||||||
src: Following['id'] | Following,
|
src: Following['id'] | Following,
|
||||||
me?: any,
|
me?: any,
|
||||||
|
@ -85,6 +74,17 @@ export class FollowingRepository extends Repository<Following> {
|
||||||
}) : undefined,
|
}) : 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 = {
|
export const packedFollowingSchema = {
|
||||||
|
|
|
@ -6,12 +6,6 @@ export type PackedHashtag = SchemaType<typeof packedHashtagSchema>;
|
||||||
|
|
||||||
@EntityRepository(Hashtag)
|
@EntityRepository(Hashtag)
|
||||||
export class HashtagRepository extends Repository<Hashtag> {
|
export class HashtagRepository extends Repository<Hashtag> {
|
||||||
public packMany(
|
|
||||||
hashtags: Hashtag[],
|
|
||||||
) {
|
|
||||||
return Promise.all(hashtags.map(x => this.pack(x)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Hashtag,
|
src: Hashtag,
|
||||||
): Promise<PackedHashtag> {
|
): Promise<PackedHashtag> {
|
||||||
|
@ -25,6 +19,12 @@ export class HashtagRepository extends Repository<Hashtag> {
|
||||||
attachedRemoteUsersCount: src.attachedRemoteUsersCount,
|
attachedRemoteUsersCount: src.attachedRemoteUsersCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public packMany(
|
||||||
|
hashtags: Hashtag[],
|
||||||
|
) {
|
||||||
|
return Promise.all(hashtags.map(x => this.pack(x)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const packedHashtagSchema = {
|
export const packedHashtagSchema = {
|
||||||
|
|
|
@ -9,13 +9,6 @@ export type PackedMuting = SchemaType<typeof packedMutingSchema>;
|
||||||
|
|
||||||
@EntityRepository(Muting)
|
@EntityRepository(Muting)
|
||||||
export class MutingRepository extends Repository<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(
|
public async pack(
|
||||||
src: Muting['id'] | Muting,
|
src: Muting['id'] | Muting,
|
||||||
me?: any
|
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 = {
|
export const packedMutingSchema = {
|
||||||
|
|
|
@ -5,13 +5,6 @@ import { ensure } from '../../prelude/ensure';
|
||||||
|
|
||||||
@EntityRepository(NoteFavorite)
|
@EntityRepository(NoteFavorite)
|
||||||
export class NoteFavoriteRepository extends Repository<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(
|
public async pack(
|
||||||
src: NoteFavorite['id'] | NoteFavorite,
|
src: NoteFavorite['id'] | NoteFavorite,
|
||||||
me?: any
|
me?: any
|
||||||
|
@ -23,4 +16,11 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
||||||
note: await Notes.pack(favorite.note || favorite.noteId, me),
|
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(
|
public async pack(
|
||||||
src: Note['id'] | Note,
|
src: Note['id'] | Note,
|
||||||
me?: User['id'] | User | null | undefined,
|
me?: User['id'] | User | null | undefined,
|
||||||
|
@ -214,6 +203,17 @@ export class NoteRepository extends Repository<Note> {
|
||||||
|
|
||||||
return packed;
|
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 = {
|
export const packedNoteSchema = {
|
||||||
|
|
|
@ -9,12 +9,6 @@ export type PackedNotification = SchemaType<typeof packedNotificationSchema>;
|
||||||
|
|
||||||
@EntityRepository(Notification)
|
@EntityRepository(Notification)
|
||||||
export class NotificationRepository extends Repository<Notification> {
|
export class NotificationRepository extends Repository<Notification> {
|
||||||
public packMany(
|
|
||||||
notifications: any[],
|
|
||||||
) {
|
|
||||||
return Promise.all(notifications.map(x => this.pack(x)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Notification['id'] | Notification,
|
src: Notification['id'] | Notification,
|
||||||
): Promise<PackedNotification> {
|
): 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 = {
|
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(
|
public async pack(
|
||||||
src: User['id'] | User,
|
src: User['id'] | User,
|
||||||
me?: User['id'] | User | null | undefined,
|
me?: User['id'] | User | null | undefined,
|
||||||
|
@ -187,6 +175,18 @@ export class UserRepository extends Repository<User> {
|
||||||
return await awaitAll(packed);
|
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 {
|
public isLocalUser(user: User): user is ILocalUser {
|
||||||
return user.host == null;
|
return user.host == null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue