mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:01:13 +08:00
UX: Show chat and message buttons on your own profile (#27600)
This commit is contained in:
@ -147,7 +147,7 @@ class UserCardSerializer < BasicUserSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def can_send_private_message_to_user
|
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
|
end
|
||||||
|
|
||||||
def include_suspend_reason?
|
def include_suspend_reason?
|
||||||
|
@ -133,7 +133,7 @@ after_initialize do
|
|||||||
|
|
||||||
add_to_serializer(:user_card, :can_chat_user) do
|
add_to_serializer(:user_card, :can_chat_user) do
|
||||||
return false if !SiteSetting.chat_enabled
|
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
|
return false if !scope.user.user_option.chat_enabled || !object.user_option.chat_enabled
|
||||||
|
|
||||||
scope.can_direct_message? && Guardian.new(object).can_chat?
|
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
|
add_to_serializer(:hidden_profile, :can_chat_user) do
|
||||||
return false if !SiteSetting.chat_enabled
|
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
|
return false if !scope.user.user_option.chat_enabled || !object.user_option.chat_enabled
|
||||||
|
|
||||||
scope.can_direct_message? && Guardian.new(object).can_chat?
|
scope.can_direct_message? && Guardian.new(object).can_chat?
|
||||||
|
@ -57,12 +57,36 @@ describe UsersController do
|
|||||||
describe "#show_card" do
|
describe "#show_card" do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
fab!(:another_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
|
context "when hidden users" do
|
||||||
before do
|
before do
|
||||||
sign_in(another_user)
|
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)
|
user.user_option.update!(hide_profile_and_presence: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +65,10 @@ RSpec.describe UserCardSerializer do
|
|||||||
it "serializes pending_posts_count" do
|
it "serializes pending_posts_count" do
|
||||||
expect(json[:pending_posts_count]).to eq 0
|
expect(json[:pending_posts_count]).to eq 0
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user