Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into scroll

pull/8190/head
Guilherme Gazzo 9 years ago
commit b85bf71e68
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
  1. 24
      client/notifications/notification.js
  2. 10
      packages/rocketchat-lib/client/lib/cachedCollection.js
  3. 2
      packages/rocketchat-ui-message/client/messageBox.js
  4. 2
      packages/rocketchat-ui-sidenav/client/accountBox.js
  5. 12
      packages/rocketchat-ui-sidenav/client/chatRoomItem.js
  6. 2
      packages/rocketchat-ui-sidenav/client/sideNav.html
  7. 19
      packages/rocketchat-ui-sidenav/client/sideNav.js
  8. 18
      packages/rocketchat-ui/client/lib/chatMessages.js
  9. 49
      packages/rocketchat-ui/client/lib/notification.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()) {
@ -55,6 +67,16 @@ Meteor.startup(function() {
KonchatNotification.newMessage(notification.payload.rid);
}
});
CachedChatSubscription.onSyncData = function(action, sub) {
if (action !== 'removed') {
notifyNewRoom(sub);
}
};
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);
@ -206,6 +208,8 @@ class CachedCollection {
delete record.$loki;
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
this.onSyncData('changed', record);
if (record._updatedAt && record._updatedAt > this.updatedAt) {
this.updatedAt = record._updatedAt;
}
@ -268,12 +272,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;
}

@ -469,6 +469,8 @@ Template.messageBox.onRendered(function() {
}).on('autogrow', () => {
this.data && this.data.onResize && this.data.onResize();
}).focus()[0];
chatMessages[RocketChat.openedRoom].restoreText(RocketChat.openedRoom);
});
Template.messageBox.onCreated(function() {

@ -29,7 +29,7 @@ Template.accountBox.helpers({
},
isAnonymous() {
if (Meteor.user() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
if (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
return 'disabled';
}
}

@ -1,5 +1,3 @@
/* globals KonchatNotification */
Template.chatRoomItem.helpers({
roomData() {
let name = this.name;
@ -25,10 +23,6 @@ Template.chatRoomItem.helpers({
if (!this.hideUnreadStatus && (FlowRouter.getParam('_id') !== this.rid || !document.hasFocus()) && this.alert) {
alertClass = 'sidebar-item__link--active';
}
// Sound notification
if (!(FlowRouter.getParam('name') === this.name) && !this.ls && this.alert === true) {
KonchatNotification.newRoom(this.rid);
}
const icon = RocketChat.roomTypes.getIcon(this.t);
const avatar = !icon;
@ -47,9 +41,3 @@ Template.chatRoomItem.helpers({
};
}
});
Template.chatRoomItem.onRendered = function() {
if (!(FlowRouter.getParam('name') && (FlowRouter.getParam('name') === this.name)) && !this.ls && (this.alert === true)) {
return KonchatNotification.newRoom(this.rid);
}
};

@ -5,7 +5,7 @@
{{> toolbar}}
</header>
{{#if currentUser}}
{{#if loggedInUser}}
<div class="unread-rooms background-primary-action-color color-primary-action-contrast top-unread-rooms hidden">
{{_ "More_unreads"}} <i class="icon-up-big"></i>
</div>

@ -1,14 +1,6 @@
/* globals menu*/
Template.sideNav.helpers({
hasUnread() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.roomsListExhibitionMode === 'unread';
},
sortByActivity() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.roomsListExhibitionMode === 'activity';
},
flexTemplate() {
return SideNav.getFlex().template;
},
@ -23,6 +15,10 @@ Template.sideNav.helpers({
roomType() {
return RocketChat.roomTypes.getTypes();
},
loggedInUser() {
return !!Meteor.userId();
}
});
@ -69,7 +65,12 @@ Template.sideNav.onCreated(function() {
this.mergedChannels = new ReactiveVar(false);
this.autorun(() => {
const user = Meteor.user();
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.roomsListExhibitionMode': 1,
'settings.preferences.mergeChannels': 1
}
});
let userPref = null;
if (user && user.settings && user.settings.preferences) {
userPref = user.settings.preferences.roomsListExhibitionMode === 'category' && user.settings.preferences.mergeChannels;

@ -379,6 +379,13 @@ this.ChatMessages = class ChatMessages {
}
}
restoreText(rid) {
const text = localStorage.getItem(`messagebox_${ rid }`);
if (typeof text === 'string') {
this.input.value = text;
}
}
keyup(rid, event) {
let i;
const input = event.currentTarget;
@ -407,6 +414,8 @@ this.ChatMessages = class ChatMessages {
this.startTyping(rid, input);
}
localStorage.setItem(`messagebox_${ rid }`, input.value);
return this.hasValue.set(input.value !== '');
}
@ -520,3 +529,12 @@ this.ChatMessages = class ChatMessages {
return !this.hasValue.get();
}
};
RocketChat.callbacks.add('afterLogoutCleanUp', () => {
Object.keys(localStorage).forEach((item) => {
if (item.indexOf('messagebox_') === 0) {
localStorage.removeItem(item);
}
});
}, RocketChat.callbacks.priority.MEDIUM, 'chatMessages-after-logout-cleanup');

@ -124,31 +124,38 @@ const KonchatNotification = {
}
};
Tracker.autorun(function() {
const user = Meteor.user();
const newRoomNotification = user && user.settings && user.settings.preferences && user.settings.preferences.newRoomNotification || 'door';
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;
Meteor.startup(() => {
Tracker.autorun(function() {
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.newRoomNotification': 1,
'settings.preferences.notificationsSoundVolume': 1
}
});
const newRoomNotification = user && user.settings && user.settings.preferences && user.settings.preferences.newRoomNotification || 'door';
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;
if ((Session.get('newRoomSound') || []).length > 0) {
Tracker.nonreactive(function() {
if (!Session.equals(`user_${ Meteor.userId() }_status`, 'busy') && newRoomNotification !== 'none') {
const [audio] = $(`audio#${ newRoomNotification }`);
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));
return audio.play();
if ((Session.get('newRoomSound') || []).length > 0) {
Meteor.defer(function() {
if (newRoomNotification !== 'none') {
const [audio] = $(`audio#${ newRoomNotification }`);
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));
return audio.play();
}
}
});
} else {
const [room] = $(`audio#${ newRoomNotification }`);
if (!room) {
return;
}
if (room.pause) {
room.pause();
return room.currentTime = 0;
}
});
} else {
const [room] = $(`audio#${ newRoomNotification }`);
if (!room) {
return;
}
if (room.pause) {
room.pause();
return room.currentTime = 0;
}
}
});
});
export { KonchatNotification };
this.KonchatNotification = KonchatNotification;

Loading…
Cancel
Save