aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 15:25:20 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch)
treeac197f3ed0768529456225ad76c912f22bc55e29 /server/models/activitypub
parent4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff)
downloadPeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts93
1 files changed, 76 insertions, 17 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index adec5e92b..90a8ac43c 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -2,8 +2,21 @@ import * as Bluebird from 'bluebird'
2import { values } from 'lodash' 2import { values } from 'lodash'
3import * as Sequelize from 'sequelize' 3import * as Sequelize from 'sequelize'
4import { 4import {
5 AfterCreate, AfterDestroy, AfterUpdate, AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IsInt, Max, Model, 5 AfterCreate,
6 Table, UpdatedAt 6 AfterDestroy,
7 AfterUpdate,
8 AllowNull,
9 BelongsTo,
10 Column,
11 CreatedAt,
12 DataType,
13 Default,
14 ForeignKey,
15 IsInt,
16 Max,
17 Model,
18 Table,
19 UpdatedAt
7} from 'sequelize-typescript' 20} from 'sequelize-typescript'
8import { FollowState } from '../../../shared/models/actors' 21import { FollowState } from '../../../shared/models/actors'
9import { AccountFollow } from '../../../shared/models/actors/follow.model' 22import { AccountFollow } from '../../../shared/models/actors/follow.model'
@@ -14,6 +27,7 @@ import { FOLLOW_STATES } from '../../initializers/constants'
14import { ServerModel } from '../server/server' 27import { ServerModel } from '../server/server'
15import { getSort } from '../utils' 28import { getSort } from '../utils'
16import { ActorModel } from './actor' 29import { ActorModel } from './actor'
30import { VideoChannelModel } from '../video/video-channel'
17 31
18@Table({ 32@Table({
19 tableName: 'actorFollow', 33 tableName: 'actorFollow',
@@ -151,7 +165,32 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
151 return ActorFollowModel.findOne(query) 165 return ActorFollowModel.findOne(query)
152 } 166 }
153 167
154 static loadByActorAndTargetHost (actorId: number, targetHost: string, t?: Sequelize.Transaction) { 168 static loadByActorAndTargetNameAndHost (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
169 const actorFollowingPartInclude = {
170 model: ActorModel,
171 required: true,
172 as: 'ActorFollowing',
173 where: {
174 preferredUsername: targetName
175 }
176 }
177
178 if (targetHost === null) {
179 actorFollowingPartInclude.where['serverId'] = null
180 } else {
181 Object.assign(actorFollowingPartInclude, {
182 include: [
183 {
184 model: ServerModel,
185 required: true,
186 where: {
187 host: targetHost
188 }
189 }
190 ]
191 })
192 }
193
155 const query = { 194 const query = {
156 where: { 195 where: {
157 actorId 196 actorId
@@ -162,20 +201,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
162 required: true, 201 required: true,
163 as: 'ActorFollower' 202 as: 'ActorFollower'
164 }, 203 },
165 { 204 actorFollowingPartInclude
166 model: ActorModel,
167 required: true,
168 as: 'ActorFollowing',
169 include: [
170 {
171 model: ServerModel,
172 required: true,
173 where: {
174 host: targetHost
175 }
176 }
177 ]
178 }
179 ], 205 ],
180 transaction: t 206 transaction: t
181 } 207 }
@@ -216,6 +242,39 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
216 }) 242 })
217 } 243 }
218 244
245 static listSubscriptionsForApi (id: number, start: number, count: number, sort: string) {
246 const query = {
247 distinct: true,
248 offset: start,
249 limit: count,
250 order: getSort(sort),
251 where: {
252 actorId: id
253 },
254 include: [
255 {
256 model: ActorModel,
257 as: 'ActorFollowing',
258 required: true,
259 include: [
260 {
261 model: VideoChannelModel,
262 required: true
263 }
264 ]
265 }
266 ]
267 }
268
269 return ActorFollowModel.findAndCountAll(query)
270 .then(({ rows, count }) => {
271 return {
272 data: rows.map(r => r.ActorFollowing.VideoChannel),
273 total: count
274 }
275 })
276 }
277
219 static listFollowersForApi (id: number, start: number, count: number, sort: string) { 278 static listFollowersForApi (id: number, start: number, count: number, sort: string) {
220 const query = { 279 const query = {
221 distinct: true, 280 distinct: true,