</div>
</div>
- <div class="no-results" i18n *ngIf="pagination.totalItems === 0">No results.</div>
+ <div class="no-results" i18n *ngIf="hasDoneFirstQuery && videos.length === 0">No results.</div>
<div
myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [autoInit]="true" [dataObservable]="onDataSubject.asObservable()"
class="videos"
// Needed to build the AP object
if (!video.VideoCaptions) {
- video.VideoCaptions = await video.$get('VideoCaptions', { transaction: t }) as VideoCaptionModel[]
+ video.VideoCaptions = await video.$get('VideoCaptions', { transaction: t })
}
const videoObject = video.toActivityPubObject()
video.VideoCaptions = await video.$get('VideoCaptions', {
attributes: [ 'language' ],
transaction
- }) as VideoCaptionModel[]
+ })
}
if (isNewVideo) {
await createTorrentAndSetInfoHash(videoStreamingPlaylist, newVideoFile)
await newVideoFile.save()
- videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles') as VideoFileModel[]
+ videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles')
video.setHLSPlaylist(videoStreamingPlaylist)
@BeforeDestroy
static async sendDeleteIfOwned (instance: AccountModel, options) {
if (!instance.Actor) {
- instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
}
await ActorFollowModel.removeFollowsOf(instance.Actor.id, options.transaction)
MActorFollowSubscriptions
} from '@server/typings/models'
import { ActivityPubActorType } from '@shared/models'
+import { afterCommitIfTransaction } from '@server/helpers/database-utils'
@Table({
tableName: 'actorFollow',
@AfterCreate
@AfterUpdate
- static incrementFollowerAndFollowingCount (instance: ActorFollowModel) {
+ static incrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) {
if (instance.state !== 'accepted') return undefined
return Promise.all([
- ActorModel.incrementFollows(instance.actorId, 'followingCount', 1),
- ActorModel.incrementFollows(instance.targetActorId, 'followersCount', 1)
+ ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction),
+ ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction)
])
}
@AfterDestroy
- static decrementFollowerAndFollowingCount (instance: ActorFollowModel) {
+ static decrementFollowerAndFollowingCount (instance: ActorFollowModel, options: any) {
return Promise.all([
- ActorModel.incrementFollows(instance.actorId, 'followingCount',-1),
- ActorModel.incrementFollows(instance.targetActorId, 'followersCount', -1)
+ ActorModel.rebuildFollowsCount(instance.actorId, 'following', options.transaction),
+ ActorModel.rebuildFollowsCount(instance.targetActorId, 'followers', options.transaction)
])
}
MActorWithInboxes
} from '../../typings/models'
import * as Bluebird from 'bluebird'
-import { Op, Transaction } from 'sequelize'
+import { Op, Transaction, literal } from 'sequelize'
enum ScopeNames {
FULL = 'FULL'
return ActorModel.scope(ScopeNames.FULL).findOne(query)
}
- static incrementFollows (id: number, column: 'followersCount' | 'followingCount', by: number) {
- return ActorModel.increment(column, {
- by,
- where: {
- id
- }
- })
+ static rebuildFollowsCount (ofId: number, type: 'followers' | 'following', transaction?: Transaction) {
+ const sanitizedOfId = parseInt(ofId + '', 10)
+ const where = { id: sanitizedOfId }
+
+ let columnToUpdate: string
+ let columnOfCount: string
+
+ if (type === 'followers') {
+ columnToUpdate = 'followersCount'
+ columnOfCount = 'targetActorId'
+ } else {
+ columnToUpdate = 'followingCount'
+ columnOfCount = 'actorId'
+ }
+
+ return ActorModel.update({
+ [columnToUpdate]: literal(`(SELECT COUNT(*) FROM "actorFollow" WHERE "${columnOfCount}" = ${sanitizedOfId})`)
+ }, { where, transaction })
}
getSharedInbox (this: MActorWithInboxes) {
@BeforeDestroy
static async removeFiles (instance: VideoCaptionModel) {
if (!instance.Video) {
- instance.Video = await instance.$get('Video') as VideoModel
+ instance.Video = await instance.$get('Video')
}
if (instance.isOwned()) {
@BeforeDestroy
static async sendDeleteIfOwned (instance: VideoChannelModel, options) {
if (!instance.Actor) {
- instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
}
if (instance.Actor.isOwned()) {
if (instance.isOwned()) {
if (!Array.isArray(instance.VideoFiles)) {
- instance.VideoFiles = await instance.$get('VideoFiles') as VideoFileModel[]
+ instance.VideoFiles = await instance.$get('VideoFiles')
}
// Remove physical files and torrents
const mastodonObject = cloneDeep(require('./json/mastodon/bad-http-signature.json'))
req.body = mastodonObject.body
req.headers = mastodonObject.headers
- req.headers.signature = 'Signature ' + req.headers.signature
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
const publicKey = require('./json/mastodon/public-key.json').publicKey
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
req.body = mastodonObject.body
req.headers = mastodonObject.headers
- req.headers.signature = 'Signature ' + req.headers.signature
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
const publicKey = require('./json/mastodon/bad-public-key.json').publicKey
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
req.body = mastodonObject.body
req.headers = mastodonObject.headers
- req.headers.signature = 'Signature ' + req.headers.signature
let errored = false
try {
expect(errored).to.be.true
})
- it('Should fail without scheme', async function () {
+ it('Should with a scheme', async function () {
const req = buildRequestStub()
req.method = 'POST'
req.url = '/accounts/ronan/inbox'
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
req.body = mastodonObject.body
req.headers = mastodonObject.headers
+ req.headers = 'Signature ' + mastodonObject.headers
let errored = false
try {
const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json'))
req.body = mastodonObject.body
req.headers = mastodonObject.headers
- req.headers.signature = 'Signature ' + req.headers.signature
const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
const publicKey = require('./json/mastodon/public-key.json').publicKey
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1)
await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0)
- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 2)
+ await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1)
await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0)
})