From 2ccaeeb341ffe8c2609039bf4c6d8835b4650316 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 10 Jan 2018 17:18:12 +0100 Subject: Fetch remote AP objects --- server/models/activitypub/actor.ts | 3 +++ server/models/video/video-comment.ts | 15 +++++++++------ server/models/video/video.ts | 12 ++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'server/models') 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 @@ -62,6 +62,9 @@ enum ScopeNames { @Table({ tableName: 'actor', indexes: [ + { + fields: [ 'url' ] + }, { fields: [ 'preferredUsername', 'serverId' ], unique: true 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 { .findOne(query) } - static loadByUrl (url: string, t?: Sequelize.Transaction) { + static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { where: { url @@ -217,10 +217,10 @@ export class VideoCommentModel extends Model { if (t !== undefined) query.transaction = t - return VideoCommentModel.findOne(query) + return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) } - static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { + static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { where: { url @@ -229,7 +229,7 @@ export class VideoCommentModel extends Model { if (t !== undefined) query.transaction = t - return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) + return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_VIDEO ]).findOne(query) } static listThreadsForApi (videoId: number, start: number, count: number, sort: string) { @@ -271,9 +271,9 @@ export class VideoCommentModel extends Model { }) } - static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction) { + static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') { const query = { - order: [ [ 'createdAt', 'ASC' ] ], + order: [ [ 'createdAt', order ] ], where: { [ Sequelize.Op.or ]: [ { id: comment.getThreadId() }, @@ -281,6 +281,9 @@ export class VideoCommentModel extends Model { ], id: { [ Sequelize.Op.ne ]: comment.id + }, + createdAt: { + [ Sequelize.Op.lt ]: comment.createdAt } }, 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 { }, { fields: [ 'id', 'privacy' ] + }, + { + fields: [ 'url'], + unique: true } ] }) @@ -535,7 +539,7 @@ export class VideoModel extends Model { return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query) } - static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) { + static loadByUUIDOrURLAndPopulateAccount (uuid: string, url: string, t?: Sequelize.Transaction) { const query: IFindOptions = { where: { [Sequelize.Op.or]: [ @@ -547,7 +551,7 @@ export class VideoModel extends Model { if (t !== undefined) query.transaction = t - return VideoModel.scope(ScopeNames.WITH_FILES).findOne(query) + return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query) } static loadAndPopulateAccountAndServerAndTags (id: number) { @@ -983,6 +987,10 @@ export class VideoModel extends Model { { type: 'Group', id: this.VideoChannel.Actor.url + }, + { + type: 'Person', + id: this.VideoChannel.Account.Actor.url } ] } -- cgit v1.2.3