11import { settings } from '../../../settings' ;
2- import { Messages } from '../../../models' ;
2+ import { Messages , Rooms } from '../../../models' ;
33import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser' ;
44
5- const hideMessagesOfType = new Set ( ) ;
5+ const hideMessagesOfTypeServer = new Set ( ) ;
66
77settings . get ( 'Hide_System_Messages' , function ( key , values ) {
88 const hiddenTypes = values . reduce ( ( array , value ) => [ ...array , ...value === 'mute_unmute' ? [ 'user-muted' , 'user-unmuted' ] : [ value ] ] , [ ] ) ;
9- hideMessagesOfType . clear ( ) ;
10- hiddenTypes . forEach ( ( item ) => hideMessagesOfType . add ( item ) ) ;
9+ hideMessagesOfTypeServer . clear ( ) ;
10+ hiddenTypes . forEach ( ( item ) => hideMessagesOfTypeServer . add ( item ) ) ;
1111} ) ;
1212
1313export const loadMessageHistory = function loadMessageHistory ( { userId, rid, end, limit = 20 , ls } ) {
14+ const room = Rooms . findOne ( rid , { fields : { sysMes : 1 } } ) ;
15+
16+ const hiddenMessageTypes = Array . isArray ( room && room . sysMes ) ? room . sysMes : Array . from ( hideMessagesOfTypeServer . values ( ) ) ; // TODO probably remove on chained event system
1417 const options = {
1518 sort : {
1619 ts : - 1 ,
@@ -24,7 +27,7 @@ export const loadMessageHistory = function loadMessageHistory({ userId, rid, end
2427 } ;
2528 }
2629
27- const records = end != null ? Messages . findVisibleByRoomIdBeforeTimestampNotContainingTypes ( rid , end , Array . from ( hideMessagesOfType . values ( ) ) , options ) . fetch ( ) : Messages . findVisibleByRoomIdNotContainingTypes ( rid , Array . from ( hideMessagesOfType . values ( ) ) , options ) . fetch ( ) ;
30+ const records = end != null ? Messages . findVisibleByRoomIdBeforeTimestampNotContainingTypes ( rid , end , hiddenMessageTypes , options ) . fetch ( ) : Messages . findVisibleByRoomIdNotContainingTypes ( rid , hiddenMessageTypes , options ) . fetch ( ) ;
2831 const messages = normalizeMessagesForUser ( records , userId ) ;
2932 let unreadNotLoaded = 0 ;
3033 let firstUnread ;
@@ -34,8 +37,7 @@ export const loadMessageHistory = function loadMessageHistory({ userId, rid, end
3437
3538 if ( ( firstMessage != null ? firstMessage . ts : undefined ) > ls ) {
3639 delete options . limit ;
37-
38- const unreadMessages = Messages . findVisibleByRoomIdBetweenTimestampsNotContainingTypes ( rid , ls , firstMessage . ts , Array . from ( hideMessagesOfType . values ( ) ) , {
40+ const unreadMessages = Messages . findVisibleByRoomIdBetweenTimestampsNotContainingTypes ( rid , ls , firstMessage . ts , hiddenMessageTypes , {
3941 limit : 1 ,
4042 sort : {
4143 ts : 1 ,
0 commit comments