import * as Sequelize from 'sequelize'
import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers'
-import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete'
import { addMethodsToModel, getSort } from '../utils'
import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface'
+import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
+import { activityPubCollection } from '../../helpers/activitypub'
+import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes>
let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
let toActivityPubObject: VideoChannelMethods.ToActivityPubObject
let isOwned: VideoChannelMethods.IsOwned
let countByAccount: VideoChannelMethods.CountByAccount
-let listOwned: VideoChannelMethods.ListOwned
let listForApi: VideoChannelMethods.ListForApi
let listByAccount: VideoChannelMethods.ListByAccount
let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
allowNull: false,
validate: {
urlValid: value => {
- const res = isVideoChannelUrlValid(value)
+ const res = isActivityPubUrlValid(value)
if (res === false) throw new Error('Video channel URL is not valid.')
}
}
listForApi,
listByAccount,
- listOwned,
loadByIdAndAccount,
loadAndPopulateAccount,
loadByUUIDAndPopulateAccount,
}
toActivityPubObject = function (this: VideoChannelInstance) {
+ let sharesObject
+ if (Array.isArray(this.VideoChannelShares)) {
+ const shares: string[] = []
+
+ for (const videoChannelShare of this.VideoChannelShares) {
+ const shareUrl = getAnnounceActivityPubUrl(this.url, videoChannelShare.Account)
+ shares.push(shareUrl)
+ }
+
+ sharesObject = activityPubCollection(shares)
+ }
+
const json = {
type: 'VideoChannel' as 'VideoChannel',
id: this.url,
content: this.description,
name: this.name,
published: this.createdAt.toISOString(),
- updated: this.updatedAt.toISOString()
+ updated: this.updatedAt.toISOString(),
+ shares: sharesObject
}
return json
return VideoChannel.count(query)
}
-listOwned = function () {
- const query = {
- where: {
- remote: false
- },
- include: [ VideoChannel['sequelize'].models.Account ]
- }
-
- return VideoChannel.findAll(query)
-}
-
listForApi = function (start: number, count: number, sort: string) {
const query = {
offset: start,