Skip to content

Commit

Permalink
Merge pull request #11074 from RocketChat/avoid-presence
Browse files Browse the repository at this point in the history
[FIX] avoid send presence without login
  • Loading branch information
engelgabriel authored Jun 10, 2018
2 parents 7bd51dc + a3e5878 commit 8d14522
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ konecty:change-case@2.3.0
konecty:delayed-task@1.0.0
konecty:mongo-counter@0.0.5_3
konecty:multiple-instances-status@1.1.0
konecty:user-presence@2.0.1
konecty:user-presence@2.1.0
launch-screen@1.1.1
less@2.7.12
livedata@1.0.18
Expand Down
73 changes: 34 additions & 39 deletions client/startup/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,7 @@ if (window.DISABLE_ANIMATION) {
Meteor.startup(function() {
TimeSync.loggingEnabled = false;

const userHasPreferences = (user) => {
if (!user) {
return false;
}

const userHasSettings = user.hasOwnProperty('settings');

if (!userHasSettings) {
return false;
}

return user.settings.hasOwnProperty('preferences');
};

Meteor.subscribe('activeUsers');

Session.setDefault('AvatarRandom', 0);

Expand Down Expand Up @@ -91,41 +77,50 @@ Meteor.startup(function() {
}
};

const defaultIdleTimeLimit = 300;

Meteor.subscribe('userData', function() {
const user = Meteor.user();
const userLanguage = user && user.language ? user.language : window.defaultUserLanguage();
Meteor.subscribe('userData');

if (!userHasPreferences(user)) {
UserPresence.awayTime = defaultIdleTimeLimit * 1000;
UserPresence.start();
} else {
UserPresence.awayTime = (user.settings.preferences.idleTimeLimit || defaultIdleTimeLimit) * 1000;
Tracker.autorun(function(computation) {
if (!Meteor.userId() && !RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
return;
}
Meteor.subscribe('activeUsers');
computation.stop();
});

if (user.settings.preferences.hasOwnProperty('enableAutoAway')) {
user.settings.preferences.enableAutoAway && UserPresence.start();
} else {
UserPresence.start();
let status = undefined;
Tracker.autorun(function() {
if (!Meteor.userId()) {
return;
}
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
status: 1,
language: 1,
'settings.idleTimeLimit': 1,
'settings.enableAutoAway': 1
}
});

if (!user) {
return;
}

const userLanguage = user.language ? user.language : window.defaultUserLanguage();
if (localStorage.getItem('userLanguage') !== userLanguage) {
localStorage.setItem('userLanguage', userLanguage);
window.setLanguage(userLanguage);
}

window.setLanguage(userLanguage);
if (RocketChat.getUserPreference(user, 'enableAutoAway')) {
const idleTimeLimit = RocketChat.getUserPreference(user, 'idleTimeLimit') || 300;
UserPresence.awayTime = idleTimeLimit * 1000;
}

let status = undefined;
Tracker.autorun(function() {
if (!Meteor.userId()) {
return;
}
UserPresence.start();

if (user && user.status !== status) {
status = user.status;
fireGlobalEvent('status-changed', status);
}
});
if (user.status !== status) {
status = user.status;
fireGlobalEvent('status-changed', status);
}
});
});

0 comments on commit 8d14522

Please sign in to comment.