diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account.ts | 2 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 56 |
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' | |||
29 | import { VideoModel } from './video' | 29 | import { VideoModel } from './video' |
30 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 30 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
31 | import { AvatarModel } from '../avatar/avatar' | 31 | import { AvatarModel } from '../avatar/avatar' |
32 | import { ServerModel } from '../server/server' | ||
32 | 33 | ||
33 | enum ScopeNames { | 34 | enum 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 { |