+ return VideoChannelModel.unscoped()
+ .scope([ ScopeNames.WITH_ACCOUNT ])
+ .findOne(query)
+ }
+
+ static loadByNameAndHostAndPopulateAccount (name: string, host: string): Promise<MChannelBannerAccountDefault> {
+ const query = {
+ include: [
+ {
+ model: ActorModel,
+ required: true,
+ where: {
+ preferredUsername: name
+ },
+ include: [
+ {
+ model: ServerModel,
+ required: true,
+ where: { host }
+ },
+ {
+ model: ActorImageModel,
+ required: false,
+ as: 'Banners'
+ }
+ ]
+ }
+ ]
+ }
+
+ return VideoChannelModel.unscoped()
+ .scope([ ScopeNames.WITH_ACCOUNT ])
+ .findOne(query)
+ }
+
+ toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary {
+ const actor = this.Actor.toFormattedSummaryJSON()
+
+ return {
+ id: this.id,
+ name: actor.name,
+ displayName: this.getDisplayName(),
+ url: actor.url,
+ host: actor.host,
+ avatars: actor.avatars,
+
+ // TODO: remove, deprecated in 4.2
+ avatar: actor.avatar
+ }
+ }
+
+ toFormattedJSON (this: MChannelFormattable): VideoChannel {
+ const viewsPerDayString = this.get('viewsPerDay') as string
+ const videosCount = this.get('videosCount') as number
+
+ let viewsPerDay: { date: Date, views: number }[]
+
+ if (viewsPerDayString) {
+ viewsPerDay = viewsPerDayString.split(',')
+ .map(v => {
+ const [ dateString, amount ] = v.split('|')
+
+ return {
+ date: new Date(dateString),
+ views: +amount
+ }
+ })
+ }
+
+ const actor = this.Actor.toFormattedJSON()
+ const videoChannel = {
+ id: this.id,
+ displayName: this.getDisplayName(),
+ description: this.description,
+ support: this.support,
+ isLocal: this.Actor.isOwned(),
+ updatedAt: this.updatedAt,
+
+ ownerAccount: undefined,
+
+ videosCount,
+ viewsPerDay,
+
+ avatars: actor.avatars,
+
+ // TODO: remove, deprecated in 4.2
+ avatar: actor.avatar
+ }
+
+ if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON()
+
+ return Object.assign(actor, videoChannel)
+ }
+
+ toActivityPubObject (this: MChannelAP): ActivityPubActor {
+ const obj = this.Actor.toActivityPubObject(this.name)
+
+ return Object.assign(obj, {
+ summary: this.description,
+ support: this.support,
+ attributedTo: [
+ {
+ type: 'Person' as 'Person',
+ id: this.Account.Actor.url
+ }
+ ]
+ })