feat: option in ACP to configure notification/email delay for chats

v1.18.x
psychobunny 5 years ago
parent aacf8f22f5
commit 5b427a0c3b

@ -6,6 +6,7 @@
"max-length": "Maximum length of chat messages", "max-length": "Maximum length of chat messages",
"max-room-size": "Maximum number of users in chat rooms", "max-room-size": "Maximum number of users in chat rooms",
"delay": "Time between chat messages in milliseconds", "delay": "Time between chat messages in milliseconds",
"notification-delay": "Notification delay for chat messages",
"restrictions.seconds-edit-after": "Number of seconds a chat message will remain editable. (0 disabled)", "restrictions.seconds-edit-after": "Number of seconds a chat message will remain editable. (0 disabled)",
"restrictions.seconds-delete-after": "Number of seconds a chat message will remain deletable. (0 disabled)" "restrictions.seconds-delete-after": "Number of seconds a chat message will remain deletable. (0 disabled)"
} }

@ -4,12 +4,11 @@ var user = require('../user');
var notifications = require('../notifications'); var notifications = require('../notifications');
var sockets = require('../socket.io'); var sockets = require('../socket.io');
var plugins = require('../plugins'); var plugins = require('../plugins');
var meta = require('../meta');
module.exports = function (Messaging) { module.exports = function (Messaging) {
Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
Messaging.notificationSendDelay = 1000 * 60;
Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => { Messaging.notifyUsersInRoom = async (fromUid, roomId, messageObj) => {
let uids = await Messaging.getUidsInRoom(roomId, 0, -1); let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
uids = await user.blocks.filterUids(fromUid, uids); uids = await user.blocks.filterUids(fromUid, uids);
@ -48,7 +47,7 @@ module.exports = function (Messaging) {
queueObj.timeout = setTimeout(function () { queueObj.timeout = setTimeout(function () {
sendNotifications(fromUid, uids, roomId, queueObj.message); sendNotifications(fromUid, uids, roomId, queueObj.message);
}, Messaging.notificationSendDelay); }, (parseFloat(meta.config.notificationSendDelay) || 60) * 1000);
}; };
async function sendNotifications(fromuid, uids, roomId, messageObj) { async function sendNotifications(fromuid, uids, roomId, messageObj) {

@ -48,6 +48,11 @@
<label>[[admin/settings/chat:delay]]</label> <label>[[admin/settings/chat:delay]]</label>
<input type="text" class="form-control" value="200" data-field="chatMessageDelay"> <input type="text" class="form-control" value="200" data-field="chatMessageDelay">
</div> </div>
<div class="form-group">
<label>[[admin/settings/chat:notification-delay]]</label>
<input type="text" class="form-control" value="60" data-field="notificationSendDelay">
</div>
</div> </div>
</div> </div>

@ -394,7 +394,7 @@ describe('Messaging Library', function () {
it('should notify offline users of message', function (done) { it('should notify offline users of message', function (done) {
Messaging.notificationSendDelay = 100; meta.config.notificationSendDelay = 0.1;
db.sortedSetAdd('users:online', Date.now() - ((meta.config.onlineCutoff * 60000) + 50000), herpUid, function (err) { db.sortedSetAdd('users:online', Date.now() - ((meta.config.onlineCutoff * 60000) + 50000), herpUid, function (err) {
assert.ifError(err); assert.ifError(err);

Loading…
Cancel
Save