mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
fixed #1904
This commit is contained in:
@@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
var db = require('./database'),
|
var db = require('./database'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
|
winston = require('winston'),
|
||||||
user = require('./user'),
|
user = require('./user'),
|
||||||
plugins = require('./plugins'),
|
plugins = require('./plugins'),
|
||||||
meta = require('./meta');
|
meta = require('./meta'),
|
||||||
|
notifications = require('./notifications'),
|
||||||
|
userNotifications = require('./user/notifications');
|
||||||
|
|
||||||
|
|
||||||
(function(Messaging) {
|
(function(Messaging) {
|
||||||
@@ -33,12 +36,6 @@ var db = require('./database'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: Here I'd check the score of the previous message in this chat's sorted set.
|
|
||||||
but unfortunately, chats are stored as a list. Once nodebb/nodebb#1902 is resolved,
|
|
||||||
I can finish it up here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
db.setObject('message:' + mid, message, function(err) {
|
db.setObject('message:' + mid, message, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -99,6 +96,15 @@ var db = require('./database'),
|
|||||||
|
|
||||||
getMessages(mids, fromuid, touid, isNew, callback);
|
getMessages(mids, fromuid, touid, isNew, callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Mark any chat notifications pertaining to this chat as read
|
||||||
|
notifications.mark_read_by_uniqueid(fromuid, 'chat_' + touid + '_' + fromuid, function(err) {
|
||||||
|
if (err) {
|
||||||
|
winston.error('[messaging] Could not mark notifications related to this chat as read: ' + err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
userNotifications.pushCount(fromuid);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMessages(mids, fromuid, touid, isNew, callback) {
|
function getMessages(mids, fromuid, touid, isNew, callback) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ var async = require('async'),
|
|||||||
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) {
|
||||||
db.getObject('notifications:' + nid, function(err, notification) {
|
db.getObject('notifications:' + nid, function(err, notification) {
|
||||||
notification.read = rank !== null ? true:false;
|
notification.read = rank !== null ? true:false;
|
||||||
|
|
||||||
// Backwards compatibility for old notification schema
|
// Backwards compatibility for old notification schema
|
||||||
// Remove this block when NodeBB v0.6.0 is released.
|
// Remove this block when NodeBB v0.6.0 is released.
|
||||||
if (notification.hasOwnProperty('text')) {
|
if (notification.hasOwnProperty('text')) {
|
||||||
@@ -289,6 +289,27 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// why_are_we_using_underscores_here_?
|
||||||
|
// maybe_camel_case_ALL_THE_THINGS
|
||||||
|
Notifications.mark_read_by_uniqueid = function(uid, uniqueId, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(db.getSortedSetRange, 'uid:' + uid + ':notifications:unread', 0, 10),
|
||||||
|
function(nids, next) {
|
||||||
|
async.filter(nids, function(nid, next) {
|
||||||
|
db.getObjectField('notifications:' + nid, 'uniqueId', function(err, value) {
|
||||||
|
next(uniqueId === value);
|
||||||
|
});
|
||||||
|
}, function(nids) {
|
||||||
|
next(null, nids);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(nids, next) {
|
||||||
|
console.log('matches:', nids);
|
||||||
|
Notifications.mark_read_multiple(nids, uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
Notifications.prune = function(cutoff) {
|
Notifications.prune = function(cutoff) {
|
||||||
var start = process.hrtime();
|
var start = process.hrtime();
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ function sendChatNotification(fromuid, touid, messageObj) {
|
|||||||
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
|
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
|
||||||
bodyLong: messageObj.content,
|
bodyLong: messageObj.content,
|
||||||
path: nconf.get('relative_path') + '/chats/' + utils.slugify(messageObj.fromUser.username),
|
path: nconf.get('relative_path') + '/chats/' + utils.slugify(messageObj.fromUser.username),
|
||||||
uniqueId: 'notification_' + fromuid + '_' + touid,
|
uniqueId: 'chat_' + fromuid + '_' + touid,
|
||||||
from: fromuid
|
from: fromuid
|
||||||
}, function(nid) {
|
}, function(nid) {
|
||||||
notifications.push(nid, [touid]);
|
notifications.push(nid, [touid]);
|
||||||
|
|||||||
Reference in New Issue
Block a user