import { AccountModel } from '../account/account'
import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
-import { throwIfNotValid } from '../utils'
+import { isOutdated, throwIfNotValid } from '../utils'
import { VideoChannelModel } from '../video/video-channel'
import { ActorFollowModel } from './actor-follow'
+import { VideoModel } from '../video/video'
enum ScopeNames {
FULL = 'FULL'
},
{
model: () => VideoChannelModel.unscoped(),
- required: false
+ required: false,
+ include: [
+ {
+ model: () => AccountModel,
+ required: true
+ }
+ ]
},
{
model: () => ServerModel,
name: 'actorId',
allowNull: false
},
+ as: 'ActorFollowings',
onDelete: 'cascade'
})
ActorFollowing: ActorFollowModel[]
VideoChannel: VideoChannelModel
static load (id: number) {
- return ActorModel.unscoped().findById(id)
+ return ActorModel.unscoped().findByPk(id)
+ }
+
+ static loadAccountActorByVideoId (videoId: number, transaction: Sequelize.Transaction) {
+ const query = {
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: VideoChannelModel.unscoped(),
+ required: true,
+ include: {
+ attributes: [ 'id' ],
+ model: VideoModel.unscoped(),
+ required: true,
+ where: {
+ id: videoId
+ }
+ }
+ }
+ ]
+ }
+ ],
+ transaction
+ }
+
+ return ActorModel.unscoped().findOne(query as any) // FIXME: typings
+ }
+
+ static isActorUrlExist (url: string) {
+ const query = {
+ raw: true,
+ where: {
+ url
+ }
+ }
+
+ return ActorModel.unscoped().findOne(query)
+ .then(a => !!a)
}
static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) {
}
static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
+ const query = {
+ where: {
+ url
+ },
+ transaction,
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: AccountModel.unscoped(),
+ required: false
+ },
+ {
+ attributes: [ 'id' ],
+ model: VideoChannelModel.unscoped(),
+ required: false
+ }
+ ]
+ }
+
+ return ActorModel.unscoped().findOne(query)
+ }
+
+ static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction) {
const query = {
where: {
url
uuid: this.uuid,
name: this.preferredUsername,
host: this.getHost(),
+ hostRedundancyAllowed: this.getRedundancyAllowed(),
followingCount: this.followingCount,
followersCount: this.followersCount,
avatar,
id: this.url,
following: this.getFollowingUrl(),
followers: this.getFollowersUrl(),
+ playlists: this.getPlaylistsUrl(),
inbox: this.inboxUrl,
outbox: this.outboxUrl,
preferredUsername: this.preferredUsername,
return this.url + '/followers'
}
+ getPlaylistsUrl () {
+ return this.url + '/playlists'
+ }
+
getPublicKeyUrl () {
return this.url + '#main-key'
}
return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST
}
+ getRedundancyAllowed () {
+ return this.Server ? this.Server.redundancyAllowed : false
+ }
+
getAvatarUrl () {
if (!this.avatarId) return undefined
isOutdated () {
if (this.isOwned()) return false
- const now = Date.now()
- const createdAtTime = this.createdAt.getTime()
- const updatedAtTime = this.updatedAt.getTime()
-
- return (now - createdAtTime) > ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL &&
- (now - updatedAtTime) > ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL
+ return isOutdated(this, ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL)
}
}