mirror of
https://github.com/discourse/discourse.git
synced 2025-01-05 02:23:54 +08:00
b3a1199493
Users can hide their public profile and presence information by checking
“Hide my public profile and presence features” on the
`u/{username}/preferences/interface` page. In that case, we also don't
want to return user status from the server.
This work has been started in https://github.com/discourse/discourse/pull/23946.
The current PR fixes all the remaining places in Core.
Note that the actual fix is quite simple – a5802f484d
.
But we had a fair amount of duplication in the code responsible for
the user status serialization, so I had to dry that up first. The refactoring
as well as adding some additional tests is the main part of this PR.
23 lines
536 B
Ruby
23 lines
536 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat
|
|
class DirectMessageSerializer < ApplicationSerializer
|
|
attributes :group, :users
|
|
|
|
def users
|
|
users = object.direct_message_users.map(&:user).map { |u| u || Chat::NullUser.new }
|
|
users = users - [scope.user] if users.count > 1
|
|
|
|
serializer =
|
|
ActiveModel::ArraySerializer.new(
|
|
users,
|
|
each_serializer: ::Chat::ChatableUserSerializer,
|
|
scope: scope,
|
|
include_status: true,
|
|
)
|
|
|
|
serializer.as_json
|
|
end
|
|
end
|
|
end
|