fix: consider broadcast union with user
close #25682 Signed-off-by: JounQin <admin@1stg.me>
This commit is contained in:
@@ -138,14 +138,14 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
};
|
||||
};
|
||||
|
||||
private getBroadcastUnion = () => {
|
||||
private getBroadcastUnion = (user?: string | null) => {
|
||||
return this.db('broadcast')
|
||||
.leftJoin(
|
||||
'broadcast_user_status',
|
||||
'id',
|
||||
'=',
|
||||
'broadcast_user_status.broadcast_id',
|
||||
)
|
||||
.leftJoin('broadcast_user_status', function clause() {
|
||||
const join = this.on('id', '=', 'broadcast_user_status.broadcast_id');
|
||||
if (user !== null && user !== undefined) {
|
||||
join.andOnVal('user', '=', user);
|
||||
}
|
||||
})
|
||||
.select(NOTIFICATION_COLUMNS);
|
||||
};
|
||||
|
||||
@@ -156,7 +156,7 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
|
||||
const subQuery = this.db('notification')
|
||||
.select(NOTIFICATION_COLUMNS)
|
||||
.unionAll([this.getBroadcastUnion()])
|
||||
.unionAll([this.getBroadcastUnion(user)])
|
||||
.as('notifications');
|
||||
|
||||
const query = this.db.from(subQuery).where(q => {
|
||||
@@ -345,16 +345,19 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
broadcastQuery.update({ ...updateColumns, read: undefined }),
|
||||
]);
|
||||
|
||||
return await this.getNotification({ id });
|
||||
return await this.getNotification({ id, user: notification.user });
|
||||
}
|
||||
|
||||
async getNotification(options: { id: string }): Promise<Notification | null> {
|
||||
async getNotification(options: {
|
||||
id: string;
|
||||
user?: string | null;
|
||||
}): Promise<Notification | null> {
|
||||
const rows = await this.db
|
||||
.select('*')
|
||||
.from(
|
||||
this.db('notification')
|
||||
.select(NOTIFICATION_COLUMNS)
|
||||
.unionAll([this.getBroadcastUnion()])
|
||||
.unionAll([this.getBroadcastUnion(options.user)])
|
||||
.as('notifications'),
|
||||
)
|
||||
.where('id', options.id)
|
||||
|
||||
Reference in New Issue
Block a user