Skip to content

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

UX: Show chat and message buttons on your own profile (#27600)

Jan Cernika07ddf4ec02e
diff --git a/app/serializers/user_card_serializer.rb b/app/serializers/user_card_serializer.rb
index b7c322d3c91..8720a35bc77 100644
--- a/app/serializers/user_card_serializer.rb
+++ b/app/serializers/user_card_serializer.rb
@@ -147,7 +147,7 @@ class UserCardSerializer < BasicUserSerializer
end
def can_send_private_message_to_user
- scope.can_send_private_message?(object) && scope.current_user != object
+ scope.can_send_private_message?(object) || scope.current_user == object
end
def include_suspend_reason?
diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb
index 84fddefd06f..797ea11269a 100644
--- a/plugins/chat/plugin.rb
+++ b/plugins/chat/plugin.rb
@@ -133,7 +133,7 @@ after_initialize do
add_to_serializer(:user_card, :can_chat_user) do
return false if !SiteSetting.chat_enabled
- return false if scope.user.blank? || scope.user.id == object.id
+ return false if scope.user.blank?
return false if !scope.user.user_option.chat_enabled || !object.user_option.chat_enabled
scope.can_direct_message? && Guardian.new(object).can_chat?
@@ -141,7 +141,7 @@ after_initialize do
add_to_serializer(:hidden_profile, :can_chat_user) do
return false if !SiteSetting.chat_enabled
- return false if scope.user.blank? || scope.user.id == object.id
+ return false if scope.user.blank?
return false if !scope.user.user_option.chat_enabled || !object.user_option.chat_enabled
scope.can_direct_message? && Guardian.new(object).can_chat?
diff --git a/plugins/chat/spec/requests/core_ext/users_controller_spec.rb b/plugins/chat/spec/requests/core_ext/users_controller_spec.rb
index 274134f3d2b..470f06104c0 100644
--- a/plugins/chat/spec/requests/core_ext/users_controller_spec.rb
+++ b/plugins/chat/spec/requests/core_ext/users_controller_spec.rb
@@ -57,12 +57,36 @@ describe UsersController do
describe "#show_card" do
fab!(:user) { Fabricate(:user) }
fab!(:another_user) { Fabricate(:user) }
+
+ before do
+ SiteSetting.chat_enabled = true
+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
+ SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:everyone]
+ end
+
+ context "when the card belongs to the current user" do
+ before { sign_in(user) }
+
+ it "returns that the user can message themselves" do
+ user.user_option.update!(hide_profile_and_presence: false)
+ user.user_option.update!(chat_enabled: true)
+ get "/u/#{user.username}/card.json"
+ expect(response).to be_successful
+ expect(response.parsed_body["user"]["can_chat_user"]).to eq(true)
+ end
+
+ it "returns that the user can message themselves when the profile is hidden" do
+ user.user_option.update!(hide_profile_and_presence: true)
+ user.user_option.update!(chat_enabled: true)
+ get "/u/#{user.username}/card.json"
+ expect(response).to be_successful
+ expect(response.parsed_body["user"]["can_chat_user"]).to eq(true)
+ end
+ end
+
context "when hidden users" do
before do
sign_in(another_user)
- SiteSetting.chat_enabled = true
- SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
- SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:everyone]
user.user_option.update!(hide_profile_and_presence: true)
end
diff --git a/spec/serializers/user_card_serializer_spec.rb b/spec/serializers/user_card_serializer_spec.rb
index afd0691bdd7..ea2573e32d1 100644
--- a/spec/serializers/user_card_serializer_spec.rb
+++ b/spec/serializers/user_card_serializer_spec.rb
@@ -65,6 +65,10 @@ RSpec.describe UserCardSerializer do
it "serializes pending_posts_count" do
expect(json[:pending_posts_count]).to eq 0
end
+
+ it "can_send_private_message_to_user is true" do
+ expect(json[:can_send_private_message_to_user]).to eq true
+ end
end
end