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.rbindex b7c322d3c91..8720a35bc77 100644--- a/app/serializers/user_card_serializer.rb+++ b/app/serializers/user_card_serializer.rb@@ -147,7 +147,7 @@ class UserCardSerializer < BasicUserSerializerenddef 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 == objectenddef include_suspend_reason?diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rbindex 84fddefd06f..797ea11269a 100644--- a/plugins/chat/plugin.rb+++ b/plugins/chat/plugin.rb@@ -133,7 +133,7 @@ after_initialize doadd_to_serializer(:user_card, :can_chat_user) doreturn 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_enabledscope.can_direct_message? && Guardian.new(object).can_chat?@@ -141,7 +141,7 @@ after_initialize doadd_to_serializer(:hidden_profile, :can_chat_user) doreturn 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_enabledscope.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.rbindex 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 dodescribe "#show_card" dofab!(: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" dobefore dosign_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)enddiff --git a/spec/serializers/user_card_serializer_spec.rb b/spec/serializers/user_card_serializer_spec.rbindex 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 doit "serializes pending_posts_count" doexpect(json[:pending_posts_count]).to eq 0end++ it "can_send_private_message_to_user is true" do+ expect(json[:can_send_private_message_to_user]).to eq true+ endendend