diff options
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r-- | server/models/video/video-channel.ts | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 0fb52827e..19dd681a7 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,5 +1,8 @@ | |||
1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction, WhereOptions } from 'sequelize' | 1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction, WhereOptions } from 'sequelize' |
2 | import { | 2 | import { |
3 | AfterCreate, | ||
4 | AfterDestroy, | ||
5 | AfterUpdate, | ||
3 | AllowNull, | 6 | AllowNull, |
4 | BeforeDestroy, | 7 | BeforeDestroy, |
5 | BelongsTo, | 8 | BelongsTo, |
@@ -18,7 +21,8 @@ import { | |||
18 | UpdatedAt | 21 | UpdatedAt |
19 | } from 'sequelize-typescript' | 22 | } from 'sequelize-typescript' |
20 | import { CONFIG } from '@server/initializers/config' | 23 | import { CONFIG } from '@server/initializers/config' |
21 | import { MAccountActor } from '@server/types/models' | 24 | import { InternalEventEmitter } from '@server/lib/internal-event-emitter' |
25 | import { MAccountHost } from '@server/types/models' | ||
22 | import { forceNumber, pick } from '@shared/core-utils' | 26 | import { forceNumber, pick } from '@shared/core-utils' |
23 | import { AttributesOnly } from '@shared/typescript-utils' | 27 | import { AttributesOnly } from '@shared/typescript-utils' |
24 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 28 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
@@ -36,6 +40,7 @@ import { | |||
36 | MChannelAP, | 40 | MChannelAP, |
37 | MChannelBannerAccountDefault, | 41 | MChannelBannerAccountDefault, |
38 | MChannelFormattable, | 42 | MChannelFormattable, |
43 | MChannelHost, | ||
39 | MChannelSummaryFormattable | 44 | MChannelSummaryFormattable |
40 | } from '../../types/models/video' | 45 | } from '../../types/models/video' |
41 | import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' | 46 | import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' |
@@ -416,6 +421,21 @@ export class VideoChannelModel extends Model<Partial<AttributesOnly<VideoChannel | |||
416 | }) | 421 | }) |
417 | VideoPlaylists: VideoPlaylistModel[] | 422 | VideoPlaylists: VideoPlaylistModel[] |
418 | 423 | ||
424 | @AfterCreate | ||
425 | static notifyCreate (channel: MChannel) { | ||
426 | InternalEventEmitter.Instance.emit('channel-created', { channel }) | ||
427 | } | ||
428 | |||
429 | @AfterUpdate | ||
430 | static notifyUpdate (channel: MChannel) { | ||
431 | InternalEventEmitter.Instance.emit('channel-updated', { channel }) | ||
432 | } | ||
433 | |||
434 | @AfterDestroy | ||
435 | static notifyDestroy (channel: MChannel) { | ||
436 | InternalEventEmitter.Instance.emit('channel-deleted', { channel }) | ||
437 | } | ||
438 | |||
419 | @BeforeDestroy | 439 | @BeforeDestroy |
420 | static async sendDeleteIfOwned (instance: VideoChannelModel, options) { | 440 | static async sendDeleteIfOwned (instance: VideoChannelModel, options) { |
421 | if (!instance.Actor) { | 441 | if (!instance.Actor) { |
@@ -827,8 +847,9 @@ export class VideoChannelModel extends Model<Partial<AttributesOnly<VideoChannel | |||
827 | }) | 847 | }) |
828 | } | 848 | } |
829 | 849 | ||
830 | getLocalUrl (this: MAccountActor | MChannelActor) { | 850 | // Avoid error when running this method on MAccount... | MChannel... |
831 | return WEBSERVER.URL + `/video-channels/` + this.Actor.preferredUsername | 851 | getClientUrl (this: MAccountHost | MChannelHost) { |
852 | return WEBSERVER.URL + '/c/' + this.Actor.getIdentifier() | ||
832 | } | 853 | } |
833 | 854 | ||
834 | getDisplayName () { | 855 | getDisplayName () { |