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