aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-23 17:58:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch)
tree2050443febcdb2a3eec68b7bbf9687e26dcb24dc /server/models/activitypub
parent240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff)
downloadPeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip
Add ability to search video channels
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts103
-rw-r--r--server/models/activitypub/actor.ts10
2 files changed, 104 insertions, 9 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index b2d7ace66..81fcf7001 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -26,7 +26,7 @@ import { ACTOR_FOLLOW_SCORE } from '../../initializers'
26import { FOLLOW_STATES } from '../../initializers/constants' 26import { FOLLOW_STATES } from '../../initializers/constants'
27import { ServerModel } from '../server/server' 27import { ServerModel } from '../server/server'
28import { getSort } from '../utils' 28import { getSort } from '../utils'
29import { ActorModel } from './actor' 29import { ActorModel, unusedActorAttributesForAPI } from './actor'
30import { VideoChannelModel } from '../video/video-channel' 30import { VideoChannelModel } from '../video/video-channel'
31import { IIncludeOptions } from '../../../node_modules/sequelize-typescript/lib/interfaces/IIncludeOptions' 31import { IIncludeOptions } from '../../../node_modules/sequelize-typescript/lib/interfaces/IIncludeOptions'
32import { AccountModel } from '../account/account' 32import { AccountModel } from '../account/account'
@@ -167,8 +167,11 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
167 return ActorFollowModel.findOne(query) 167 return ActorFollowModel.findOne(query)
168 } 168 }
169 169
170 static loadByActorAndTargetNameAndHost (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) { 170 static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
171 const actorFollowingPartInclude: IIncludeOptions = { 171 const actorFollowingPartInclude: IIncludeOptions = {
172 attributes: {
173 exclude: unusedActorAttributesForAPI
174 },
172 model: ActorModel, 175 model: ActorModel,
173 required: true, 176 required: true,
174 as: 'ActorFollowing', 177 as: 'ActorFollowing',
@@ -177,7 +180,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
177 }, 180 },
178 include: [ 181 include: [
179 { 182 {
180 model: VideoChannelModel, 183 model: VideoChannelModel.unscoped(),
181 required: false 184 required: false
182 } 185 }
183 ] 186 ]
@@ -200,17 +203,79 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
200 actorId 203 actorId
201 }, 204 },
202 include: [ 205 include: [
203 {
204 model: ActorModel,
205 required: true,
206 as: 'ActorFollower'
207 },
208 actorFollowingPartInclude 206 actorFollowingPartInclude
209 ], 207 ],
210 transaction: t 208 transaction: t
211 } 209 }
212 210
213 return ActorFollowModel.findOne(query) 211 return ActorFollowModel.findOne(query)
212 .then(result => {
213 if (result && result.ActorFollowing.VideoChannel) {
214 result.ActorFollowing.VideoChannel.Actor = result.ActorFollowing
215 }
216
217 return result
218 })
219 }
220
221 static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]) {
222 const whereTab = targets
223 .map(t => {
224 if (t.host) {
225 return {
226 [ Sequelize.Op.and ]: [
227 {
228 '$preferredUsername$': t.name
229 },
230 {
231 '$host$': t.host
232 }
233 ]
234 }
235 }
236
237 return {
238 [ Sequelize.Op.and ]: [
239 {
240 '$preferredUsername$': t.name
241 },
242 {
243 '$serverId$': null
244 }
245 ]
246 }
247 })
248
249 const query = {
250 attributes: [],
251 where: {
252 [ Sequelize.Op.and ]: [
253 {
254 [ Sequelize.Op.or ]: whereTab
255 },
256 {
257 actorId
258 }
259 ]
260 },
261 include: [
262 {
263 attributes: [ 'preferredUsername' ],
264 model: ActorModel.unscoped(),
265 required: true,
266 as: 'ActorFollowing',
267 include: [
268 {
269 attributes: [ 'host' ],
270 model: ServerModel.unscoped(),
271 required: false
272 }
273 ]
274 }
275 ]
276 }
277
278 return ActorFollowModel.findAll(query)
214 } 279 }
215 280
216 static listFollowingForApi (id: number, start: number, count: number, sort: string) { 281 static listFollowingForApi (id: number, start: number, count: number, sort: string) {
@@ -248,6 +313,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
248 313
249 static listSubscriptionsForApi (id: number, start: number, count: number, sort: string) { 314 static listSubscriptionsForApi (id: number, start: number, count: number, sort: string) {
250 const query = { 315 const query = {
316 attributes: [],
251 distinct: true, 317 distinct: true,
252 offset: start, 318 offset: start,
253 limit: count, 319 limit: count,
@@ -257,6 +323,9 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
257 }, 323 },
258 include: [ 324 include: [
259 { 325 {
326 attributes: {
327 exclude: unusedActorAttributesForAPI
328 },
260 model: ActorModel, 329 model: ActorModel,
261 as: 'ActorFollowing', 330 as: 'ActorFollowing',
262 required: true, 331 required: true,
@@ -266,8 +335,24 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
266 required: true, 335 required: true,
267 include: [ 336 include: [
268 { 337 {
269 model: AccountModel, 338 attributes: {
339 exclude: unusedActorAttributesForAPI
340 },
341 model: ActorModel,
270 required: true 342 required: true
343 },
344 {
345 model: AccountModel,
346 required: true,
347 include: [
348 {
349 attributes: {
350 exclude: unusedActorAttributesForAPI
351 },
352 model: ActorModel,
353 required: true
354 }
355 ]
271 } 356 }
272 ] 357 ]
273 } 358 }
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 2abf40713..ec0b4b2d9 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -42,6 +42,16 @@ enum ScopeNames {
42 FULL = 'FULL' 42 FULL = 'FULL'
43} 43}
44 44
45export const unusedActorAttributesForAPI = [
46 'publicKey',
47 'privateKey',
48 'inboxUrl',
49 'outboxUrl',
50 'sharedInboxUrl',
51 'followersUrl',
52 'followingUrl'
53]
54
45@DefaultScope({ 55@DefaultScope({
46 include: [ 56 include: [
47 { 57 {