aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts25
-rw-r--r--server/models/activitypub/actor.ts20
2 files changed, 31 insertions, 14 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 51b09e09b..8ef770cd4 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -27,7 +27,13 @@ import { createSafeIn, getSort } from '../utils'
27import { ActorModel, unusedActorAttributesForAPI } from './actor' 27import { ActorModel, unusedActorAttributesForAPI } from './actor'
28import { VideoChannelModel } from '../video/video-channel' 28import { VideoChannelModel } from '../video/video-channel'
29import { AccountModel } from '../account/account' 29import { AccountModel } from '../account/account'
30import { IncludeOptions, Op, Transaction, QueryTypes } from 'sequelize' 30import { IncludeOptions, Op, QueryTypes, Transaction } from 'sequelize'
31import {
32 MActorFollowActorsDefault,
33 MActorFollowActorsDefaultSubscription,
34 MActorFollowFollowingHost,
35 MActorFollowSubscriptions
36} from '@server/typings/models'
31 37
32@Table({ 38@Table({
33 tableName: 'actorFollow', 39 tableName: 'actorFollow',
@@ -143,7 +149,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
143 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved) 149 if (numberOfActorFollowsRemoved) logger.info('Removed bad %d actor follows.', numberOfActorFollowsRemoved)
144 } 150 }
145 151
146 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction) { 152 static loadByActorAndTarget (actorId: number, targetActorId: number, t?: Transaction): Bluebird<MActorFollowActorsDefault> {
147 const query = { 153 const query = {
148 where: { 154 where: {
149 actorId, 155 actorId,
@@ -167,7 +173,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
167 return ActorFollowModel.findOne(query) 173 return ActorFollowModel.findOne(query)
168 } 174 }
169 175
170 static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Transaction) { 176 static loadByActorAndTargetNameAndHostForAPI (
177 actorId: number,
178 targetName: string,
179 targetHost: string,
180 t?: Transaction
181 ): Bluebird<MActorFollowActorsDefaultSubscription> {
171 const actorFollowingPartInclude: IncludeOptions = { 182 const actorFollowingPartInclude: IncludeOptions = {
172 model: ActorModel, 183 model: ActorModel,
173 required: true, 184 required: true,
@@ -220,7 +231,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
220 }) 231 })
221 } 232 }
222 233
223 static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]) { 234 static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Bluebird<MActorFollowFollowingHost[]> {
224 const whereTab = targets 235 const whereTab = targets
225 .map(t => { 236 .map(t => {
226 if (t.host) { 237 if (t.host) {
@@ -314,7 +325,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
314 ] 325 ]
315 } 326 }
316 327
317 return ActorFollowModel.findAndCountAll(query) 328 return ActorFollowModel.findAndCountAll<MActorFollowActorsDefault>(query)
318 .then(({ rows, count }) => { 329 .then(({ rows, count }) => {
319 return { 330 return {
320 data: rows, 331 data: rows,
@@ -357,7 +368,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
357 ] 368 ]
358 } 369 }
359 370
360 return ActorFollowModel.findAndCountAll(query) 371 return ActorFollowModel.findAndCountAll<MActorFollowActorsDefault>(query)
361 .then(({ rows, count }) => { 372 .then(({ rows, count }) => {
362 return { 373 return {
363 data: rows, 374 data: rows,
@@ -414,7 +425,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
414 ] 425 ]
415 } 426 }
416 427
417 return ActorFollowModel.findAndCountAll(query) 428 return ActorFollowModel.findAndCountAll<MActorFollowSubscriptions>(query)
418 .then(({ rows, count }) => { 429 .then(({ rows, count }) => {
419 return { 430 return {
420 data: rows.map(r => r.ActorFollowing.VideoChannel), 431 data: rows.map(r => r.ActorFollowing.VideoChannel),
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 9cc53f78a..2312127b4 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -36,6 +36,8 @@ import { isOutdated, throwIfNotValid } from '../utils'
36import { VideoChannelModel } from '../video/video-channel' 36import { VideoChannelModel } from '../video/video-channel'
37import { ActorFollowModel } from './actor-follow' 37import { ActorFollowModel } from './actor-follow'
38import { VideoModel } from '../video/video' 38import { VideoModel } from '../video/video'
39import { MActor, MActorAccountChannelId, MActorFull } from '../../typings/models'
40import * as Bluebird from 'bluebird'
39 41
40enum ScopeNames { 42enum ScopeNames {
41 FULL = 'FULL' 43 FULL = 'FULL'
@@ -252,11 +254,15 @@ export class ActorModel extends Model<ActorModel> {
252 }) 254 })
253 VideoChannel: VideoChannelModel 255 VideoChannel: VideoChannelModel
254 256
255 static load (id: number) { 257 static load (id: number): Bluebird<MActor> {
256 return ActorModel.unscoped().findByPk(id) 258 return ActorModel.unscoped().findByPk(id)
257 } 259 }
258 260
259 static loadAccountActorByVideoId (videoId: number, transaction: Sequelize.Transaction) { 261 static loadFull (id: number): Bluebird<MActorFull> {
262 return ActorModel.scope(ScopeNames.FULL).findByPk(id)
263 }
264
265 static loadFromAccountByVideoId (videoId: number, transaction: Sequelize.Transaction): Bluebird<MActor> {
260 const query = { 266 const query = {
261 include: [ 267 include: [
262 { 268 {
@@ -300,7 +306,7 @@ export class ActorModel extends Model<ActorModel> {
300 .then(a => !!a) 306 .then(a => !!a)
301 } 307 }
302 308
303 static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) { 309 static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction): Bluebird<MActorFull[]> {
304 const query = { 310 const query = {
305 where: { 311 where: {
306 followersUrl: { 312 followersUrl: {
@@ -313,7 +319,7 @@ export class ActorModel extends Model<ActorModel> {
313 return ActorModel.scope(ScopeNames.FULL).findAll(query) 319 return ActorModel.scope(ScopeNames.FULL).findAll(query)
314 } 320 }
315 321
316 static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction) { 322 static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction): Bluebird<MActorFull> {
317 const query = { 323 const query = {
318 where: { 324 where: {
319 preferredUsername, 325 preferredUsername,
@@ -325,7 +331,7 @@ export class ActorModel extends Model<ActorModel> {
325 return ActorModel.scope(ScopeNames.FULL).findOne(query) 331 return ActorModel.scope(ScopeNames.FULL).findOne(query)
326 } 332 }
327 333
328 static loadByNameAndHost (preferredUsername: string, host: string) { 334 static loadByNameAndHost (preferredUsername: string, host: string): Bluebird<MActorFull> {
329 const query = { 335 const query = {
330 where: { 336 where: {
331 preferredUsername 337 preferredUsername
@@ -344,7 +350,7 @@ export class ActorModel extends Model<ActorModel> {
344 return ActorModel.scope(ScopeNames.FULL).findOne(query) 350 return ActorModel.scope(ScopeNames.FULL).findOne(query)
345 } 351 }
346 352
347 static loadByUrl (url: string, transaction?: Sequelize.Transaction) { 353 static loadByUrl (url: string, transaction?: Sequelize.Transaction): Bluebird<MActorAccountChannelId> {
348 const query = { 354 const query = {
349 where: { 355 where: {
350 url 356 url
@@ -367,7 +373,7 @@ export class ActorModel extends Model<ActorModel> {
367 return ActorModel.unscoped().findOne(query) 373 return ActorModel.unscoped().findOne(query)
368 } 374 }
369 375
370 static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction) { 376 static loadByUrlAndPopulateAccountAndChannel (url: string, transaction?: Sequelize.Transaction): Bluebird<MActorFull> {
371 const query = { 377 const query = {
372 where: { 378 where: {
373 url 379 url