Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Avoid unnecessary calls to Meteor.user() on client #11212

Merged
merged 7 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/notifications/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Meteor.startup(function() {
// This logic is duplicated in /client/startup/unread.coffee.
const hasFocus = readMessage.isEnable();
const messageIsInOpenedRoom = openedRoomId === notification.payload.rid;
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.userId(), 'muteFocusedConversations');

fireGlobalEvent('notification', {
notification,
Expand Down Expand Up @@ -60,7 +60,7 @@ Meteor.startup(function() {
// This logic is duplicated in /client/startup/unread.coffee.
const hasFocus = readMessage.isEnable();
const messageIsInOpenedRoom = openedRoomId === notification.payload.rid;
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.userId(), 'muteFocusedConversations');

if (RocketChat.Layout.isEmbedded()) {
if (!hasFocus && messageIsInOpenedRoom) {
Expand Down
2 changes: 1 addition & 1 deletion client/startup/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Meteor.startup(function() {
// Increment the total unread count.
unreadCount += subscription.unread;
if (subscription.alert === true && subscription.unreadAlert !== 'nothing') {
const userUnreadAlert = RocketChat.getUserPreference(Meteor.user(), 'unreadAlert');
const userUnreadAlert = RocketChat.getUserPreference(Meteor.userId(), 'unreadAlert');
if (subscription.unreadAlert === 'all' || userUnreadAlert !== false) {
unreadAlert = '•';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-emoji-emojione/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ for (const key in emojione.emojioneList) {
Meteor.startup(function() {
Tracker.autorun(function() {
if (isSetNotNull(() => RocketChat.emoji.packages.emojione)) {
if (isSetNotNull(() => RocketChat.getUserPreference(Meteor.user(), 'convertAsciiEmoji'))) {
RocketChat.emoji.packages.emojione.ascii = RocketChat.getUserPreference(Meteor.user(), 'convertAsciiEmoji');
if (isSetNotNull(() => RocketChat.getUserPreference(Meteor.userId(), 'convertAsciiEmoji'))) {
RocketChat.emoji.packages.emojione.ascii = RocketChat.getUserPreference(Meteor.userId(), 'convertAsciiEmoji');
} else {
RocketChat.emoji.packages.emojione.ascii = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-emoji/client/emojiButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Template.messageBox.events({
event.stopPropagation();
event.preventDefault();

if (!RocketChat.getUserPreference(Meteor.user(), 'useEmojis')) {
if (!RocketChat.getUserPreference(Meteor.userId(), 'useEmojis')) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-emoji/client/emojiParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import s from 'underscore.string';
* @param {Object} message - The message object
*/
RocketChat.callbacks.add('renderMessage', (message) => {
if (isSetNotNull(() => RocketChat.getUserPreference(Meteor.user(), 'useEmojis')) &&
!RocketChat.getUserPreference(Meteor.user(), 'useEmojis')) {
if (isSetNotNull(() => RocketChat.getUserPreference(Meteor.userId(), 'useEmojis')) &&
!RocketChat.getUserPreference(Meteor.userId(), 'useEmojis')) {
return message;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-highlight-words/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function HighlightWordsClient(message) {
}
}

const to_highlight = RocketChat.getUserPreference(Meteor.user(), 'highlights');
const to_highlight = RocketChat.getUserPreference(Meteor.userId(), 'highlights');
if (Array.isArray(to_highlight)) {
to_highlight.forEach((highlight) => {
if (!s.isBlank(highlight)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ Template.messageAttachment.helpers({
if (this.collapsed != null) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
time() {
Expand Down
3 changes: 1 addition & 2 deletions packages/rocketchat-oembed/client/oembedAudioWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Template.oembedAudioWidget.helpers({
if (this.collapsed) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
});
3 changes: 1 addition & 2 deletions packages/rocketchat-oembed/client/oembedFrameWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Template.oembedFrameWidget.helpers({
if (this.collapsed) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
});
9 changes: 3 additions & 6 deletions packages/rocketchat-oembed/client/oembedImageWidget.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Template.oembedImageWidget.helpers({
loadImage() {
const user = Meteor.user();

if (RocketChat.getUserPreference(user, 'autoImageLoad') === false && this.downloadImages == null) {
if (RocketChat.getUserPreference(Meteor.userId(), 'autoImageLoad') === false && this.downloadImages == null) {
return false;
}
if (Meteor.Device.isPhone() && RocketChat.getUserPreference(user, 'saveMobileBandwidth') && this.downloadImages == null) {
if (Meteor.Device.isPhone() && RocketChat.getUserPreference(Meteor.userId(), 'saveMobileBandwidth') && this.downloadImages == null) {
return false;
}
return true;
Expand All @@ -14,8 +12,7 @@ Template.oembedImageWidget.helpers({
if (this.collapsed != null) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
});
3 changes: 1 addition & 2 deletions packages/rocketchat-oembed/client/oembedUrlWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ Template.oembedUrlWidget.helpers({
if (this.collapsed != null) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},
});
3 changes: 1 addition & 2 deletions packages/rocketchat-oembed/client/oembedVideoWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Template.oembedVideoWidget.helpers({
if (this.collapsed) {
return this.collapsed;
} else {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'collapseMediaByDefault') === true;
return RocketChat.getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ Template.pushNotificationsFlexTab.helpers({
}
},
defaultAudioNotification() {
let preference = RocketChat.getUserPreference(Meteor.user(), 'audioNotifications');
let preference = RocketChat.getUserPreference(Meteor.userId(), 'audioNotifications');
if (preference === 'default') {
preference = RocketChat.settings.get('Accounts_Default_User_Preferences_audioNotifications');
}
return notificationLabels[preference];
},
defaultDesktopNotification() {
let preference = RocketChat.getUserPreference(Meteor.user(), 'desktopNotifications');
let preference = RocketChat.getUserPreference(Meteor.userId(), 'desktopNotifications');
if (preference === 'default') {
preference = RocketChat.settings.get('Accounts_Default_User_Preferences_desktopNotifications');
}
return notificationLabels[preference];
},
defaultMobileNotification() {
let preference = RocketChat.getUserPreference(Meteor.user(), 'mobileNotifications');
let preference = RocketChat.getUserPreference(Meteor.userId(), 'mobileNotifications');
if (preference === 'default') {
preference = RocketChat.settings.get('Accounts_Default_User_Preferences_mobileNotifications');
}
Expand Down Expand Up @@ -190,7 +190,7 @@ Template.pushNotificationsFlexTab.events({

'click [data-play]'(e) {
e.preventDefault();
const user = Meteor.user();
const user = Meteor.userId();

let value = Template.instance().form.audioNotificationValue.get();
if (value === '0') {
Expand Down Expand Up @@ -340,7 +340,7 @@ Template.pushNotificationsPopover.helpers({
return Template.instance().data.options;
},
defaultDesktopNotification() {
let preference = RocketChat.getUserPreference(Meteor.user(), 'desktopNotifications');
let preference = RocketChat.getUserPreference(Meteor.userId(), 'desktopNotifications');
if (preference === 'default') {
preference = RocketChat.settings.get('Accounts_Default_User_Preferences_desktopNotifications');
}
Expand Down
23 changes: 11 additions & 12 deletions packages/rocketchat-ui-account/client/accountPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ function checkedSelected(property, value, defaultValue = undefined) {
if (defaultValue && defaultValue.hash) {
defaultValue = undefined;
}
return RocketChat.getUserPreference(Meteor.user(), property, defaultValue) === value;
return RocketChat.getUserPreference(Meteor.userId(), property, defaultValue) === value;
}

Template.accountPreferences.helpers({
audioAssets() {
return (RocketChat.CustomSounds && RocketChat.CustomSounds.getList && RocketChat.CustomSounds.getList()) || [];
},
newMessageNotification() {
return RocketChat.getUserPreference(Meteor.user(), 'newMessageNotification');
return RocketChat.getUserPreference(Meteor.userId(), 'newMessageNotification');
},
newRoomNotification() {
return RocketChat.getUserPreference(Meteor.user(), 'newRoomNotification');
return RocketChat.getUserPreference(Meteor.userId(), 'newRoomNotification');
},
muteFocusedConversations() {
return RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');
return RocketChat.getUserPreference(Meteor.userId(), 'muteFocusedConversations');
},
languages() {
const languages = TAPi18n.getLanguages();
Expand Down Expand Up @@ -60,7 +60,7 @@ Template.accountPreferences.helpers({
return checkedSelected(property, value, defaultValue);
},
highlights() {
const userHighlights = RocketChat.getUserPreference(Meteor.user(), 'highlights');
const userHighlights = RocketChat.getUserPreference(Meteor.userId(), 'highlights');
return userHighlights ? userHighlights.join(',\n') : undefined;
},
desktopNotificationEnabled() {
Expand All @@ -70,14 +70,14 @@ Template.accountPreferences.helpers({
return KonchatNotification.notificationStatus.get() === 'denied' || (window.Notification && Notification.permission === 'denied');
},
desktopNotificationDuration() {
const userPref = RocketChat.getUserPreference(Meteor.user(), 'desktopNotificationDuration', 'undefined');
const userPref = RocketChat.getUserPreference(Meteor.userId(), 'desktopNotificationDuration', 'undefined');
return userPref !== 'undefined' ? userPref : undefined;
},
defaultDesktopNotificationDuration() {
return RocketChat.settings.get('Accounts_Default_User_Preferences_desktopNotificationDuration');
},
idleTimeLimit() {
return RocketChat.getUserPreference(Meteor.user(), 'idleTimeLimit');
return RocketChat.getUserPreference(Meteor.userId(), 'idleTimeLimit');
},
defaultIdleTimeLimit() {
return RocketChat.settings.get('Accounts_Default_User_Preferences_idleTimeLimit');
Expand All @@ -98,15 +98,14 @@ Template.accountPreferences.helpers({
return RocketChat.settings.get('UserData_EnableDownload') !== false;
},
notificationsSoundVolume() {
return RocketChat.getUserPreference(Meteor.user(), 'notificationsSoundVolume');
return RocketChat.getUserPreference(Meteor.userId(), 'notificationsSoundVolume');
},
dontAskAgainList() {
return RocketChat.getUserPreference(Meteor.user(), 'dontAskAgainList');
return RocketChat.getUserPreference(Meteor.userId(), 'dontAskAgainList');
},
});

Template.accountPreferences.onCreated(function() {
const user = Meteor.user();
const settingsTemplate = this.parentTemplate(3);

if (settingsTemplate.child == null) {
Expand All @@ -115,7 +114,7 @@ Template.accountPreferences.onCreated(function() {

settingsTemplate.child.push(this);

this.useEmojis = new ReactiveVar(RocketChat.getUserPreference(user, 'useEmojis'));
this.useEmojis = new ReactiveVar(RocketChat.getUserPreference(Meteor.userId(), 'useEmojis'));

let instance = this;

Expand Down Expand Up @@ -172,7 +171,7 @@ Template.accountPreferences.onCreated(function() {
}

// if highlights changed we need page reload
const highlights = RocketChat.getUserPreference(Meteor.user(), 'highlights');
const highlights = RocketChat.getUserPreference(Meteor.userId(), 'highlights');
if (highlights && highlights.join('\n') !== data.highlights.join('\n')) {
reload = true;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/rocketchat-ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ Template.message.helpers({
}
},
roleTags() {
const user = Meteor.user();
if (!RocketChat.settings.get('UI_DisplayRoles') || RocketChat.getUserPreference(user, 'hideRoles')) {
if (!RocketChat.settings.get('UI_DisplayRoles') || RocketChat.getUserPreference(Meteor.userId(), 'hideRoles')) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-message/client/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Template.messageBox.helpers({
return RocketChat.Layout.isEmbedded();
},
isEmojiEnable() {
return RocketChat.getUserPreference(Meteor.user(), 'useEmojis');
return RocketChat.getUserPreference(Meteor.userId(), 'useEmojis');
},
dataReply() {
return Template.instance().dataReply.get();
Expand Down
11 changes: 10 additions & 1 deletion packages/rocketchat-ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ Template.roomList.helpers({
if (this.anonymous) {
return RocketChat.models.Rooms.find({ t: 'c' }, { sort: { name: 1 } });
}
const user = Meteor.userId();

const user = RocketChat.models.Users.findOne(Meteor.userId(), {
tassoevan marked this conversation as resolved.
Show resolved Hide resolved
fields: {
'settings.preferences.sidebarSortby': 1,
'settings.preferences.sidebarShowFavorites': 1,
'settings.preferences.sidebarShowUnread': 1,
'services.tokenpass': 1,
},
});

const sortBy = RocketChat.getUserPreference(user, 'sidebarSortby') || 'alphabetical';
const query = {
open: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-sidenav/client/sideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Template.sideNav.helpers({
},

sidebarHideAvatar() {
return RocketChat.getUserPreference(Meteor.user(), 'sidebarHideAvatar');
return RocketChat.getUserPreference(Meteor.userId(), 'sidebarHideAvatar');
},
});

Expand Down
10 changes: 5 additions & 5 deletions packages/rocketchat-ui-sidenav/client/sortlist.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* globals popover */

const checked = function(prop, field) {
const user = Meteor.userId();
const userId = Meteor.userId();
if (prop === 'sidebarShowFavorites') {
return RocketChat.getUserPreference(user, 'sidebarShowFavorites');
return RocketChat.getUserPreference(userId, 'sidebarShowFavorites');
}
if (prop === 'sidebarGroupByType') {
return RocketChat.getUserPreference(user, 'sidebarGroupByType');
return RocketChat.getUserPreference(userId, 'sidebarGroupByType');
}
if (prop === 'sidebarShowUnread') {
return RocketChat.getUserPreference(user, 'sidebarShowUnread');
return RocketChat.getUserPreference(userId, 'sidebarShowUnread');
}
if (prop === 'sidebarSortby') {
return (RocketChat.getUserPreference(user, 'sidebarSortby') || 'alphabetical') === field;
return (RocketChat.getUserPreference(userId, 'sidebarSortby') || 'alphabetical') === field;
}
};

Expand Down
9 changes: 4 additions & 5 deletions packages/rocketchat-ui/client/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const KonchatNotification = {
canReply: true,
});

const user = Meteor.user();
const notificationDuration = notification.duration - 0 || RocketChat.getUserPreference(user, 'desktopNotificationDuration') - 0;
const notificationDuration = notification.duration - 0 || RocketChat.getUserPreference(Meteor.userId(), 'desktopNotificationDuration') - 0;
if (notificationDuration > 0) {
setTimeout((() => n.close()), notificationDuration * 1000);
}
Expand Down Expand Up @@ -89,9 +88,9 @@ const KonchatNotification = {

newMessage(rid) {
if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) {
const user = Meteor.user();
const newMessageNotification = RocketChat.getUserPreference(user, 'newMessageNotification');
const audioVolume = RocketChat.getUserPreference(user, 'notificationsSoundVolume');
const userId = Meteor.userId();
const newMessageNotification = RocketChat.getUserPreference(userId, 'newMessageNotification');
const audioVolume = RocketChat.getUserPreference(userId, 'notificationsSoundVolume');

const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } });

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/views/app/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Template.rc_modal.events({
label: dontAskAgain.label,
};

let dontAskAgainList = RocketChat.getUserPreference(Meteor.user(), 'dontAskAgainList');
let dontAskAgainList = RocketChat.getUserPreference(Meteor.userId(), 'dontAskAgainList');
if (dontAskAgainList) {
dontAskAgainList.push(dontAskAgainObject);
} else {
Expand Down
Loading