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

This commit is contained in:
Jan Cernik 2024-06-25 07:52:17 -03:00 committed by GitHub
parent c8e65fa673
commit a07ddf4ec0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 6 deletions

View File

@ -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?

View File

@ -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?

View File

@ -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

View File

@ -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