mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
UX: Show chat and message buttons on your own profile (#27600)
This commit is contained in:
parent
c8e65fa673
commit
a07ddf4ec0
|
@ -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?
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user