aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-10 17:18:12 +0100
committerChocobozzz <me@florianbigard.com>2018-01-10 17:19:14 +0100
commit2ccaeeb341ffe8c2609039bf4c6d8835b4650316 (patch)
treea6bf6e05e7f02bc315e872d67a0b61ad6ad3d777 /server/models
parent759f8a29e95932023564ca98dcbc90d1acb92da0 (diff)
downloadPeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.tar.gz
PeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.tar.zst
PeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.zip
Fetch remote AP objects
Diffstat (limited to 'server/models')
-rw-r--r--server/models/activitypub/actor.ts3
-rw-r--r--server/models/video/video-comment.ts15
-rw-r--r--server/models/video/video.ts12
3 files changed, 22 insertions, 8 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 707f140af..b88e06b41 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -63,6 +63,9 @@ enum ScopeNames {
63 tableName: 'actor', 63 tableName: 'actor',
64 indexes: [ 64 indexes: [
65 { 65 {
66 fields: [ 'url' ]
67 },
68 {
66 fields: [ 'preferredUsername', 'serverId' ], 69 fields: [ 'preferredUsername', 'serverId' ],
67 unique: true 70 unique: true
68 } 71 }
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index dbb2fe429..fffa4bb57 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -208,7 +208,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
208 .findOne(query) 208 .findOne(query)
209 } 209 }
210 210
211 static loadByUrl (url: string, t?: Sequelize.Transaction) { 211 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
212 const query: IFindOptions<VideoCommentModel> = { 212 const query: IFindOptions<VideoCommentModel> = {
213 where: { 213 where: {
214 url 214 url
@@ -217,10 +217,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
217 217
218 if (t !== undefined) query.transaction = t 218 if (t !== undefined) query.transaction = t
219 219
220 return VideoCommentModel.findOne(query) 220 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query)
221 } 221 }
222 222
223 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { 223 static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Sequelize.Transaction) {
224 const query: IFindOptions<VideoCommentModel> = { 224 const query: IFindOptions<VideoCommentModel> = {
225 where: { 225 where: {
226 url 226 url
@@ -229,7 +229,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
229 229
230 if (t !== undefined) query.transaction = t 230 if (t !== undefined) query.transaction = t
231 231
232 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) 232 return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_VIDEO ]).findOne(query)
233 } 233 }
234 234
235 static listThreadsForApi (videoId: number, start: number, count: number, sort: string) { 235 static listThreadsForApi (videoId: number, start: number, count: number, sort: string) {
@@ -271,9 +271,9 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
271 }) 271 })
272 } 272 }
273 273
274 static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction) { 274 static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') {
275 const query = { 275 const query = {
276 order: [ [ 'createdAt', 'ASC' ] ], 276 order: [ [ 'createdAt', order ] ],
277 where: { 277 where: {
278 [ Sequelize.Op.or ]: [ 278 [ Sequelize.Op.or ]: [
279 { id: comment.getThreadId() }, 279 { id: comment.getThreadId() },
@@ -281,6 +281,9 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
281 ], 281 ],
282 id: { 282 id: {
283 [ Sequelize.Op.ne ]: comment.id 283 [ Sequelize.Op.ne ]: comment.id
284 },
285 createdAt: {
286 [ Sequelize.Op.lt ]: comment.createdAt
284 } 287 }
285 }, 288 },
286 transaction: t 289 transaction: t
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 918892938..6b825bf93 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -178,6 +178,10 @@ enum ScopeNames {
178 }, 178 },
179 { 179 {
180 fields: [ 'id', 'privacy' ] 180 fields: [ 'id', 'privacy' ]
181 },
182 {
183 fields: [ 'url'],
184 unique: true
181 } 185 }
182 ] 186 ]
183}) 187})
@@ -535,7 +539,7 @@ export class VideoModel extends Model<VideoModel> {
535 return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query) 539 return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query)
536 } 540 }
537 541
538 static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) { 542 static loadByUUIDOrURLAndPopulateAccount (uuid: string, url: string, t?: Sequelize.Transaction) {
539 const query: IFindOptions<VideoModel> = { 543 const query: IFindOptions<VideoModel> = {
540 where: { 544 where: {
541 [Sequelize.Op.or]: [ 545 [Sequelize.Op.or]: [
@@ -547,7 +551,7 @@ export class VideoModel extends Model<VideoModel> {
547 551
548 if (t !== undefined) query.transaction = t 552 if (t !== undefined) query.transaction = t
549 553
550 return VideoModel.scope(ScopeNames.WITH_FILES).findOne(query) 554 return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query)
551 } 555 }
552 556
553 static loadAndPopulateAccountAndServerAndTags (id: number) { 557 static loadAndPopulateAccountAndServerAndTags (id: number) {
@@ -983,6 +987,10 @@ export class VideoModel extends Model<VideoModel> {
983 { 987 {
984 type: 'Group', 988 type: 'Group',
985 id: this.VideoChannel.Actor.url 989 id: this.VideoChannel.Actor.url
990 },
991 {
992 type: 'Person',
993 id: this.VideoChannel.Account.Actor.url
986 } 994 }
987 ] 995 ]
988 } 996 }