Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add channelUpdatedAt list subscriptions sort

Chocobozzze002b6fcd6bf
diff --git a/packages/tests/src/api/users/user-subscriptions.ts b/packages/tests/src/api/users/user-subscriptions.ts
index eb4ea9539b..a0c61a6127 100644
--- a/packages/tests/src/api/users/user-subscriptions.ts
+++ b/packages/tests/src/api/users/user-subscriptions.ts
@@ -53,7 +53,8 @@ describe('Test users subscriptions', function () {
command = servers[0].subscriptions
})
- describe('Destinction between server videos and user videos', function () {
+ describe('Distinction between server videos and user videos', function () {
+
it('Should display videos of server 2 on server 1', async function () {
const { total } = await servers[0].videos.list()
@@ -161,6 +162,15 @@ describe('Test users subscriptions', function () {
expect(body.data).to.have.lengthOf(0)
}
})
+
+ it('Should sort subscriptions by channelUpdatedAt', async function () {
+ const body = await command.list({ token: users[0].accessToken, sort: '-channelUpdatedAt' })
+ expect(body.total).to.equal(2)
+
+ const subscriptions = body.data
+ expect(subscriptions[0].name).to.equal('user3_channel')
+ expect(subscriptions[1].name).to.equal('root_channel')
+ })
})
describe('Subscription videos', function () {
diff --git a/server/core/controllers/api/users/my-subscriptions.ts b/server/core/controllers/api/users/my-subscriptions.ts
index 3c0e48121a..75690dff2a 100644
--- a/server/core/controllers/api/users/my-subscriptions.ts
+++ b/server/core/controllers/api/users/my-subscriptions.ts
@@ -57,7 +57,7 @@ mySubscriptionsRouter.get('/me/subscriptions',
setDefaultSort,
setDefaultPagination,
userSubscriptionListValidator,
- asyncMiddleware(getUserSubscriptions)
+ asyncMiddleware(listUserSubscriptions)
)
mySubscriptionsRouter.post('/me/subscriptions',
@@ -151,7 +151,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon
.end()
}
-async function getUserSubscriptions (req: express.Request, res: express.Response) {
+async function listUserSubscriptions (req: express.Request, res: express.Response) {
const user = res.locals.oauth.token.User
const actorId = user.Account.Actor.id
diff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.ts
index 4b46a8f51e..d5ac322ebc 100644
--- a/server/core/initializers/constants.ts
+++ b/server/core/initializers/constants.ts
@@ -85,7 +85,7 @@ export const WEBSERVER = {
// Sortable columns per schema
export const SORTABLE_COLUMNS = {
ADMIN_USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
- USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
+ USER_SUBSCRIPTIONS: [ 'id', 'createdAt', 'channelUpdatedAt' ],
ACCOUNTS: [ 'createdAt' ],
JOBS: [ 'createdAt' ],
VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
diff --git a/server/core/models/actor/actor-follow.ts b/server/core/models/actor/actor-follow.ts
index 8925a3f6d8..47f6055c9d 100644
--- a/server/core/models/actor/actor-follow.ts
+++ b/server/core/models/actor/actor-follow.ts
@@ -40,7 +40,7 @@ import {
} from '../../initializers/constants.js'
import { AccountModel } from '../account/account.js'
import { ServerModel } from '../server/server.js'
-import { SequelizeModel, buildSQLAttributes, createSafeIn, getSort, searchAttribute, throwIfNotValid } from '../shared/index.js'
+import { SequelizeModel, buildSQLAttributes, createSafeIn, getSubscriptionSort, searchAttribute, throwIfNotValid } from '../shared/index.js'
import { doesExist } from '../shared/query.js'
import { VideoChannelModel } from '../video/video-channel.js'
import { ActorModel, unusedActorAttributesForAPI } from './actor.js'
@@ -428,11 +428,11 @@ export class ActorFollowModel extends SequelizeModel<ActorFollowModel> {
return {
attributes: forCount === true
? []
- : SORTABLE_COLUMNS.USER_SUBSCRIPTIONS,
+ : SORTABLE_COLUMNS.USER_SUBSCRIPTIONS.filter(s => s !== 'channelUpdatedAt'),
distinct: true,
offset: start,
limit: count,
- order: getSort(sort),
+ order: getSubscriptionSort(sort),
where,
include: [
{
diff --git a/server/core/models/shared/sort.ts b/server/core/models/shared/sort.ts
index d923072f2c..b1ca8cf89e 100644
--- a/server/core/models/shared/sort.ts
+++ b/server/core/models/shared/sort.ts
@@ -1,7 +1,7 @@
import { literal, OrderItem, Sequelize } from 'sequelize'
// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
-function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+export function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
let finalField: string | ReturnType<typeof Sequelize.col>
@@ -15,7 +15,7 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
return [ [ finalField, direction ], lastSort ]
}
-function getAdminUsersSort (value: string): OrderItem[] {
+export function getAdminUsersSort (value: string): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
let finalField: string | ReturnType<typeof Sequelize.col>
@@ -34,7 +34,7 @@ function getAdminUsersSort (value: string): OrderItem[] {
return [ [ finalField as any, direction, nullPolicy ], [ 'id', 'ASC' ] ]
}
-function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+export function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'name') {
@@ -44,7 +44,7 @@ function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]):
return getSort(value, lastSort)
}
-function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+export function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'trending') { // Sort by aggregation
@@ -81,7 +81,7 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
return [ firstSort, lastSort ]
}
-function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+export function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
const videoFields = new Set([ 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid' ])
@@ -96,7 +96,7 @@ function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ])
return getSort(value, lastSort)
}
-function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
+export function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
if (field === 'redundancyAllowed') {
@@ -109,7 +109,7 @@ function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'A
return getSort(value, lastSort)
}
-function getChannelSyncSort (value: string): OrderItem[] {
+export function getChannelSyncSort (value: string): OrderItem[] {
const { direction, field } = buildSortDirectionAndField(value)
if (field.toLowerCase() === 'videochannel') {
return [
@@ -119,7 +119,18 @@ function getChannelSyncSort (value: string): OrderItem[] {
return [ [ field, direction ] ]
}
-function buildSortDirectionAndField (value: string) {
+export function getSubscriptionSort (value: string): OrderItem[] {
+ const { direction, field } = buildSortDirectionAndField(value)
+
+ if (field === 'channelUpdatedAt') {
+ return [
+ [ literal('"ActorFollowing.VideoChannel.updatedAt"'), direction ]
+ ]
+ }
+ return [ [ field, direction ] ]
+}
+
+export function buildSortDirectionAndField (value: string) {
let field: string
let direction: 'ASC' | 'DESC'
@@ -133,14 +144,3 @@ function buildSortDirectionAndField (value: string) {
return { direction, field }
}
-
-export {
- buildSortDirectionAndField,
- getPlaylistSort,
- getSort,
- getAdminUsersSort,
- getVideoSort,
- getBlacklistSort,
- getChannelSyncSort,
- getInstanceFollowsSort
-}