Skip to content

Commit

Permalink
Merge pull request #16 from CMU-313/phillip-project1
Browse files Browse the repository at this point in the history
Refactoring code to reduce level of nesting (Project 1)
  • Loading branch information
philliparaujo authored Sep 23, 2024
2 parents a81893e + 59843e2 commit c0c83be
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions public/src/modules/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ define('chat', [
}
if (module.modalExists(roomId)) {
loadAndCenter(module.getModal(roomId));
} else {
api.get(`/chats/${roomId}`, {
uid: uid || app.user.uid,
}).then((roomData) => {
roomData.users = roomData.users.filter(function (user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
roomData.uid = uid || app.user.uid;
roomData.isSelf = true;
module.createModal(roomData, loadAndCenter);
}).catch(alerts.error);
return;
}

api.get(`/chats/${roomId}`, {
uid: uid || app.user.uid,
}).then((roomData) => {
roomData.users = roomData.users.filter(function (user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
roomData.uid = uid || app.user.uid;
roomData.isSelf = true;
module.createModal(roomData, loadAndCenter);
}).catch(alerts.error);
});
};

Expand Down

0 comments on commit c0c83be

Please sign in to comment.