Add backend support for users to follow series

Introduces a UserSeriesFollow model with a dedicated join table so users
can follow/unfollow series and receive socket notifications when new
books are added to followed series. The user JSON response now includes a
seriesFollowing array, and three new API endpoints are available under
/api/me/follows/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Paul DeVito 2026-03-22 20:29:11 -04:00
parent 8b89b27654
commit 37b95582a2
9 changed files with 744 additions and 5 deletions

View file

@ -357,7 +357,7 @@ class User extends Model {
[sequelize.Op.like]: username
}
},
include: this.sequelize.models.mediaProgress
include: [this.sequelize.models.mediaProgress, this.sequelize.models.userSeriesFollow]
})
if (user) userCache.set(user)
@ -382,7 +382,7 @@ class User extends Model {
[sequelize.Op.like]: email
}
},
include: this.sequelize.models.mediaProgress
include: [this.sequelize.models.mediaProgress, this.sequelize.models.userSeriesFollow]
})
if (user) userCache.set(user)
@ -402,7 +402,7 @@ class User extends Model {
if (cachedUser) return cachedUser
const user = await this.findByPk(userId, {
include: this.sequelize.models.mediaProgress
include: [this.sequelize.models.mediaProgress, this.sequelize.models.userSeriesFollow]
})
if (user) userCache.set(user)
@ -426,7 +426,7 @@ class User extends Model {
where: {
[sequelize.Op.or]: [{ id: userId }, { 'extraData.oldUserId': userId }]
},
include: this.sequelize.models.mediaProgress
include: [this.sequelize.models.mediaProgress, this.sequelize.models.userSeriesFollow]
})
if (user) userCache.set(user)
@ -447,7 +447,7 @@ class User extends Model {
const user = await this.findOne({
where: sequelize.where(sequelize.literal(`extraData->>"authOpenIDSub"`), sub),
include: this.sequelize.models.mediaProgress
include: [this.sequelize.models.mediaProgress, this.sequelize.models.userSeriesFollow]
})
if (user) userCache.set(user)
@ -506,6 +506,17 @@ class User extends Model {
}
}
/**
* Invalidate cached user when series follows change
* @param {string} userId
*/
static seriesFollowChanged(userId) {
const cachedUser = userCache.getById(userId)
if (cachedUser) {
userCache.delete(userId)
}
}
/**
* Initialize model
* @param {import('../Database').sequelize} sequelize
@ -621,6 +632,7 @@ class User extends Model {
isOldToken: this.isOldToken,
mediaProgress: this.mediaProgresses?.map((mp) => mp.getOldMediaProgress()) || [],
seriesHideFromContinueListening: [...seriesHideFromContinueListening],
seriesFollowing: this.userSeriesFollows?.map((f) => f.seriesId) || [],
bookmarks: this.bookmarks?.map((b) => ({ ...b })) || [],
isActive: this.isActive,
isLocked: this.isLocked,