Notify new room on initial sync data as well

pull/8144/head
Diego Sampaio 8 years ago
parent 096672ed85
commit dc0aa06651
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 27
      client/notifications/notification.js
  2. 8
      packages/rocketchat-lib/client/lib/cachedCollection.js

@ -1,9 +1,21 @@
/* globals KonchatNotification, fireGlobalEvent, readMessage */
/* globals KonchatNotification, fireGlobalEvent, readMessage, CachedChatSubscription */
// Show notifications and play a sound for new messages.
// We trust the server to only send notifications for interesting messages, e.g. direct messages or
// group messages in which the user is mentioned.
function notifyNewRoom(sub) {
// Do not play new room sound if user is busy
if (Session.equals(`user_${ Meteor.userId() }_status`, 'busy')) {
return;
}
if (!(FlowRouter.getParam('name') && FlowRouter.getParam('name') === sub.name) && !sub.ls && sub.alert === true) {
return KonchatNotification.newRoom(sub.rid);
}
}
Meteor.startup(function() {
Tracker.autorun(function() {
if (Meteor.userId()) {
@ -56,15 +68,14 @@ Meteor.startup(function() {
}
});
RocketChat.Notifications.onUser('subscriptions-changed', function(action, sub) {
// Do not play new room sound if user is busy
if (Session.equals(`user_${ Meteor.userId() }_status`, 'busy')) {
return;
CachedChatSubscription.onSyncData = function(action, sub) {
if (action === 'changed') {
notifyNewRoom(sub);
}
};
if (!(FlowRouter.getParam('name') && FlowRouter.getParam('name') === sub.name) && !sub.ls && sub.alert === true) {
return KonchatNotification.newRoom(sub.rid);
}
RocketChat.Notifications.onUser('subscriptions-changed', (action, sub) => {
notifyNewRoom(sub);
});
}
});

@ -99,7 +99,8 @@ class CachedCollection {
useCache = true,
debug = false,
version = 6,
maxCacheTime = 60*60*24*30
maxCacheTime = 60*60*24*30,
onSyncData = (/* action, record */) => {}
}) {
this.collection = collection || new Mongo.Collection(null);
@ -116,6 +117,7 @@ class CachedCollection {
this.userRelated = userRelated;
this.updatedAt = new Date(0);
this.maxCacheTime = maxCacheTime;
this.onSyncData = onSyncData;
RocketChat.CachedCollectionManager.register(this);
@ -268,12 +270,16 @@ class CachedCollection {
if (record._deletedAt) {
this.collection.remove({ _id: record._id });
this.onSyncData('removed', record);
if (record._deletedAt && record._deletedAt > this.updatedAt) {
this.updatedAt = record._deletedAt;
}
} else {
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
this.onSyncData('changed', record);
if (record._updatedAt && record._updatedAt > this.updatedAt) {
this.updatedAt = record._updatedAt;
}

Loading…
Cancel
Save