@ -54,6 +54,15 @@ module.exports = function (Messaging) {
data . groupChat = parseInt ( data . groupChat , 10 ) === 1 ;
data . groupChat = parseInt ( data . groupChat , 10 ) === 1 ;
}
}
if ( ! fields . length || fields . includes ( 'notificationSetting' ) ) {
data . notificationSetting = data . notificationSetting ||
(
data . public ?
Messaging . notificationSettings . ATMENTION :
Messaging . notificationSettings . ALLMESSAGES
) ;
}
if ( data . hasOwnProperty ( 'groups' ) || ! fields . length || fields . includes ( 'groups' ) ) {
if ( data . hasOwnProperty ( 'groups' ) || ! fields . length || fields . includes ( 'groups' ) ) {
try {
try {
data . groups = JSON . parse ( data . groups || '[]' ) ;
data . groups = JSON . parse ( data . groups || '[]' ) ;
@ -76,6 +85,7 @@ module.exports = function (Messaging) {
const room = {
const room = {
roomId : roomId ,
roomId : roomId ,
timestamp : now ,
timestamp : now ,
notificationSetting : data . notificationSetting ,
} ;
} ;
if ( data . hasOwnProperty ( 'roomName' ) && data . roomName ) {
if ( data . hasOwnProperty ( 'roomName' ) && data . roomName ) {
@ -145,10 +155,14 @@ module.exports = function (Messaging) {
... roomIds . map ( id => ` chat:room: ${ id } :uids ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :uids ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :owners ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :owners ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :uids:online ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :uids:online ` ) ,
... roomIds . map ( id => ` chat:room: ${ id } :notification:settings ` ) ,
] ) ,
] ) ,
db . sortedSetRemove ( 'chat:rooms' , roomIds ) ,
db . sortedSetRemove ( [
db . sortedSetRemove ( 'chat:rooms:public' , roomIds ) ,
'chat:rooms' ,
db . sortedSetRemove ( 'chat:rooms:public:order' , roomIds ) ,
'chat:rooms:public' ,
'chat:rooms:public:order' ,
'chat:rooms:public:lastpost' ,
] , roomIds ) ,
] ) ;
] ) ;
cache . del ( [
cache . del ( [
'chat:rooms:public:all' ,
'chat:rooms:public:all' ,
@ -448,7 +462,36 @@ module.exports = function (Messaging) {
await db . sortedSetAdd ( ` chat:room: ${ roomId } :uids:online ` , Date . now ( ) , uid ) ;
await db . sortedSetAdd ( ` chat:room: ${ roomId } :uids:online ` , Date . now ( ) , uid ) ;
}
}
const [ canReply , users , messages , settings , isOwner , onlineUids ] = await Promise . all ( [
async function getNotificationOptions ( ) {
const userSetting = await db . getObjectField ( ` chat:room: ${ roomId } :notification:settings ` , uid ) ;
const roomDefault = room . notificationSetting ;
const currentSetting = userSetting || roomDefault ;
const labels = {
[ Messaging . notificationSettings . NONE ] : { label : '[[modules:chat.notification-setting-none]]' , icon : 'fa-ban' } ,
[ Messaging . notificationSettings . ATMENTION ] : { label : '[[modules:chat.notification-setting-at-mention-only]]' , icon : 'fa-at' } ,
[ Messaging . notificationSettings . ALLMESSAGES ] : { label : '[[modules:chat.notification-setting-all-messages]]' , icon : 'fa-comment-o' } ,
} ;
const options = [
{
label : '[[modules:chat.notification-setting-room-default]]' ,
subLabel : labels [ roomDefault ] . label || '' ,
icon : labels [ roomDefault ] . icon ,
value : - 1 ,
selected : userSetting === null ,
} ,
] ;
Object . keys ( labels ) . forEach ( ( key ) => {
options . push ( {
label : labels [ key ] . label ,
icon : labels [ key ] . icon ,
value : key ,
selected : parseInt ( userSetting , 10 ) === parseInt ( key , 10 ) ,
} ) ;
} ) ;
return { options , selectedIcon : labels [ currentSetting ] . icon } ;
}
const [ canReply , users , messages , settings , isOwner , onlineUids , notifOptions ] = await Promise . all ( [
Messaging . canReply ( roomId , uid ) ,
Messaging . canReply ( roomId , uid ) ,
Messaging . getUsersInRoomFromSet ( ` chat:room: ${ roomId } :uids:online ` , roomId , 0 , 39 , true ) ,
Messaging . getUsersInRoomFromSet ( ` chat:room: ${ roomId } :uids:online ` , roomId , 0 , 39 , true ) ,
Messaging . getMessages ( {
Messaging . getMessages ( {
@ -460,6 +503,7 @@ module.exports = function (Messaging) {
user . getSettings ( uid ) ,
user . getSettings ( uid ) ,
Messaging . isRoomOwner ( uid , roomId ) ,
Messaging . isRoomOwner ( uid , roomId ) ,
io . getUidsInRoom ( ` chat_room_ ${ roomId } ` ) ,
io . getUidsInRoom ( ` chat_room_ ${ roomId } ` ) ,
getNotificationOptions ( ) ,
] ) ;
] ) ;
users . forEach ( ( user ) => {
users . forEach ( ( user ) => {
@ -481,6 +525,8 @@ module.exports = function (Messaging) {
room . showUserInput = ! room . maximumUsersInChatRoom || room . maximumUsersInChatRoom > 2 ;
room . showUserInput = ! room . maximumUsersInChatRoom || room . maximumUsersInChatRoom > 2 ;
room . isAdminOrGlobalMod = isAdmin || isGlobalMod ;
room . isAdminOrGlobalMod = isAdmin || isGlobalMod ;
room . isAdmin = isAdmin ;
room . isAdmin = isAdmin ;
room . notificationOptions = notifOptions . options ;
room . notificationOptionsIcon = notifOptions . selectedIcon ;
const payload = await plugins . hooks . fire ( 'filter:messaging.loadRoom' , { uid , data , room } ) ;
const payload = await plugins . hooks . fire ( 'filter:messaging.loadRoom' , { uid , data , room } ) ;
return payload . room ;
return payload . room ;