mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
updating notifications.create to accept a hash instead of discrete arguments - breaking change
This commit is contained in:
@@ -53,21 +53,30 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Notifications.create = function(text, path, uniqueId, callback) {
|
Notifications.create = function(data, callback) {
|
||||||
/**
|
/**
|
||||||
* uniqueId is used solely to override stale nids.
|
* data.uniqueId is used solely to override stale nids.
|
||||||
* If a new nid is pushed to a user and an existing nid in the user's
|
* If a new nid is pushed to a user and an existing nid in the user's
|
||||||
* (un)read list contains the same uniqueId, it will be removed, and
|
* (un)read list contains the same uniqueId, it will be removed, and
|
||||||
* the new one put in its place.
|
* the new one put in its place.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Add default values to data Object if not already set
|
||||||
|
var defaults = {
|
||||||
|
text: '',
|
||||||
|
path: null,
|
||||||
|
datetime: Date.now(),
|
||||||
|
uniqueId: utils.generateUUID()
|
||||||
|
};
|
||||||
|
for(var v in defaults) {
|
||||||
|
if (defaults.hasOwnProperty(v) && !data[v]) {
|
||||||
|
data[v] = defaults[v];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.incrObjectField('global', 'nextNid', function(err, nid) {
|
db.incrObjectField('global', 'nextNid', function(err, nid) {
|
||||||
db.setAdd('notifications', nid);
|
db.setAdd('notifications', nid);
|
||||||
db.setObject('notifications:' + nid, {
|
db.setObject('notifications:' + nid, data, function(err, status) {
|
||||||
text: text || '',
|
|
||||||
path: path || null,
|
|
||||||
datetime: Date.now(),
|
|
||||||
uniqueId: uniqueId || utils.generateUUID()
|
|
||||||
}, function(err, status) {
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
callback(nid);
|
callback(nid);
|
||||||
}
|
}
|
||||||
@@ -75,18 +84,6 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function destroy(nid) {
|
|
||||||
|
|
||||||
db.delete('notifications:' + nid, function(err, result) {
|
|
||||||
db.setRemove('notifications', nid, function(err, result) {
|
|
||||||
if (err) {
|
|
||||||
winston.error('Problem deleting expired notifications. Stack follows.');
|
|
||||||
winston.error(err.stack);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Notifications.push = function(nid, uids, callback) {
|
Notifications.push = function(nid, uids, callback) {
|
||||||
var websockets = require('./socket.io');
|
var websockets = require('./socket.io');
|
||||||
if (!Array.isArray(uids)) {
|
if (!Array.isArray(uids)) {
|
||||||
|
|||||||
@@ -103,7 +103,11 @@ SocketModules.chats.send = function(socket, data) {
|
|||||||
notifText = 'New message from <strong>' + username + '</strong>';
|
notifText = 'New message from <strong>' + username + '</strong>';
|
||||||
|
|
||||||
if (!module.parent.exports.isUserOnline(touid)) {
|
if (!module.parent.exports.isUserOnline(touid)) {
|
||||||
notifications.create(notifText, 'javascript:app.openChat('' + username + '', ' + socket.uid + ');', 'notification_' + socket.uid + '_' + touid, function(nid) {
|
notifications.create({
|
||||||
|
text: notifText,
|
||||||
|
path: 'javascript:app.openChat('' + username + '', ' + socket.uid + ');',
|
||||||
|
uniqueId: 'notification_' + socket.uid + '_' + touid
|
||||||
|
}, function(nid) {
|
||||||
notifications.push(nid, [touid], function(success) {
|
notifications.push(nid, [touid], function(success) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -260,7 +260,11 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(adminGroup, next) {
|
function(adminGroup, next) {
|
||||||
|
|
||||||
notifications.create(message, path, 'post_flag:' + pid, function(nid) {
|
notifications.create({
|
||||||
|
text: message,
|
||||||
|
path: path,
|
||||||
|
uniqueId: 'post_flag:' + pid
|
||||||
|
}, function(nid) {
|
||||||
notifications.push(nid, adminGroup.members, function() {
|
notifications.push(nid, adminGroup.members, function() {
|
||||||
next(null);
|
next(null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -268,7 +268,11 @@ var winston = require('winston'),
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications.create('<strong>' + username + '</strong> has posted a reply to: "<strong>' + topicData.title + '</strong>"', nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid, 'topic:' + tid, function(nid) {
|
notifications.create({
|
||||||
|
text: '<strong>' + username + '</strong> has posted a reply to: "<strong>' + topicData.title + '</strong>"',
|
||||||
|
path: nconf.get('relative_path') + '/topic/' + topicData.slug + '#' + pid,
|
||||||
|
uniqueId: 'topic:' + tid
|
||||||
|
}, function(nid) {
|
||||||
next(null, nid);
|
next(null, nid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -289,7 +293,7 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err, results) {
|
], function(err, results) {
|
||||||
if (!err) {
|
if (!err && results[1].length) {
|
||||||
notifications.push(results[0], results[1]);
|
notifications.push(results[0], results[1]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
16
src/user.js
16
src/user.js
@@ -710,13 +710,19 @@ var bcrypt = require('bcryptjs'),
|
|||||||
User.sendPostNotificationToFollowers = function(uid, tid, pid) {
|
User.sendPostNotificationToFollowers = function(uid, tid, pid) {
|
||||||
User.getUserField(uid, 'username', function(err, username) {
|
User.getUserField(uid, 'username', function(err, username) {
|
||||||
db.getSetMembers('followers:' + uid, function(err, followers) {
|
db.getSetMembers('followers:' + uid, function(err, followers) {
|
||||||
topics.getTopicField(tid, 'slug', function(err, slug) {
|
if (followers && followers.length) {
|
||||||
var message = '<strong>' + username + '</strong> made a new post';
|
topics.getTopicField(tid, 'slug', function(err, slug) {
|
||||||
|
var message = '<strong>' + username + '</strong> made a new post';
|
||||||
|
|
||||||
notifications.create(message, nconf.get('relative_path') + '/topic/' + slug + '#' + pid, 'topic:' + tid, function(nid) {
|
notifications.create({
|
||||||
notifications.push(nid, followers);
|
text: message,
|
||||||
|
path: nconf.get('relative_path') + '/topic/' + slug + '#' + pid,
|
||||||
|
uniqueId: 'topic:' + tid
|
||||||
|
}, function(nid) {
|
||||||
|
notifications.push(nid, followers);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user