mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
@@ -92,6 +92,7 @@
|
||||
socket.on('api:notifications.get', function(data) {
|
||||
var notifFrag = document.createDocumentFragment(),
|
||||
notifEl = document.createElement('li'),
|
||||
notifIcon = document.querySelector('.notifications a i'),
|
||||
numRead = data.read.length,
|
||||
numUnread = data.unread.length,
|
||||
x;
|
||||
@@ -114,18 +115,21 @@
|
||||
notifFrag.appendChild(notifEl);
|
||||
}
|
||||
notifList.appendChild(notifFrag);
|
||||
|
||||
socket.emit('api:notifications.removeFlag');
|
||||
notifIcon.className = 'icon-circle-blank';
|
||||
});
|
||||
socket.on('api:notifications.counts', function(counts) {
|
||||
socket.on('api:notifications.hasFlag', function(flag) {
|
||||
var notifIcon = document.querySelector('.notifications a i');
|
||||
if(notifIcon) {
|
||||
if (counts.unread > 0) notifIcon.className = 'icon-circle active';
|
||||
if (flag > 0) notifIcon.className = 'icon-circle active';
|
||||
else notifIcon.className = 'icon-circle-blank';
|
||||
}
|
||||
});
|
||||
socket.on('event:new_notification', function() {
|
||||
document.querySelector('.notifications a i').className = 'icon-circle active';
|
||||
});
|
||||
socket.emit('api:notifications.counts');
|
||||
socket.emit('api:notifications.hasFlag');
|
||||
|
||||
|
||||
require(['mobileMenu'], function(mobileMenu) {
|
||||
|
||||
@@ -54,6 +54,7 @@ var RDB = require('./redis.js'),
|
||||
(function(uid) {
|
||||
Notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() {
|
||||
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.score, nid);
|
||||
RDB.set('uid:' + uid + ':notifications:flag', 1);
|
||||
global.io.sockets.in('uid_' + uid).emit('event:new_notification');
|
||||
if (callback) callback(true);
|
||||
});
|
||||
|
||||
21
src/user.js
21
src/user.js
@@ -789,20 +789,17 @@ var utils = require('./../public/src/utils.js'),
|
||||
callback(notifications);
|
||||
});
|
||||
},
|
||||
counts: function(uid, callback) {
|
||||
async.parallel({
|
||||
unread: function(next) {
|
||||
RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, function(err, count) {
|
||||
next(null, count);
|
||||
hasFlag: function(uid, callback) {
|
||||
RDB.get('uid:1:notifications:flag', function(err, flag) {
|
||||
if (err) RDB.handle(err);
|
||||
|
||||
if (flag === '1') callback(true);
|
||||
else callback(false);
|
||||
});
|
||||
},
|
||||
read: function(next) {
|
||||
RDB.zcount('uid:' + uid + ':notifications:read', 0, 10, function(err, count) {
|
||||
next(null, count);
|
||||
});
|
||||
}
|
||||
}, function(err, counts) {
|
||||
callback(counts);
|
||||
removeFlag: function(uid) {
|
||||
RDB.del('uid:' + uid + ':notifications:flag', function(err) {
|
||||
if (err) RDB.handle(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,9 +292,6 @@ var express = require('express'),
|
||||
app.get('/api/:method/:id*', api_method);
|
||||
|
||||
app.all('/test', function(req, res) {
|
||||
notifications.create('normal 7', 5, '/topics/1', 'fteds', function(nid) {
|
||||
notifications.push(nid, 1);
|
||||
});
|
||||
res.send();
|
||||
});
|
||||
|
||||
|
||||
@@ -262,12 +262,16 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:notifications.counts', function(data) {
|
||||
user.notifications.counts(uid, function(counts) {
|
||||
socket.emit('api:notifications.counts', counts);
|
||||
socket.on('api:notifications.hasFlag', function(data) {
|
||||
user.notifications.hasFlag(uid, function(flag) {
|
||||
socket.emit('api:notifications.hasFlag', flag);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:notifications.removeFlag', function() {
|
||||
user.notifications.removeFlag(uid);
|
||||
});
|
||||
|
||||
socket.on('api:notifications.mark_read', function(nid) {
|
||||
notifications.mark_read(nid, uid);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user