You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/socket.io/notifications.js

62 lines
1.7 KiB
JavaScript

8 years ago
'use strict';
var async = require('async');
9 years ago
var user = require('../user');
var notifications = require('../notifications');
var utils = require('../../public/src/utils');
var SocketNotifs = {};
SocketNotifs.get = function (socket, data, callback) {
if (data && Array.isArray(data.nids) && socket.uid) {
user.notifications.getNotifications(data.nids, socket.uid, callback);
} else {
user.notifications.get(socket.uid, callback);
}
};
SocketNotifs.loadMore = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
9 years ago
return callback(new Error('[[error:invalid-data]]'));
}
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
9 years ago
}
var start = parseInt(data.after, 10);
var stop = start + 20;
async.waterfall([
function (next) {
user.notifications.getAll(socket.uid, start, stop, next);
},
function (notifications, next) {
next(null, {notifications: notifications, nextStart: stop});
},
], callback);
9 years ago
};
SocketNotifs.getCount = function (socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, callback);
};
SocketNotifs.deleteAll = function (socket, data, callback) {
10 years ago
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
10 years ago
}
user.notifications.deleteAll(socket.uid, callback);
};
SocketNotifs.markRead = function (socket, nid, callback) {
10 years ago
notifications.markRead(nid, socket.uid, callback);
};
SocketNotifs.markUnread = function (socket, nid, callback) {
notifications.markUnread(nid, socket.uid, callback);
};
SocketNotifs.markAllRead = function (socket, data, callback) {
10 years ago
notifications.markAllRead(socket.uid, callback);
};
module.exports = SocketNotifs;