mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add typeOneOf filter to list notifications
This commit is contained in:
parent
8f35e76928
commit
0bf17d869c
11 changed files with 200 additions and 98 deletions
|
@ -112,7 +112,6 @@ import { ActorImageModel } from '../actor/actor-image.js'
|
|||
] as (ModelIndexesOptions & { where?: WhereOptions })[]
|
||||
})
|
||||
export class UserNotificationModel extends SequelizeModel<UserNotificationModel> {
|
||||
|
||||
@AllowNull(false)
|
||||
@Default(null)
|
||||
@Is('UserNotificationType', value => throwIfNotValid(value, isUserNotificationTypeValid, 'type'))
|
||||
|
@ -275,22 +274,33 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
|
|||
})
|
||||
VideoCaption: Awaited<VideoCaptionModel>
|
||||
|
||||
static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
|
||||
const where = { userId }
|
||||
static listForApi (options: {
|
||||
userId: number
|
||||
start: number
|
||||
count: number
|
||||
sort: string
|
||||
unread?: boolean
|
||||
typeOneOf?: UserNotificationType_Type[]
|
||||
}) {
|
||||
const { userId, start, count, sort, unread, typeOneOf } = options
|
||||
|
||||
const countWhere = { userId }
|
||||
|
||||
const query = {
|
||||
userId,
|
||||
unread,
|
||||
offset: start,
|
||||
limit: count,
|
||||
sort,
|
||||
where
|
||||
|
||||
userId,
|
||||
unread,
|
||||
typeOneOf
|
||||
}
|
||||
|
||||
if (unread !== undefined) query.where['read'] = !unread
|
||||
if (unread !== undefined) countWhere['read'] = !unread
|
||||
if (typeOneOf !== undefined) countWhere['type'] = { [Op.in]: typeOneOf }
|
||||
|
||||
return Promise.all([
|
||||
UserNotificationModel.count({ where })
|
||||
UserNotificationModel.count({ where: countWhere })
|
||||
.then(count => count || 0),
|
||||
|
||||
count === 0
|
||||
|
@ -339,31 +349,31 @@ export class UserNotificationModel extends SequelizeModel<UserNotificationModel>
|
|||
const queries = [
|
||||
buildAccountWhereQuery(
|
||||
`SELECT "userNotification"."id" FROM "userNotification" ` +
|
||||
`INNER JOIN "account" ON "userNotification"."accountId" = "account"."id" ` +
|
||||
`INNER JOIN actor ON "actor"."id" = "account"."actorId" `
|
||||
`INNER JOIN "account" ON "userNotification"."accountId" = "account"."id" ` +
|
||||
`INNER JOIN actor ON "actor"."id" = "account"."actorId" `
|
||||
),
|
||||
|
||||
// Remove notifications from muted accounts that followed ours
|
||||
buildAccountWhereQuery(
|
||||
`SELECT "userNotification"."id" FROM "userNotification" ` +
|
||||
`INNER JOIN "actorFollow" ON "actorFollow".id = "userNotification"."actorFollowId" ` +
|
||||
`INNER JOIN actor ON actor.id = "actorFollow"."actorId" ` +
|
||||
`INNER JOIN account ON account."actorId" = actor.id `
|
||||
`INNER JOIN "actorFollow" ON "actorFollow".id = "userNotification"."actorFollowId" ` +
|
||||
`INNER JOIN actor ON actor.id = "actorFollow"."actorId" ` +
|
||||
`INNER JOIN account ON account."actorId" = actor.id `
|
||||
),
|
||||
|
||||
// Remove notifications from muted accounts that commented something
|
||||
buildAccountWhereQuery(
|
||||
`SELECT "userNotification"."id" FROM "userNotification" ` +
|
||||
`INNER JOIN "actorFollow" ON "actorFollow".id = "userNotification"."actorFollowId" ` +
|
||||
`INNER JOIN actor ON actor.id = "actorFollow"."actorId" ` +
|
||||
`INNER JOIN account ON account."actorId" = actor.id `
|
||||
`INNER JOIN "actorFollow" ON "actorFollow".id = "userNotification"."actorFollowId" ` +
|
||||
`INNER JOIN actor ON actor.id = "actorFollow"."actorId" ` +
|
||||
`INNER JOIN account ON account."actorId" = actor.id `
|
||||
),
|
||||
|
||||
buildAccountWhereQuery(
|
||||
`SELECT "userNotification"."id" FROM "userNotification" ` +
|
||||
`INNER JOIN "videoComment" ON "videoComment".id = "userNotification"."commentId" ` +
|
||||
`INNER JOIN account ON account.id = "videoComment"."accountId" ` +
|
||||
`INNER JOIN actor ON "actor"."id" = "account"."actorId" `
|
||||
`INNER JOIN "videoComment" ON "videoComment".id = "userNotification"."commentId" ` +
|
||||
`INNER JOIN account ON account.id = "videoComment"."accountId" ` +
|
||||
`INNER JOIN actor ON "actor"."id" = "account"."actorId" `
|
||||
)
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue