Baris Usakli 12 years ago
commit 4a214b6ef0

@ -96,10 +96,39 @@
notifTrigger.addEventListener('click', function(e) { notifTrigger.addEventListener('click', function(e) {
e.preventDefault(); e.preventDefault();
if (notifContainer.className.indexOf('open') === -1) { if (notifContainer.className.indexOf('open') === -1) {
socket.emit('api:notifications.get'); socket.emit('api:notifications.get', null, function(data) {
socket.emit('api:notifications.mark_all_read', null, function() { var notifFrag = document.createDocumentFragment(),
notifIcon.className = 'icon-circle-blank'; notifEl = document.createElement('li'),
utils.refreshTitle(); numRead = data.read.length,
numUnread = data.unread.length,
x;
notifList.innerHTML = '';
if ((data.read.length + data.unread.length) > 0) {
for(x=0;x<numUnread;x++) {
notifEl.setAttribute('data-nid', data.unread[x].nid);
notifEl.className = 'unread';
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
notifFrag.appendChild(notifEl.cloneNode(true));
}
for(x=0;x<numRead;x++) {
notifEl.setAttribute('data-nid', data.read[x].nid);
notifEl.className = '';
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
notifFrag.appendChild(notifEl.cloneNode(true));
}
} else {
notifEl.innerHTML = '<a>You have no notifications</a>';
notifFrag.appendChild(notifEl);
}
notifList.appendChild(notifFrag);
if (data.unread.length > 0) notifIcon.className = 'icon-circle active';
else notifIcon.className = 'icon-circle-blank';
socket.emit('api:notifications.mark_all_read', null, function() {
notifIcon.className = 'icon-circle-blank';
utils.refreshTitle();
});
}); });
} }
}); });
@ -115,35 +144,6 @@
if (nid > 0) socket.emit('api:notifications.mark_read', nid); if (nid > 0) socket.emit('api:notifications.mark_read', nid);
} }
}); });
socket.on('api:notifications.get', function(data) {
var notifFrag = document.createDocumentFragment(),
notifEl = document.createElement('li'),
numRead = data.read.length,
numUnread = data.unread.length,
x;
notifList.innerHTML = '';
if ((data.read.length + data.unread.length) > 0) {
for(x=0;x<numUnread;x++) {
notifEl.setAttribute('data-nid', data.unread[x].nid);
notifEl.className = 'unread';
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
notifFrag.appendChild(notifEl.cloneNode(true));
}
for(x=0;x<numRead;x++) {
notifEl.setAttribute('data-nid', data.read[x].nid);
notifEl.className = '';
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
notifFrag.appendChild(notifEl.cloneNode(true));
}
} else {
notifEl.innerHTML = '<a>You have no notifications</a>';
notifFrag.appendChild(notifEl);
}
notifList.appendChild(notifFrag);
if (data.unread.length > 0) notifIcon.className = 'icon-circle active';
else notifIcon.className = 'icon-circle-blank';
});
socket.on('event:new_notification', function() { socket.on('event:new_notification', function() {
document.querySelector('.notifications a i').className = 'icon-circle active'; document.querySelector('.notifications a i').className = 'icon-circle active';
app.alert({ app.alert({

@ -70,7 +70,10 @@ var express = require('express'),
ttl: 60*60*24*14 ttl: 60*60*24*14
}), }),
secret: nconf.get('secret'), secret: nconf.get('secret'),
key: 'express.sid' key: 'express.sid',
cookie: {
maxAge: 60*60*24*30 // 30 days
}
})); }));
app.use(express.csrf()); app.use(express.csrf());
app.use(function(req, res, next) { app.use(function(req, res, next) {

@ -484,9 +484,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
postTools.restore(uid, data.pid); postTools.restore(uid, data.pid);
}); });
socket.on('api:notifications.get', function(data) { socket.on('api:notifications.get', function(data, callback) {
user.notifications.get(uid, function(notifs) { user.notifications.get(uid, function(notifs) {
socket.emit('api:notifications.get', notifs); callback(notifs);
}); });
}); });

Loading…
Cancel
Save