Table,
UpdatedAt
} from 'sequelize-typescript'
-import { ActivityPubActorType } from '../../../shared/models/activitypub'
+import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub'
import { Avatar } from '../../../shared/models/avatars/avatar.model'
import { activityPubContextify } from '../../helpers/activitypub'
import {
MActorFull,
MActorHost,
MActorServer,
- MActorSummaryFormattable,
+ MActorSummaryFormattable, MActorUrl,
MActorWithInboxes
} from '../../typings/models'
import * as Bluebird from 'bluebird'
})
VideoChannel: VideoChannelModel
- private static cache: { [ id: string ]: any } = {}
+ private static localNameCache: { [ id: string ]: any } = {}
+ private static localUrlCache: { [ id: string ]: any } = {}
static load (id: number): Bluebird<MActor> {
return ActorModel.unscoped().findByPk(id)
const query = {
where: {
followersUrl: {
- [ Op.in ]: followersUrls
+ [Op.in]: followersUrls
}
},
transaction
static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> {
// The server actor never change, so we can easily cache it
- if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.cache[preferredUsername]) {
- return Bluebird.resolve(ActorModel.cache[preferredUsername])
+ if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localNameCache[preferredUsername]) {
+ return Bluebird.resolve(ActorModel.localNameCache[preferredUsername])
}
const query = {
.findOne(query)
.then(actor => {
if (preferredUsername === SERVER_ACTOR_NAME) {
- ActorModel.cache[ preferredUsername ] = actor
+ ActorModel.localNameCache[preferredUsername] = actor
+ }
+
+ return actor
+ })
+ }
+
+ static loadLocalUrlByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorUrl> {
+ // The server actor never change, so we can easily cache it
+ if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localUrlCache[preferredUsername]) {
+ return Bluebird.resolve(ActorModel.localUrlCache[preferredUsername])
+ }
+
+ const query = {
+ attributes: [ 'url' ],
+ where: {
+ preferredUsername,
+ serverId: null
+ },
+ transaction
+ }
+
+ return ActorModel.unscoped()
+ .findOne(query)
+ .then(actor => {
+ if (preferredUsername === SERVER_ACTOR_NAME) {
+ ActorModel.localUrlCache[preferredUsername] = actor
}
return actor
}
toActivityPubObject (this: MActorAP, name: string) {
- let icon = undefined
+ let icon: ActivityIconObject
+
if (this.avatarId) {
const extension = extname(this.Avatar.filename)
+
icon = {
type: 'Image',
mediaType: extension === '.png' ? 'image/png' : 'image/jpeg',