diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000..0685d1cfc7 Binary files /dev/null and b/dump.rdb differ diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index 04c75e9e67..495e282d62 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -41,36 +41,53 @@ module.exports = function (Messaging) { modifyRoomData(roomData, fields); return roomData; }; + // Copilot generated code + + // print statements + + console.log('Safa'); function modifyRoomData(rooms, fields) { rooms.forEach((data) => { - if (data) { - db.parseIntFields(data, intFields, fields); - data.roomName = validator.escape(String(data.roomName || '')); - data.public = parseInt(data.public, 10) === 1; - data.groupChat = data.userCount > 2; - - if (!fields.length || fields.includes('notificationSetting')) { - data.notificationSetting = data.notificationSetting || - ( - data.public ? - Messaging.notificationSettings.ATMENTION : - Messaging.notificationSettings.ALLMESSAGES - ); - } + if (!data) return; + + db.parseIntFields(data, intFields, fields); + data.roomName = validator.escape(String(data.roomName || '')); + data.public = parseInt(data.public, 10) === 1; + data.groupChat = data.userCount > 2; + + if (shouldUpdateNotificationSetting(fields)) { + data.notificationSetting = data.notificationSetting || + (data.public ? + Messaging.notificationSettings.ATMENTION : + Messaging.notificationSettings.ALLMESSAGES + ); + } - if (data.hasOwnProperty('groups') || !fields.length || fields.includes('groups')) { - try { - data.groups = JSON.parse(data.groups || '[]'); - } catch (err) { - winston.error(err.stack); - data.groups = []; - } + if (shouldUpdateGroups(data, fields)) { + try { + data.groups = JSON.parse(data.groups || '[]'); + } catch (err) { + winston.error(err.stack); + data.groups = []; } } }); } + function shouldUpdateNotificationSetting(fields) { + return !fields.length || fields.includes('notificationSetting'); + } + + function shouldUpdateGroups(data, fields) { + return data.hasOwnProperty('groups') || !fields.length || fields.includes('groups'); + } + + // print statements + console.log('Safa'); + + // End of Copilot generated code + Messaging.newRoom = async (uid, data) => { // backwards compat. remove in 4.x if (Array.isArray(data)) { // old usage second param used to be toUids