Upvote notification frequency selection (#6087)

Closes #5963

- Notify on every upvote
- Notify on every tenth upvote
- Notify logarithmically (on 10, 100, 1000...)
- Disable upvote notifications
v1.18.x
Peter Jaszkowiak 7 years ago committed by Julian Lam
parent 3fd25257e0
commit 74ceb78800

@ -110,6 +110,11 @@
"outgoing-message-sound": "Outgoing message sound",
"notification-sound": "Notification sound",
"no-sound": "No sound",
"upvote-notif-freq": "Upvote Notification Frequency",
"upvote-notif-freq.all": "All Upvotes",
"upvote-notif-freq.everyTen": "Every Ten Upvotes",
"upvote-notif-freq.logarithmic": "On 10, 100, 1000...",
"upvote-notif-freq.disabled": "Disabled",
"browsing": "Browsing Settings",
"open_links_in_new_tab": "Open outgoing links in new tab",

@ -135,6 +135,20 @@ settingsController.get = function (req, res, callback) {
language.selected = language.code === userData.settings.userLang;
});
var notifFreqOptions = [
'all',
'everyTen',
'logarithmic',
'disabled',
];
userData.upvoteNotifFreq = notifFreqOptions.map(function (name) {
return {
name: name,
selected: name === userData.notifFreqOptions,
};
});
userData.disableCustomUserSkins = parseInt(meta.config.disableCustomUserSkins, 10) === 1;
userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1;

@ -232,6 +232,7 @@ module.exports = function (Posts) {
user: {
reputation: newreputation,
},
fromuid: uid,
post: postData,
upvote: type === 'upvote' && !unvote,
downvote: type === 'downvote' && !unvote,

@ -13,7 +13,7 @@ var notifications = require('../notifications');
var plugins = require('../plugins');
var utils = require('../utils');
var SocketHelpers = {};
var SocketHelpers = module.exports;
SocketHelpers.notifyOnlineUsers = function (uid, result) {
winston.warn('[deprecated] SocketHelpers.notifyOnlineUsers, consider using socketHelpers.notifyNew(uid, \'newPost\', result);');
@ -171,6 +171,51 @@ SocketHelpers.sendNotificationToTopicOwner = function (tid, fromuid, command, no
});
};
SocketHelpers.upvote = function (data, notification) {
if (!data || !data.post || !data.post.uid || !data.post.votes || !data.post.pid || !data.fromuid) {
return;
}
var votes = data.post.votes;
var touid = data.post.uid;
var fromuid = data.fromuid;
var pid = data.post.pid;
var shouldNotify = {
all: function () {
return votes > 0;
},
everyTen: function () {
return votes > 0 && votes % 10 === 0;
},
logarithmic: function () {
return votes > 1 && Math.log10(votes) % 1 === 0;
},
disabled: function () {
return false;
},
};
async.waterfall([
function (next) {
user.getSettings(touid, next);
},
function (settings, next) {
var should = shouldNotify[settings.upvoteNotifFreq] || shouldNotify.all;
if (should()) {
SocketHelpers.sendNotificationToPostOwner(pid, fromuid, 'upvote', notification);
}
next();
},
], function (err) {
if (err) {
winston.error(err);
}
});
};
SocketHelpers.rescindUpvoteNotification = function (pid, fromuid) {
var uid;
async.waterfall([
@ -199,5 +244,3 @@ SocketHelpers.emitToTopicAndCategory = function (event, data) {
websockets.in('topic_' + data.tid).emit(event, data);
websockets.in('category_' + data.cid).emit(event, data);
};
module.exports = SocketHelpers;

@ -69,7 +69,9 @@ function executeCommand(socket, command, eventName, notification, data, callback
websockets.in(data.room_id).emit('event:' + eventName, result);
}
if (result && notification) {
if (result && command === 'upvote') {
socketHelpers.upvote(result, notification);
} else if (result && notification) {
socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, command, notification);
} else if (result && command === 'unvote') {
socketHelpers.rescindUpvoteNotification(data.pid, socket.uid);

@ -74,8 +74,7 @@ module.exports = function (User) {
settings.categoryTopicSort = getSetting(settings, 'categoryTopicSort', 'newest_to_oldest');
settings.followTopicsOnCreate = parseInt(getSetting(settings, 'followTopicsOnCreate', 1), 10) === 1;
settings.followTopicsOnReply = parseInt(getSetting(settings, 'followTopicsOnReply', 0), 10) === 1;
settings.sendChatNotifications = parseInt(getSetting(settings, 'sendChatNotifications', 0), 10) === 1;
settings.sendPostNotifications = parseInt(getSetting(settings, 'sendPostNotifications', 0), 10) === 1;
settings.upvoteNotifFreq = getSetting(settings, 'upvoteNotifFreq', 'all');
settings.restrictChat = parseInt(getSetting(settings, 'restrictChat', 0), 10) === 1;
settings.topicSearchEnabled = parseInt(getSetting(settings, 'topicSearchEnabled', 0), 10) === 1;
settings.delayImageLoading = parseInt(getSetting(settings, 'delayImageLoading', 1), 10) === 1;
@ -131,6 +130,7 @@ module.exports = function (User) {
notificationSound: data.notificationSound,
incomingChatSound: data.incomingChatSound,
outgoingChatSound: data.outgoingChatSound,
upvoteNotifFreq: data.upvoteNotifFreq,
notificationType_upvote: data.notificationType_upvote,
'notificationType_new-topic': data['notificationType_new-topic'],
'notificationType_new-reply': data['notificationType_new-reply'],

Loading…
Cancel
Save