feat: チャンネルをお気に入りに登録できるように

Resolve #10097
This commit is contained in:
syuilo
2023-03-31 11:30:27 +09:00
parent 5d94062581
commit 3cb0cc7989
17 changed files with 327 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Notification, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, AntennaNote, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelNotePining, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite } from './index.js';
import { User, Note, Announcement, AnnouncementRead, App, NoteFavorite, NoteThreadMuting, NoteReaction, NoteUnread, Notification, Poll, PollVote, UserProfile, UserKeypair, UserPending, AttestationChallenge, UserSecurityKey, UserPublickey, UserList, UserListJoining, UserNotePining, UserIp, UsedUsername, Following, FollowRequest, Instance, Emoji, DriveFile, DriveFolder, Meta, Muting, RenoteMuting, Blocking, SwSubscription, Hashtag, AbuseUserReport, RegistrationTicket, AuthSession, AccessToken, Signin, Page, PageLike, GalleryPost, GalleryLike, ModerationLog, Clip, ClipNote, Antenna, AntennaNote, PromoNote, PromoRead, Relay, MutedNote, Channel, ChannelFollowing, ChannelFavorite, ChannelNotePining, RegistryItem, Webhook, Ad, PasswordResetRequest, RetentionAggregation, FlashLike, Flash, Role, RoleAssignment, ClipFavorite } from './index.js';
import type { DataSource } from 'typeorm';
import type { Provider } from '@nestjs/common';
@@ -340,6 +340,12 @@ const $channelFollowingsRepository: Provider = {
inject: [DI.db],
};
const $channelFavoritesRepository: Provider = {
provide: DI.channelFavoritesRepository,
useFactory: (db: DataSource) => db.getRepository(ChannelFavorite),
inject: [DI.db],
};
const $channelNotePiningsRepository: Provider = {
provide: DI.channelNotePiningsRepository,
useFactory: (db: DataSource) => db.getRepository(ChannelNotePining),
@@ -460,6 +466,7 @@ const $roleAssignmentsRepository: Provider = {
$mutedNotesRepository,
$channelsRepository,
$channelFollowingsRepository,
$channelFavoritesRepository,
$channelNotePiningsRepository,
$registryItemsRepository,
$webhooksRepository,
@@ -528,6 +535,7 @@ const $roleAssignmentsRepository: Provider = {
$mutedNotesRepository,
$channelsRepository,
$channelFollowingsRepository,
$channelFavoritesRepository,
$channelNotePiningsRepository,
$registryItemsRepository,
$webhooksRepository,

View File

@@ -0,0 +1,41 @@
import { PrimaryColumn, Entity, Index, JoinColumn, Column, ManyToOne } from 'typeorm';
import { id } from '../id.js';
import { User } from './User.js';
import { Channel } from './Channel.js';
@Entity()
@Index(['userId', 'channelId'], { unique: true })
export class ChannelFavorite {
@PrimaryColumn(id())
public id: string;
@Index()
@Column('timestamp with time zone', {
comment: 'The created date of the ChannelFavorite.',
})
public createdAt: Date;
@Index()
@Column({
...id(),
})
public channelId: Channel['id'];
@ManyToOne(type => Channel, {
onDelete: 'CASCADE',
})
@JoinColumn()
public channel: Channel | null;
@Index()
@Column({
...id(),
})
public userId: User['id'];
@ManyToOne(type => User, {
onDelete: 'CASCADE',
})
@JoinColumn()
public user: User | null;
}

View File

@@ -10,6 +10,7 @@ import { AttestationChallenge } from '@/models/entities/AttestationChallenge.js'
import { AuthSession } from '@/models/entities/AuthSession.js';
import { Blocking } from '@/models/entities/Blocking.js';
import { ChannelFollowing } from '@/models/entities/ChannelFollowing.js';
import { ChannelFavorite } from '@/models/entities/ChannelFavorite.js';
import { ChannelNotePining } from '@/models/entities/ChannelNotePining.js';
import { Clip } from '@/models/entities/Clip.js';
import { ClipNote } from '@/models/entities/ClipNote.js';
@@ -79,6 +80,7 @@ export {
AuthSession,
Blocking,
ChannelFollowing,
ChannelFavorite,
ChannelNotePining,
Clip,
ClipNote,
@@ -147,6 +149,7 @@ export type AttestationChallengesRepository = Repository<AttestationChallenge>;
export type AuthSessionsRepository = Repository<AuthSession>;
export type BlockingsRepository = Repository<Blocking>;
export type ChannelFollowingsRepository = Repository<ChannelFollowing>;
export type ChannelFavoritesRepository = Repository<ChannelFavorite>;
export type ChannelNotePiningsRepository = Repository<ChannelNotePining>;
export type ClipsRepository = Repository<Clip>;
export type ClipNotesRepository = Repository<ClipNote>;

View File

@@ -42,6 +42,10 @@ export const packedChannelSchema = {
type: 'boolean',
optional: true, nullable: false,
},
isFavorited: {
type: 'boolean',
optional: true, nullable: false,
},
userId: {
type: 'string',
nullable: true, optional: false,