diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-03 16:38:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-03 16:38:50 +0100 |
commit | 265ba139ebf56bbdc1c65f6ea4f367774c691fc0 (patch) | |
tree | c7c52d1ae48a35b8f9aa06a9fa2335a6ba502fd1 /server/models | |
parent | 9bce811268cd74b402176ae9fcd8b77ac887576e (diff) | |
download | PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.tar.gz PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.tar.zst PeerTube-265ba139ebf56bbdc1c65f6ea4f367774c691fc0.zip |
Send account activitypub update events
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account.ts | 23 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 40 |
3 files changed, 63 insertions, 2 deletions
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' | |||
18 | import { sendDeleteActor } from '../../lib/activitypub/send' | 18 | import { sendDeleteActor } from '../../lib/activitypub/send' |
19 | import { ActorModel } from '../activitypub/actor' | 19 | import { ActorModel } from '../activitypub/actor' |
20 | import { ApplicationModel } from '../application/application' | 20 | import { ApplicationModel } from '../application/application' |
21 | import { AvatarModel } from '../avatar/avatar' | ||
21 | import { ServerModel } from '../server/server' | 22 | import { ServerModel } from '../server/server' |
22 | import { throwIfNotValid } from '../utils' | 23 | import { getSort, throwIfNotValid } from '../utils' |
23 | import { VideoChannelModel } from '../video/video-channel' | 24 | import { VideoChannelModel } from '../video/video-channel' |
24 | import { UserModel } from './user' | 25 | import { UserModel } from './user' |
25 | 26 | ||
@@ -32,6 +33,10 @@ import { UserModel } from './user' | |||
32 | { | 33 | { |
33 | model: () => ServerModel, | 34 | model: () => ServerModel, |
34 | required: false | 35 | required: false |
36 | }, | ||
37 | { | ||
38 | model: () => AvatarModel, | ||
39 | required: false | ||
35 | } | 40 | } |
36 | ] | 41 | ] |
37 | } | 42 | } |
@@ -166,6 +171,22 @@ export class AccountModel extends Model<AccountModel> { | |||
166 | return AccountModel.findOne(query) | 171 | return AccountModel.findOne(query) |
167 | } | 172 | } |
168 | 173 | ||
174 | static listForApi (start: number, count: number, sort: string) { | ||
175 | const query = { | ||
176 | offset: start, | ||
177 | limit: count, | ||
178 | order: [ getSort(sort) ] | ||
179 | } | ||
180 | |||
181 | return AccountModel.findAndCountAll(query) | ||
182 | .then(({ rows, count }) => { | ||
183 | return { | ||
184 | data: rows, | ||
185 | total: count | ||
186 | } | ||
187 | }) | ||
188 | } | ||
189 | |||
169 | toFormattedJSON (): Account { | 190 | toFormattedJSON (): Account { |
170 | const actor = this.Actor.toFormattedJSON() | 191 | const actor = this.Actor.toFormattedJSON() |
171 | const account = { | 192 | 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<ActorModel> { | |||
372 | getAvatarUrl () { | 372 | getAvatarUrl () { |
373 | if (!this.avatarId) return undefined | 373 | if (!this.avatarId) return undefined |
374 | 374 | ||
375 | return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath | 375 | return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath() |
376 | } | 376 | } |
377 | } | 377 | } |
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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { AccountModel } from '../account/account' | ||
3 | import { ActorModel } from '../activitypub/actor' | 4 | import { ActorModel } from '../activitypub/actor' |
4 | import { VideoModel } from './video' | 5 | import { VideoModel } from './video' |
6 | import { VideoChannelModel } from './video-channel' | ||
5 | 7 | ||
6 | enum ScopeNames { | 8 | enum ScopeNames { |
7 | FULL = 'FULL', | 9 | FULL = 'FULL', |
@@ -99,4 +101,42 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
99 | return VideoShareModel.scope(ScopeNames.FULL).findAll(query) | 101 | return VideoShareModel.scope(ScopeNames.FULL).findAll(query) |
100 | .then(res => res.map(r => r.Actor)) | 102 | .then(res => res.map(r => r.Actor)) |
101 | } | 103 | } |
104 | |||
105 | static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { | ||
106 | const query = { | ||
107 | attributes: [], | ||
108 | include: [ | ||
109 | { | ||
110 | model: ActorModel, | ||
111 | required: true | ||
112 | }, | ||
113 | { | ||
114 | attributes: [], | ||
115 | model: VideoModel, | ||
116 | required: true, | ||
117 | include: [ | ||
118 | { | ||
119 | attributes: [], | ||
120 | model: VideoChannelModel.unscoped(), | ||
121 | required: true, | ||
122 | include: [ | ||
123 | { | ||
124 | attributes: [], | ||
125 | model: AccountModel.unscoped(), | ||
126 | required: true, | ||
127 | where: { | ||
128 | actorId: actorOwnerId | ||
129 | } | ||
130 | } | ||
131 | ] | ||
132 | } | ||
133 | ] | ||
134 | } | ||
135 | ], | ||
136 | transaction: t | ||
137 | } | ||
138 | |||
139 | return VideoShareModel.scope(ScopeNames.FULL).findAll(query) | ||
140 | .then(res => res.map(r => r.Actor)) | ||
141 | } | ||
102 | } | 142 | } |