import { values } from 'lodash'
import { extname } from 'path'
-import * as Sequelize from 'sequelize'
import {
AllowNull,
BelongsTo,
MActorFormattable,
MActorFull,
MActorHost,
- MActorRedundancyAllowedOpt,
MActorServer,
- MActorSummaryFormattable
+ MActorSummaryFormattable,
+ MActorWithInboxes
} from '../../typings/models'
import * as Bluebird from 'bluebird'
+import { Op, Transaction } from 'sequelize'
enum ScopeNames {
FULL = 'FULL'
},
{
fields: [ 'preferredUsername', 'serverId' ],
- unique: true
+ unique: true,
+ where: {
+ serverId: {
+ [Op.ne]: null
+ }
+ }
},
+ // {
+ // fields: [ 'preferredUsername' ],
+ // unique: true,
+ // where: {
+ // serverId: null
+ // }
+ // },
{
fields: [ 'inboxUrl', 'sharedInboxUrl' ]
},
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
inboxUrl: string
- @AllowNull(false)
- @Is('ActorOutboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'outbox url'))
+ @AllowNull(true)
+ @Is('ActorOutboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'outbox url', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
outboxUrl: string
- @AllowNull(false)
- @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url'))
+ @AllowNull(true)
+ @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
sharedInboxUrl: string
- @AllowNull(false)
- @Is('ActorFollowersUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'followers url'))
+ @AllowNull(true)
+ @Is('ActorFollowersUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'followers url', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
followersUrl: string
- @AllowNull(false)
- @Is('ActorFollowingUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'following url'))
+ @AllowNull(true)
+ @Is('ActorFollowingUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'following url', true))
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
followingUrl: string
return ActorModel.scope(ScopeNames.FULL).findByPk(id)
}
- static loadFromAccountByVideoId (videoId: number, transaction: Sequelize.Transaction): Bluebird<MActor> {
+ static loadFromAccountByVideoId (videoId: number, transaction: Transaction): Bluebird<MActor> {
const query = {
include: [
{
.then(a => !!a)
}
- static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction): Bluebird<MActorFull[]> {
+ static listByFollowersUrls (followersUrls: string[], transaction?: Transaction): Bluebird<MActorFull[]> {
const query = {
where: {
followersUrl: {
- [ Sequelize.Op.in ]: followersUrls
+ [ Op.in ]: followersUrls
}
},
transaction
return ActorModel.scope(ScopeNames.FULL).findAll(query)
}
- static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction): Bluebird<MActorFull> {
+ static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> {
const query = {
where: {
preferredUsername,
return ActorModel.scope(ScopeNames.FULL).findOne(query)
}
- static loadByUrl (url: string, transaction?: Sequelize.Transaction): Bluebird<MActorAccountChannelId> {
+ static loadByUrl (url: string, transaction?: Transaction): Bluebird<MActorAccountChannelId> {
const query = {
where: {
url
return ActorModel.unscoped().findOne(query)
}
- static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction): Bluebird<MActorFull> {
+ static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Transaction): Bluebird<MActorFull> {
const query = {
where: {
url
})
}
+ getSharedInbox (this: MActorWithInboxes) {
+ return this.sharedInboxUrl || this.inboxUrl
+ }
+
toFormattedSummaryJSON (this: MActorSummaryFormattable) {
let avatar: Avatar = null
if (this.Avatar) {
})
}
- toActivityPubObject (this: MActorAP, name: string, type: 'Account' | 'Application' | 'VideoChannel') {
- let activityPubType
- if (type === 'Account') {
- activityPubType = 'Person' as 'Person'
- } else if (type === 'Application') {
- activityPubType = 'Application' as 'Application'
- } else { // VideoChannel
- activityPubType = 'Group' as 'Group'
- }
-
+ toActivityPubObject (this: MActorAP, name: string) {
let icon = undefined
if (this.avatarId) {
const extension = extname(this.Avatar.filename)
}
const json = {
- type: activityPubType,
+ type: this.type,
id: this.url,
following: this.getFollowingUrl(),
followers: this.getFollowersUrl(),
return activityPubContextify(json)
}
- getFollowerSharedInboxUrls (t: Sequelize.Transaction) {
+ getFollowerSharedInboxUrls (t: Transaction) {
const query = {
attributes: [ 'sharedInboxUrl' ],
include: [