isActorPublicKeyValid
} from '../../helpers/custom-validators/activitypub/actor'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
-import { ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
+import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
import { AccountModel } from '../account/account'
import { AvatarModel } from '../avatar/avatar'
import { ServerModel } from '../server/server'
[ScopeNames.FULL]: {
include: [
{
- model: () => AccountModel,
+ model: () => AccountModel.unscoped(),
required: false
},
{
- model: () => VideoChannelModel,
+ model: () => VideoChannelModel.unscoped(),
required: false
},
{
@Table({
tableName: 'actor',
indexes: [
+ {
+ fields: [ 'url' ]
+ },
{
fields: [ 'preferredUsername', 'serverId' ],
unique: true
+ },
+ {
+ fields: [ 'inboxUrl', 'sharedInboxUrl' ]
}
]
})
foreignKey: {
allowNull: true
},
- onDelete: 'set null'
+ onDelete: 'set null',
+ hooks: true
})
Avatar: AvatarModel
},
onDelete: 'cascade'
})
- AccountFollowing: ActorFollowModel[]
+ ActorFollowing: ActorFollowModel[]
@HasMany(() => ActorFollowModel, {
foreignKey: {
name: 'targetActorId',
allowNull: false
},
- as: 'followers',
+ as: 'ActorFollowers',
onDelete: 'cascade'
})
- AccountFollowers: ActorFollowModel[]
+ ActorFollowers: ActorFollowModel[]
@ForeignKey(() => ServerModel)
@Column
foreignKey: {
allowNull: true
},
- onDelete: 'cascade'
+ onDelete: 'cascade',
+ hooks: true
})
Account: AccountModel
foreignKey: {
allowNull: true
},
- onDelete: 'cascade'
+ onDelete: 'cascade',
+ hooks: true
})
VideoChannel: VideoChannelModel
static load (id: number) {
- return ActorModel.scope(ScopeNames.FULL).findById(id)
+ return ActorModel.unscoped().findById(id)
}
static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) {
return ActorModel.scope(ScopeNames.FULL).findOne(query)
}
+ static incrementFollows (id: number, column: 'followersCount' | 'followingCount', by: number) {
+ // FIXME: typings
+ return (ActorModel as any).increment(column, {
+ by,
+ where: {
+ id
+ }
+ })
+ }
+
+ static async getActorsFollowerSharedInboxUrls (actors: ActorModel[], t: Sequelize.Transaction) {
+ const query = {
+ // attribute: [],
+ where: {
+ id: {
+ [Sequelize.Op.in]: actors.map(a => a.id)
+ }
+ },
+ include: [
+ {
+ // attributes: [ ],
+ model: ActorFollowModel.unscoped(),
+ required: true,
+ as: 'ActorFollowers',
+ where: {
+ state: 'accepted'
+ },
+ include: [
+ {
+ attributes: [ 'sharedInboxUrl' ],
+ model: ActorModel.unscoped(),
+ as: 'ActorFollower',
+ required: true
+ }
+ ]
+ }
+ ],
+ transaction: t
+ }
+
+ const hash: { [ id: number ]: string[] } = {}
+ const res = await ActorModel.findAll(query)
+ for (const actor of res) {
+ hash[actor.id] = actor.ActorFollowers.map(follow => follow.ActorFollower.sharedInboxUrl)
+ }
+
+ return hash
+ }
+
toFormattedJSON () {
let avatar: Avatar = null
if (this.Avatar) {
avatar = this.Avatar.toFormattedJSON()
}
- let score: number
- if (this.Server) {
- score = this.Server.score
- }
-
return {
id: this.id,
url: this.url,
uuid: this.uuid,
+ name: this.preferredUsername,
host: this.getHost(),
- score,
followingCount: this.followingCount,
followersCount: this.followersCount,
- avatar
+ avatar,
+ createdAt: this.createdAt,
+ updatedAt: this.updatedAt
}
}
attributes: [ 'sharedInboxUrl' ],
include: [
{
- model: ActorFollowModel,
+ attribute: [],
+ model: ActorFollowModel.unscoped(),
required: true,
- as: 'followers',
+ as: 'ActorFollowing',
where: {
+ state: 'accepted',
targetActorId: this.id
}
}
return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath()
}
+
+ 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
+ }
}