import { extname } from 'path'
import * as Sequelize from 'sequelize'
import {
- AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, DefaultScope, ForeignKey, HasMany, HasOne, Is, IsUUID, Model, Scopes,
- Table, UpdatedAt
+ AllowNull,
+ BelongsTo,
+ Column,
+ CreatedAt,
+ DataType,
+ Default,
+ DefaultScope,
+ ForeignKey,
+ HasMany,
+ HasOne,
+ Is,
+ IsUUID,
+ Model,
+ Scopes,
+ Table,
+ UpdatedAt
} from 'sequelize-typescript'
import { ActivityPubActorType } from '../../../shared/models/activitypub'
import { Avatar } from '../../../shared/models/avatars/avatar.model'
import { activityPubContextify } from '../../helpers/activitypub'
import {
- isActorFollowersCountValid, isActorFollowingCountValid, isActorPreferredUsernameValid, isActorPrivateKeyValid,
+ isActorFollowersCountValid,
+ isActorFollowingCountValid,
+ isActorPreferredUsernameValid,
+ isActorPrivateKeyValid,
isActorPublicKeyValid
} from '../../helpers/custom-validators/activitypub/actor'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
FULL = 'FULL'
}
+export const unusedActorAttributesForAPI = [
+ 'publicKey',
+ 'privateKey',
+ 'inboxUrl',
+ 'outboxUrl',
+ 'sharedInboxUrl',
+ 'followersUrl',
+ 'followingUrl',
+ 'url',
+ 'createdAt',
+ 'updatedAt'
+]
+
@DefaultScope({
include: [
{
tableName: 'actor',
indexes: [
{
- fields: [ 'url' ]
+ fields: [ 'url' ],
+ unique: true
},
{
fields: [ 'preferredUsername', 'serverId' ],
},
{
fields: [ 'inboxUrl', 'sharedInboxUrl' ]
+ },
+ {
+ fields: [ 'sharedInboxUrl' ]
+ },
+ {
+ fields: [ 'serverId' ]
+ },
+ {
+ fields: [ 'avatarId' ]
+ },
+ {
+ fields: [ 'uuid' ],
+ unique: true
+ },
+ {
+ fields: [ 'followersUrl' ]
}
]
})
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
return ActorModel.scope(ScopeNames.FULL).findAll(query)
}
- static loadLocalByName (preferredUsername: string) {
+ static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction) {
const query = {
where: {
preferredUsername,
serverId: null
- }
+ },
+ transaction
}
return ActorModel.scope(ScopeNames.FULL).findOne(query)
attributes: [ 'sharedInboxUrl' ],
include: [
{
- model: ActorFollowModel,
+ attribute: [],
+ model: ActorFollowModel.unscoped(),
required: true,
- as: 'followers',
+ as: 'ActorFollowing',
where: {
+ state: 'accepted',
targetActorId: this.id
}
}
return 'acct:' + this.preferredUsername + '@' + this.getHost()
}
+ getIdentifier () {
+ return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername
+ }
+
getHost () {
return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST
}