Skip to content

A platform for community discussion. Free, open, simple.

FIX: accounts for `hide_profile_and_presence` core user option (#20991)

Joffrey JAFFEUX838fb37019c7
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.js
index 59a182617e8..71176926c35 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat.js
@@ -17,14 +17,17 @@ const CHAT_ONLINE_OPTIONS = {
export default class Chat extends Service {
@service appEvents;
+ @service currentUser;
@service chatNotificationManager;
@service chatSubscriptionsManager;
@service chatStateManager;
@service presence;
@service router;
@service site;
+
@service chatChannelsManager;
@tracked activeChannel = null;
+
cook = null;
presenceChannel = null;
sidebarActive = false;
@@ -114,6 +117,10 @@ export default class Chat extends Service {
return;
}
+ if (this.currentUser.user_option?.hide_profile_and_presence) {
+ return;
+ }
+
if (this.chatStateManager.isActive) {
this.presenceChannel.enter({ activeOptions: CHAT_ONLINE_OPTIONS });
} else {
diff --git a/plugins/chat/spec/system/user_presence.rb b/plugins/chat/spec/system/user_presence.rb
new file mode 100644
index 00000000000..aeebe426157
--- /dev/null
+++ b/plugins/chat/spec/system/user_presence.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+RSpec.describe "User presence", type: :system, js: true do
+ fab!(:channel_1) { Fabricate(:chat_channel) }
+ fab!(:current_user) { Fabricate(:user) }
+
+ let(:channel) { PageObjects::Pages::ChatChannel.new }
+
+ before do
+ chat_system_bootstrap
+ channel_1.add(current_user)
+ end
+
+ it "shows presence indicator" do
+ sign_in(current_user)
+ chat.visit_channel(channel_1)
+ channel.send_message("Am I present?")
+
+ expect(page).to have_selector(".chat-user-avatar.is-online")
+ end
+
+ context "when user hides presence" do
+ it "hides the presence indicator" do
+ current_user.user_option.update!(hide_profile_and_presence: true)
+ sign_in(current_user)
+ chat.visit_channel(channel_1)
+ channel.send_message("Am I present?")
+
+ expect(page).to have_no_selector(".chat-user-avatar.is-online")
+ end
+ end
+end