aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub/actor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/activitypub/actor.ts')
-rw-r--r--server/models/activitypub/actor.ts67
1 files changed, 23 insertions, 44 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 8cedcc2bc..e7eb35e2c 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -2,32 +2,15 @@ import { values } from 'lodash'
2import { join } from 'path' 2import { join } from 'path'
3import * as Sequelize from 'sequelize' 3import * as Sequelize from 'sequelize'
4import { 4import {
5 AllowNull, 5 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, DefaultScope, ForeignKey, HasMany, HasOne, Is, IsUUID, Model, Scopes,
6 BelongsTo, 6 Table, UpdatedAt
7 Column,
8 CreatedAt,
9 DataType,
10 Default, DefaultScope,
11 ForeignKey,
12 HasMany,
13 HasOne,
14 Is,
15 IsUUID,
16 Model,
17 Scopes,
18 Table,
19 UpdatedAt
20} from 'sequelize-typescript' 7} from 'sequelize-typescript'
21import { ActivityPubActorType } from '../../../shared/models/activitypub' 8import { ActivityPubActorType } from '../../../shared/models/activitypub'
22import { Avatar } from '../../../shared/models/avatars/avatar.model' 9import { Avatar } from '../../../shared/models/avatars/avatar.model'
23import { activityPubContextify } from '../../helpers' 10import { activityPubContextify } from '../../helpers'
24import { 11import {
25 isActivityPubUrlValid, 12 isActivityPubUrlValid, isActorFollowersCountValid, isActorFollowingCountValid, isActorPreferredUsernameValid,
26 isActorFollowersCountValid, 13 isActorPrivateKeyValid, isActorPublicKeyValid
27 isActorFollowingCountValid,
28 isActorNameValid,
29 isActorPrivateKeyValid,
30 isActorPublicKeyValid
31} from '../../helpers/custom-validators/activitypub' 14} from '../../helpers/custom-validators/activitypub'
32import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 15import { ACTIVITY_PUB_ACTOR_TYPES, AVATARS_DIR, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
33import { AccountModel } from '../account/account' 16import { AccountModel } from '../account/account'
@@ -71,7 +54,7 @@ enum ScopeNames {
71 tableName: 'actor', 54 tableName: 'actor',
72 indexes: [ 55 indexes: [
73 { 56 {
74 fields: [ 'name', 'serverId' ], 57 fields: [ 'preferredUsername', 'serverId' ],
75 unique: true 58 unique: true
76 } 59 }
77 ] 60 ]
@@ -89,9 +72,9 @@ export class ActorModel extends Model<ActorModel> {
89 uuid: string 72 uuid: string
90 73
91 @AllowNull(false) 74 @AllowNull(false)
92 @Is('ActorName', value => throwIfNotValid(value, isActorNameValid, 'actor name')) 75 @Is('ActorPreferredUsername', value => throwIfNotValid(value, isActorPreferredUsernameValid, 'actor preferred username'))
93 @Column 76 @Column
94 name: string 77 preferredUsername: string
95 78
96 @AllowNull(false) 79 @AllowNull(false)
97 @Is('ActorUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 80 @Is('ActorUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
@@ -212,16 +195,6 @@ export class ActorModel extends Model<ActorModel> {
212 return ActorModel.scope(ScopeNames.FULL).findById(id) 195 return ActorModel.scope(ScopeNames.FULL).findById(id)
213 } 196 }
214 197
215 static loadByUUID (uuid: string) {
216 const query = {
217 where: {
218 uuid
219 }
220 }
221
222 return ActorModel.scope(ScopeNames.FULL).findOne(query)
223 }
224
225 static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) { 198 static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) {
226 const query = { 199 const query = {
227 where: { 200 where: {
@@ -235,10 +208,10 @@ export class ActorModel extends Model<ActorModel> {
235 return ActorModel.scope(ScopeNames.FULL).findAll(query) 208 return ActorModel.scope(ScopeNames.FULL).findAll(query)
236 } 209 }
237 210
238 static loadLocalByName (name: string) { 211 static loadLocalByName (preferredUsername: string) {
239 const query = { 212 const query = {
240 where: { 213 where: {
241 name, 214 preferredUsername,
242 serverId: null 215 serverId: null
243 } 216 }
244 } 217 }
@@ -246,10 +219,10 @@ export class ActorModel extends Model<ActorModel> {
246 return ActorModel.scope(ScopeNames.FULL).findOne(query) 219 return ActorModel.scope(ScopeNames.FULL).findOne(query)
247 } 220 }
248 221
249 static loadByNameAndHost (name: string, host: string) { 222 static loadByNameAndHost (preferredUsername: string, host: string) {
250 const query = { 223 const query = {
251 where: { 224 where: {
252 name 225 preferredUsername
253 }, 226 },
254 include: [ 227 include: [
255 { 228 {
@@ -286,17 +259,15 @@ export class ActorModel extends Model<ActorModel> {
286 } 259 }
287 } 260 }
288 261
289 let host = CONFIG.WEBSERVER.HOST
290 let score: number 262 let score: number
291 if (this.Server) { 263 if (this.Server) {
292 host = this.Server.host
293 score = this.Server.score 264 score = this.Server.score
294 } 265 }
295 266
296 return { 267 return {
297 id: this.id, 268 id: this.id,
298 uuid: this.uuid, 269 uuid: this.uuid,
299 host, 270 host: this.getHost(),
300 score, 271 score,
301 followingCount: this.followingCount, 272 followingCount: this.followingCount,
302 followersCount: this.followersCount, 273 followersCount: this.followersCount,
@@ -304,7 +275,7 @@ export class ActorModel extends Model<ActorModel> {
304 } 275 }
305 } 276 }
306 277
307 toActivityPubObject (preferredUsername: string, type: 'Account' | 'Application' | 'VideoChannel') { 278 toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') {
308 let activityPubType 279 let activityPubType
309 if (type === 'Account') { 280 if (type === 'Account') {
310 activityPubType = 'Person' as 'Person' 281 activityPubType = 'Person' as 'Person'
@@ -321,9 +292,9 @@ export class ActorModel extends Model<ActorModel> {
321 followers: this.getFollowersUrl(), 292 followers: this.getFollowersUrl(),
322 inbox: this.inboxUrl, 293 inbox: this.inboxUrl,
323 outbox: this.outboxUrl, 294 outbox: this.outboxUrl,
324 preferredUsername, 295 preferredUsername: this.preferredUsername,
325 url: this.url, 296 url: this.url,
326 name: this.name, 297 name,
327 endpoints: { 298 endpoints: {
328 sharedInbox: this.sharedInboxUrl 299 sharedInbox: this.sharedInboxUrl
329 }, 300 },
@@ -373,4 +344,12 @@ export class ActorModel extends Model<ActorModel> {
373 isOwned () { 344 isOwned () {
374 return this.serverId === null 345 return this.serverId === null
375 } 346 }
347
348 getWebfingerUrl () {
349 return 'acct:' + this.preferredUsername + '@' + this.getHost()
350 }
351
352 getHost () {
353 return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST
354 }
376} 355}