aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-17 15:45:42 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit8a19bee1a1ee39f973bb37429e4f73c3f2873cdb (patch)
tree33c93ef19451d7e46d4be74ce0681359d2dcc70e /server/models
parent965c4b22d0e4d2f853501e844e6ebbb861bd389d (diff)
downloadPeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.gz
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.zst
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.zip
Add ability to set a name to a channel
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account.ts2
-rw-r--r--server/models/activitypub/actor.ts5
-rw-r--r--server/models/video/video-channel.ts56
3 files changed, 46 insertions, 17 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 66f5dcf2e..07539a04e 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -194,7 +194,7 @@ export class AccountModel extends Model<AccountModel> {
194 return AccountModel.findOne(query) 194 return AccountModel.findOne(query)
195 } 195 }
196 196
197 static loadLocalByNameAndHost (name: string, host: string) { 197 static loadByNameAndHost (name: string, host: string) {
198 const query = { 198 const query = {
199 include: [ 199 include: [
200 { 200 {
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 35d7c35e8..2abf40713 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -260,12 +260,13 @@ export class ActorModel extends Model<ActorModel> {
260 return ActorModel.scope(ScopeNames.FULL).findAll(query) 260 return ActorModel.scope(ScopeNames.FULL).findAll(query)
261 } 261 }
262 262
263 static loadLocalByName (preferredUsername: string) { 263 static loadLocalByName (preferredUsername: string, transaction?: Sequelize.Transaction) {
264 const query = { 264 const query = {
265 where: { 265 where: {
266 preferredUsername, 266 preferredUsername,
267 serverId: null 267 serverId: null
268 } 268 },
269 transaction
269 } 270 }
270 271
271 return ActorModel.scope(ScopeNames.FULL).findOne(query) 272 return ActorModel.scope(ScopeNames.FULL).findOne(query)
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 0273fab13..9f80e0b8d 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -29,6 +29,7 @@ import { getSort, throwIfNotValid } from '../utils'
29import { VideoModel } from './video' 29import { VideoModel } from './video'
30import { CONSTRAINTS_FIELDS } from '../../initializers' 30import { CONSTRAINTS_FIELDS } from '../../initializers'
31import { AvatarModel } from '../avatar/avatar' 31import { AvatarModel } from '../avatar/avatar'
32import { ServerModel } from '../server/server'
32 33
33enum ScopeNames { 34enum ScopeNames {
34 WITH_ACCOUNT = 'WITH_ACCOUNT', 35 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -206,7 +207,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
206 } 207 }
207 208
208 static loadByIdAndAccount (id: number, accountId: number) { 209 static loadByIdAndAccount (id: number, accountId: number) {
209 const options = { 210 const query = {
210 where: { 211 where: {
211 id, 212 id,
212 accountId 213 accountId
@@ -215,7 +216,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
215 216
216 return VideoChannelModel 217 return VideoChannelModel
217 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 218 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
218 .findOne(options) 219 .findOne(query)
219 } 220 }
220 221
221 static loadAndPopulateAccount (id: number) { 222 static loadAndPopulateAccount (id: number) {
@@ -225,7 +226,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
225 } 226 }
226 227
227 static loadByUUIDAndPopulateAccount (uuid: string) { 228 static loadByUUIDAndPopulateAccount (uuid: string) {
228 const options = { 229 const query = {
229 include: [ 230 include: [
230 { 231 {
231 model: ActorModel, 232 model: ActorModel,
@@ -239,36 +240,63 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
239 240
240 return VideoChannelModel 241 return VideoChannelModel
241 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 242 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
242 .findOne(options) 243 .findOne(query)
243 } 244 }
244 245
245 static loadAndPopulateAccountAndVideos (id: number) { 246 static loadLocalByNameAndPopulateAccount (name: string) {
246 const options = { 247 const query = {
247 include: [ 248 include: [
248 VideoModel 249 {
250 model: ActorModel,
251 required: true,
252 where: {
253 preferredUsername: name,
254 serverId: null
255 }
256 }
249 ] 257 ]
250 } 258 }
251 259
252 return VideoChannelModel 260 return VideoChannelModel
253 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ]) 261 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
254 .findById(id, options) 262 .findOne(query)
255 } 263 }
256 264
257 static loadLocalByName (name: string) { 265 static loadByNameAndHostAndPopulateAccount (name: string, host: string) {
258 const query = { 266 const query = {
259 include: [ 267 include: [
260 { 268 {
261 model: ActorModel, 269 model: ActorModel,
262 required: true, 270 required: true,
263 where: { 271 where: {
264 preferredUsername: name, 272 preferredUsername: name
265 serverId: null 273 },
266 } 274 include: [
275 {
276 model: ServerModel,
277 required: true,
278 where: { host }
279 }
280 ]
267 } 281 }
268 ] 282 ]
269 } 283 }
270 284
271 return VideoChannelModel.findOne(query) 285 return VideoChannelModel
286 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
287 .findOne(query)
288 }
289
290 static loadAndPopulateAccountAndVideos (id: number) {
291 const options = {
292 include: [
293 VideoModel
294 ]
295 }
296
297 return VideoChannelModel
298 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ])
299 .findById(id, options)
272 } 300 }
273 301
274 toFormattedJSON (): VideoChannel { 302 toFormattedJSON (): VideoChannel {