Skip to content

Commit

Permalink
Merge pull request #12 from CMU-313/melody/proj1
Browse files Browse the repository at this point in the history
Merge individual changes made in Project 1
  • Loading branch information
shinyumh authored Sep 20, 2024
2 parents 68a7fd8 + 9e5cbfb commit b859768
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/messaging/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,27 @@ module.exports = function (Messaging) {

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 (!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')) {
try {
data.groups = JSON.parse(data.groups || '[]');
} catch (err) {
winston.error(err.stack);
data.groups = [];
}
if (data.hasOwnProperty('groups') || !fields.length || fields.includes('groups')) {
try {
data.groups = JSON.parse(data.groups || '[]');
} catch (err) {
winston.error(err.stack);
data.groups = [];
}
}
});
Expand Down

0 comments on commit b859768

Please sign in to comment.