@@ -5,6 +5,7 @@ import type { PaginatedResult } from '@rocket.chat/rest-typings';
55import { escapeRegExp } from '@rocket.chat/string-helpers' ;
66import type { FindOptions } from 'mongodb' ;
77
8+ import { notifyOnLivechatInquiryChangedByRoom , notifyOnRoomChanged } from '../../../../../../app/lib/server/lib/notifyListener' ;
89import { logger } from '../../lib/logger' ;
910
1011type FindPriorityParams = {
@@ -24,7 +25,7 @@ export async function findPriority({
2425 ...( text && { $or : [ { name : new RegExp ( escapeRegExp ( text ) , 'i' ) } , { description : new RegExp ( escapeRegExp ( text ) , 'i' ) } ] } ) ,
2526 } ;
2627
27- const { cursor, totalCount } = await LivechatPriority . findPaginated ( query , {
28+ const { cursor, totalCount } = LivechatPriority . findPaginated ( query , {
2829 sort : sort || { name : 1 } ,
2930 skip : offset ,
3031 limit : count ,
@@ -64,7 +65,7 @@ export const updateRoomPriority = async (
6465 user : Required < Pick < IUser , '_id' | 'username' | 'name' > > ,
6566 priorityId : string ,
6667) : Promise < void > => {
67- const room = await LivechatRooms . findOneById ( rid , { projection : { _id : 1 } } ) ;
68+ const room = await LivechatRooms . findOneById ( rid ) ;
6869 if ( ! room ) {
6970 throw new Error ( 'error-room-does-not-exist' ) ;
7071 }
@@ -79,10 +80,15 @@ export const updateRoomPriority = async (
7980 LivechatInquiry . setPriorityForRoom ( rid , priority ) ,
8081 addPriorityChangeHistoryToRoom ( room . _id , user , priority ) ,
8182 ] ) ;
83+
84+ void notifyOnRoomChanged ( { ...room , priorityId : priority . _id , priorityWeight : priority . sortItem } , 'updated' ) ;
85+ void notifyOnLivechatInquiryChangedByRoom ( rid , 'updated' ) ;
8286} ;
8387
8488export const removePriorityFromRoom = async ( rid : string , user : Required < Pick < IUser , '_id' | 'username' | 'name' > > ) : Promise < void > => {
85- const room = await LivechatRooms . findOneById < Pick < IOmnichannelRoom , '_id' > > ( rid , { projection : { _id : 1 } } ) ;
89+ const room = await LivechatRooms . findOneById < Omit < IOmnichannelRoom , 'priorityId' | 'priorityWeight' > > ( rid , {
90+ projection : { priorityId : 0 , priorityWeight : 0 } ,
91+ } ) ;
8692 if ( ! room ) {
8793 throw new Error ( 'error-room-does-not-exist' ) ;
8894 }
@@ -92,6 +98,9 @@ export const removePriorityFromRoom = async (rid: string, user: Required<Pick<IU
9298 LivechatInquiry . unsetPriorityForRoom ( rid ) ,
9399 addPriorityChangeHistoryToRoom ( rid , user ) ,
94100 ] ) ;
101+
102+ void notifyOnRoomChanged ( room , 'updated' ) ;
103+ void notifyOnLivechatInquiryChangedByRoom ( rid , 'updated' ) ;
95104} ;
96105
97106const addPriorityChangeHistoryToRoom = async (
0 commit comments