aboutsummaryrefslogtreecommitdiff
path: root/routes/user.js
diff options
context:
space:
mode:
authorHumairAK <humair88@hotmail.com>2016-08-27 19:43:07 +0000
committerHumairAK <humair88@hotmail.com>2016-08-27 19:43:07 +0000
commit83f233a7fe270dc77893c2df590b2e28ba30fc41 (patch)
tree5916fa8fde478da08a481fcf9fb367f311e08eeb /routes/user.js
parent17a4b5f57e0223b211ab8ff601e587920e6e1bef (diff)
Added more inbox functionality for paging
Diffstat (limited to 'routes/user.js')
-rw-r--r--routes/user.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/routes/user.js b/routes/user.js
index 3717be4..9b5f0fb 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -136,6 +136,7 @@ router.get('/user_profile', loggedIn, isUser, function(req, res, next) {
/**
* Serve mail messages for page pageNum with messageCount messages as a JSON object
+ * mail is sorted by date.
*/
router.get('/user_profile/inbox/:messageCount/:pageNum', loggedIn, isUser, function(req, res, next) {
@@ -182,13 +183,11 @@ router.get('/user_profile/inbox/:messageCount/:pageNum', loggedIn, isUser, funct
var index = (pageNum - 1) * messageCount;
var indexMax = index + messageCount;
var inboxLength = inbox.length;
- var count = 0;
- /* Testing Purposes
- var notification = "index = " + index + "\n" +
- "indexMax = " + indexMax + "\n" +
- "inboxLength = " + inbox.length + "\n";
- console.log(notification); */
+ // Consider a more efficient alternative to sorting mail
+ inbox.sort(function(b,a){
+ return new Date(a.date).getTime() - new Date(b.date).getTime()
+ });
// Find the 10 messages situated at page num in inbox, store in mail
if(index >= inboxLength){
@@ -202,14 +201,17 @@ router.get('/user_profile/inbox/:messageCount/:pageNum', loggedIn, isUser, funct
while((index < inboxLength) && (index < indexMax)){
mail.push(inbox[index]);
index++;
- count++;
- console.log("in while: " + count);
}
}
// return mail JSON object :: JSON.stringify({json});
- var mailJSON = JSON.stringify(mail);
- res.end(mailJSON);
+ var mailbox = {
+ mailCount : inboxLength,
+ mail : mail
+ };
+ var mailboxJSON = JSON.stringify(mailbox);
+
+ res.end(mailboxJSON);
});
});