Skip to content

Commit

Permalink
feat: option in ACP to configure notification/email delay for chats
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobunny committed Sep 28, 2020
1 parent aacf8f2 commit 5b427a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions public/language/en-GB/admin/settings/chat.json
Expand Up @@ -6,6 +6,7 @@
"max-length": "Maximum length of chat messages",
"max-room-size": "Maximum number of users in chat rooms",
"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-delete-after": "Number of seconds a chat message will remain deletable. (0 disabled)"
}
5 changes: 2 additions & 3 deletions src/messaging/notifications.js
Expand Up @@ -4,12 +4,11 @@ var user = require('../user');
var notifications = require('../notifications');
var sockets = require('../socket.io');
var plugins = require('../plugins');
var meta = require('../meta');

module.exports = function (Messaging) {
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) => {
let uids = await Messaging.getUidsInRoom(roomId, 0, -1);
uids = await user.blocks.filterUids(fromUid, uids);
Expand Down Expand Up @@ -48,7 +47,7 @@ module.exports = function (Messaging) {

queueObj.timeout = setTimeout(function () {
sendNotifications(fromUid, uids, roomId, queueObj.message);
}, Messaging.notificationSendDelay);
}, (parseFloat(meta.config.notificationSendDelay) || 60) * 1000);
};

async function sendNotifications(fromuid, uids, roomId, messageObj) {
Expand Down
5 changes: 5 additions & 0 deletions src/views/admin/settings/chat.tpl
Expand Up @@ -48,6 +48,11 @@
<label>[[admin/settings/chat:delay]]</label>
<input type="text" class="form-control" value="200" data-field="chatMessageDelay">
</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>

Expand Down
4 changes: 2 additions & 2 deletions test/messaging.js
Expand Up @@ -361,7 +361,7 @@ describe('Messaging Library', function () {
it('should return invalid-data error', function (done) {
socketModules.chats.getRaw({ uid: fooUid }, null, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
socketModules.chats.getRaw({ uid: fooUid }, { }, function (err) {
socketModules.chats.getRaw({ uid: fooUid }, {}, function (err) {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('Messaging Library', function () {


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) {
assert.ifError(err);
Expand Down

0 comments on commit 5b427a0

Please sign in to comment.