From 265ba139ebf56bbdc1c65f6ea4f367774c691fc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 3 Jan 2018 16:38:50 +0100 Subject: Send account activitypub update events --- server/models/account/account.ts | 23 +++++++++++++++++++++- server/models/activitypub/actor.ts | 2 +- server/models/video/video-share.ts | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index d3503aaa3..493068127 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -18,8 +18,9 @@ import { isUserUsernameValid } from '../../helpers/custom-validators/users' import { sendDeleteActor } from '../../lib/activitypub/send' import { ActorModel } from '../activitypub/actor' import { ApplicationModel } from '../application/application' +import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' -import { throwIfNotValid } from '../utils' +import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { UserModel } from './user' @@ -32,6 +33,10 @@ import { UserModel } from './user' { model: () => ServerModel, required: false + }, + { + model: () => AvatarModel, + required: false } ] } @@ -166,6 +171,22 @@ export class AccountModel extends Model { return AccountModel.findOne(query) } + static listForApi (start: number, count: number, sort: string) { + const query = { + offset: start, + limit: count, + order: [ getSort(sort) ] + } + + return AccountModel.findAndCountAll(query) + .then(({ rows, count }) => { + return { + data: rows, + total: count + } + }) + } + toFormattedJSON (): Account { const actor = this.Actor.toFormattedJSON() const account = { diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index ff5ab2e32..2ef7c77a2 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -372,6 +372,6 @@ export class ActorModel extends Model { getAvatarUrl () { if (!this.avatarId) return undefined - return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath + return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath() } } diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index c252fd646..56576f98c 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,7 +1,9 @@ import * as Sequelize from 'sequelize' import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' +import { AccountModel } from '../account/account' import { ActorModel } from '../activitypub/actor' import { VideoModel } from './video' +import { VideoChannelModel } from './video-channel' enum ScopeNames { FULL = 'FULL', @@ -99,4 +101,42 @@ export class VideoShareModel extends Model { return VideoShareModel.scope(ScopeNames.FULL).findAll(query) .then(res => res.map(r => r.Actor)) } + + static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { + const query = { + attributes: [], + include: [ + { + model: ActorModel, + required: true + }, + { + attributes: [], + model: VideoModel, + required: true, + include: [ + { + attributes: [], + model: VideoChannelModel.unscoped(), + required: true, + include: [ + { + attributes: [], + model: AccountModel.unscoped(), + required: true, + where: { + actorId: actorOwnerId + } + } + ] + } + ] + } + ], + transaction: t + } + + return VideoShareModel.scope(ScopeNames.FULL).findAll(query) + .then(res => res.map(r => r.Actor)) + } } -- cgit v1.2.3