From 63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Nov 2017 13:41:10 +0100 Subject: Correctly forward like/dislikes and undo --- server/models/account/account-interface.ts | 2 ++ server/models/account/account.ts | 17 ++++++++++++++- server/models/video/video.ts | 35 ++++++++++++------------------ 3 files changed, 32 insertions(+), 22 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts index 2e4b0382d..6fc98ba45 100644 --- a/server/models/account/account-interface.ts +++ b/server/models/account/account-interface.ts @@ -12,6 +12,7 @@ export namespace AccountMethods { export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird export type LoadLocalByName = (name: string) => Bluebird export type LoadByNameAndHost = (name: string, host: string) => Bluebird + export type ListByFollowersUrls = (followerUrls: string[], transaction?: Sequelize.Transaction) => Bluebird export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount @@ -29,6 +30,7 @@ export interface AccountClass { loadByUrl: AccountMethods.LoadByUrl loadLocalByName: AccountMethods.LoadLocalByName loadByNameAndHost: AccountMethods.LoadByNameAndHost + listByFollowersUrls: AccountMethods.ListByFollowersUrls } export interface AccountAttributes { diff --git a/server/models/account/account.ts b/server/models/account/account.ts index f2bd325f3..fff3ce087 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -26,6 +26,7 @@ let loadByUUID: AccountMethods.LoadByUUID let loadByUrl: AccountMethods.LoadByUrl let loadLocalByName: AccountMethods.LoadLocalByName let loadByNameAndHost: AccountMethods.LoadByNameAndHost +let listByFollowersUrls: AccountMethods.ListByFollowersUrls let isOwned: AccountMethods.IsOwned let toActivityPubObject: AccountMethods.ToActivityPubObject let toFormattedJSON: AccountMethods.ToFormattedJSON @@ -188,7 +189,8 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes loadByUUID, loadByUrl, loadLocalByName, - loadByNameAndHost + loadByNameAndHost, + listByFollowersUrls ] const instanceMethods = [ isOwned, @@ -427,3 +429,16 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) { return Account.findOne(query) } + +listByFollowersUrls = function (followersUrls: string[], transaction?: Sequelize.Transaction) { + const query: Sequelize.FindOptions = { + where: { + followersUrl: { + [Sequelize.Op.in]: followersUrls + } + }, + transaction + } + + return Account.findAll(query) +} diff --git a/server/models/video/video.ts b/server/models/video/video.ts index e5fd92549..82b95c489 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -6,27 +6,8 @@ import { join } from 'path' import * as Sequelize from 'sequelize' import { VideoPrivacy, VideoResolution } from '../../../shared' import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' -import { - createTorrentPromise, - generateImageFromVideoFile, - getVideoFileHeight, - isVideoCategoryValid, - isVideoDescriptionValid, - isVideoDurationValid, - isVideoLanguageValid, - isVideoLicenceValid, - isVideoNameValid, - isVideoNSFWValid, - isVideoPrivacyValid, - logger, - renamePromise, - statPromise, - transcode, - unlinkPromise, - writeFilePromise -} from '../../helpers' import { activityPubCollection } from '../../helpers/activitypub' -import { isVideoUrlValid } from '../../helpers/custom-validators/videos' +import { isVideoCategoryValid, isVideoLanguageValid, isVideoPrivacyValid, isVideoUrlValid } from '../../helpers/custom-validators/videos' import { API_VERSION, CONFIG, @@ -39,7 +20,7 @@ import { VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES -} from '../../initializers' +} from '../../initializers/constants' import { sendDeleteVideo } from '../../lib/index' import { addMethodsToModel, getSort } from '../utils' @@ -47,6 +28,10 @@ import { addMethodsToModel, getSort } from '../utils' import { TagInstance } from './tag-interface' import { VideoFileInstance, VideoFileModel } from './video-file-interface' import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' +import { isVideoNameValid, isVideoLicenceValid, isVideoNSFWValid, isVideoDescriptionValid, isVideoDurationValid } from '../../helpers/index' +import { logger } from '../../helpers/logger' +import { generateImageFromVideoFile, transcode, getVideoFileHeight } from '../../helpers/ffmpeg-utils' +import { createTorrentPromise, writeFilePromise, unlinkPromise, renamePromise, statPromise } from '../../helpers/core-utils' let Video: Sequelize.Model let getOriginalFile: VideoMethods.GetOriginalFile @@ -1013,6 +998,10 @@ loadAndPopulateAccountAndServerAndTags = function (id: number) { model: Video['sequelize'].models.AccountVideoRate, include: [ Video['sequelize'].models.Account ] }, + { + model: Video['sequelize'].models.VideoShare, + include: [ Video['sequelize'].models.Account ] + }, Video['sequelize'].models.Tag, Video['sequelize'].models.VideoFile ] @@ -1040,6 +1029,10 @@ loadByUUIDAndPopulateAccountAndServerAndTags = function (uuid: string) { model: Video['sequelize'].models.AccountVideoRate, include: [ Video['sequelize'].models.Account ] }, + { + model: Video['sequelize'].models.VideoShare, + include: [ Video['sequelize'].models.Account ] + }, Video['sequelize'].models.Tag, Video['sequelize'].models.VideoFile ] -- cgit v1.2.3