diff --git a/packages/rocketchat-ui-flextab/client/tabs/membersList.js b/packages/rocketchat-ui-flextab/client/tabs/membersList.js index 8936960fef04e..de254edb32e6c 100644 --- a/packages/rocketchat-ui-flextab/client/tabs/membersList.js +++ b/packages/rocketchat-ui-flextab/client/tabs/membersList.js @@ -26,7 +26,7 @@ Template.membersList.helpers({ const roomUsers = Template.instance().users.get(); const room = ChatRoom.findOne(this.rid); const roomMuted = (room != null ? room.muted : undefined) || []; - const userUtcOffset = Meteor.user().utcOffset; + const userUtcOffset = Meteor.user() && Meteor.user().utcOffset; let totalOnline = 0; let users = roomUsers.map(function(user) { let utcOffset; diff --git a/packages/rocketchat-ui-message/client/message.js b/packages/rocketchat-ui-message/client/message.js index 1be8518e364fc..40def8559037f 100644 --- a/packages/rocketchat-ui-message/client/message.js +++ b/packages/rocketchat-ui-message/client/message.js @@ -13,7 +13,7 @@ Template.message.helpers({ roleTags() { const user = Meteor.user(); // test user -> settings -> preferences -> hideRoles - if (!RocketChat.settings.get('UI_DisplayRoles') || ['settings', 'preferences', 'hideRoles'].reduce((obj, field) => typeof obj !== 'undefined' && obj[field], user)) { + if (!RocketChat.settings.get('UI_DisplayRoles') || (user && ['settings', 'preferences', 'hideRoles'].reduce((obj, field) => typeof obj !== 'undefined' && obj[field], user))) { return []; } @@ -205,7 +205,7 @@ Template.message.helpers({ return true; }, reactions() { - const userUsername = Meteor.user().username; + const userUsername = Meteor.user() && Meteor.user().username; return Object.keys(this.reactions||{}).map(emoji => { const reaction = this.reactions[emoji]; const total = reaction.usernames.length; diff --git a/packages/rocketchat-ui-message/client/messageBox.js b/packages/rocketchat-ui-message/client/messageBox.js index 255f47ed671e2..19a666e66708c 100644 --- a/packages/rocketchat-ui-message/client/messageBox.js +++ b/packages/rocketchat-ui-message/client/messageBox.js @@ -54,7 +54,7 @@ Template.messageBox.helpers({ return RocketChat.settings.get('Message_ShowFormattingTips') && (RocketChat.Markdown || RocketChat.MarkdownCode || katexSyntax()); }, canJoin() { - return RocketChat.roomTypes.verifyShowJoinLink(this._id); + return Meteor.userId() && RocketChat.roomTypes.verifyShowJoinLink(this._id); }, joinCodeRequired() { const code = Session.get(`roomData${ this._id }`); @@ -179,6 +179,13 @@ Template.messageBox.helpers({ }, showSandstorm() { return Meteor.settings['public'].sandstorm && !Meteor.isCordova; + }, + + anonymousRead() { + return (Meteor.userId() == null) && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true; + }, + anonymousWrite() { + return (Meteor.userId() == null) && RocketChat.settings.get('Accounts_AllowAnonymousRead') === true && RocketChat.settings.get('Accounts_AllowAnonymousWrite') === true; } }); @@ -248,6 +255,21 @@ Template.messageBox.events({ } }); }, + + 'click .register'(event) { + event.stopPropagation(); + event.preventDefault(); + return Session.set('forceLogin', true); + }, + 'click .register-anonymous'(event) { + event.stopPropagation(); + event.preventDefault(); + return Meteor.call('registerUser', {}, function(error, loginData) { + if (loginData && loginData.token) { + return Meteor.loginWithToken(loginData.token); + } + }); + }, 'focus .input-message'(event, instance) { KonchatNotification.removeRoomNotification(this._id); chatMessages[this._id].input = instance.find('.input-message'); diff --git a/packages/rocketchat-ui/client/views/app/room.js b/packages/rocketchat-ui/client/views/app/room.js index c066b0c600d89..e3d9fd62c231f 100644 --- a/packages/rocketchat-ui/client/views/app/room.js +++ b/packages/rocketchat-ui/client/views/app/room.js @@ -224,11 +224,16 @@ Template.room.helpers({ return true; } + if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { + return true; + } + if (RocketChat.authz.hasAllPermission('preview-c-room')) { return true; } return (RocketChat.models.Subscriptions.findOne({rid: this._id}) != null); + } }); @@ -405,11 +410,17 @@ Template.room.events({ }, 'click .flex-tab .user-image > button'(e, instance) { + if (!Meteor.userId()) { + return; + } instance.tabBar.open(); return instance.setUserDetail(this.user.username); }, 'click .user-card-message'(e, instance) { + if (!Meteor.userId()) { + return; + } const roomData = Session.get(`roomData${ this._arguments[1].rid }`); if (RocketChat.Layout.isEmbedded()) { @@ -476,6 +487,9 @@ Template.room.events({ }, 'click .mention-link'(e, instance) { + if (!Meteor.userId()) { + return; + } const channel = $(e.currentTarget).data('channel'); if (channel != null) { if (RocketChat.Layout.isEmbedded()) {