mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-14 00:20:40 +01:00
notifications page + ajaxify route + css styling
This commit is contained in:
@@ -154,6 +154,16 @@ var user = require('./../user.js'),
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/notifications', function(req, res) {
|
||||
if (req.user && req.user.uid) {
|
||||
user.notifications.getAll(req.user.uid, null, null, function(err, notifications) {
|
||||
res.json({
|
||||
notifications: notifications
|
||||
});
|
||||
});
|
||||
} else res.send(403);
|
||||
});
|
||||
|
||||
app.get('/confirm/:id', function (req, res) {
|
||||
user.email.confirm(req.params.id, function (data) {
|
||||
if (data.status === 'ok') {
|
||||
|
||||
30
src/user.js
30
src/user.js
@@ -945,6 +945,36 @@ var utils = require('./../public/src/utils.js'),
|
||||
callback(notifications);
|
||||
});
|
||||
},
|
||||
getAll: function(uid, limit, before, callback) {
|
||||
var now = new Date();
|
||||
|
||||
if (!limit || parseInt(limit) <= 0) limit = 25;
|
||||
if (before) before = new Date(parseInt(before, 10));
|
||||
|
||||
RDB.multi()
|
||||
.zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
|
||||
.zrevrangebyscore('uid:' + uid + ':notifications:unread', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
|
||||
.exec(function(err, results) {
|
||||
// Merge the read and unread notifications
|
||||
var nids = results[0].concat(results[1]);
|
||||
|
||||
async.map(nids, function(nid, next) {
|
||||
notifications.get(nid, function(notif_data) {
|
||||
next(null, notif_data);
|
||||
});
|
||||
}, function(err, notifs) {
|
||||
notifs = notifs.sort(function(a, b) {
|
||||
return parseInt(b.datetime, 10) - parseInt(a.datetime, 10);
|
||||
}).map(function(notif) {
|
||||
notif.datetimeISO = new Date(parseInt(notif.datetime, 10)).toISOString();
|
||||
|
||||
return notif;
|
||||
});
|
||||
|
||||
callback(err, notifs);
|
||||
})
|
||||
});
|
||||
},
|
||||
getUnreadCount: function(uid, callback) {
|
||||
RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, callback);
|
||||
},
|
||||
|
||||
@@ -282,7 +282,7 @@ var express = require('express'),
|
||||
|
||||
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
|
||||
(function () {
|
||||
var routes = ['login', 'register', 'account', 'recent', 'unread', 'popular', 'active', '403', '404'];
|
||||
var routes = ['login', 'register', 'account', 'recent', 'unread', 'notifications', '403', '404'];
|
||||
|
||||
for (var i = 0, ii = routes.length; i < ii; i++) {
|
||||
(function (route) {
|
||||
|
||||
Reference in New Issue
Block a user