mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: extract channel. joined_by method (#21752)
This only moves code around and doesn't change any behavior. This does two things: 1. Extracts the `channel.joined_by?` methods 2. Uses term "members" instead of "participants" for chat members
This commit is contained in:
parent
050828d1de
commit
3349ce2c79
@ -119,6 +119,14 @@ module Chat
|
|||||||
update_user_counts
|
update_user_counts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def joined_by?(user)
|
||||||
|
user.user_chat_channel_memberships.strict_loading.any? do |membership|
|
||||||
|
predicate = membership.chat_channel_id == id
|
||||||
|
predicate = predicate && membership.following if public_channel?
|
||||||
|
predicate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.update_message_counts
|
def self.update_message_counts
|
||||||
# NOTE: Chat::Channel#messages_count is not updated every time
|
# NOTE: Chat::Channel#messages_count is not updated every time
|
||||||
# a message is created or deleted in a channel, so it should not
|
# a message is created or deleted in a channel, so it should not
|
||||||
|
@ -158,20 +158,14 @@ module Chat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def group_users_to_notify(users)
|
def group_users_to_notify(users)
|
||||||
potential_participants, unreachable =
|
potential_members, unreachable =
|
||||||
users.partition { |user| user.guardian.can_join_chat_channel?(@chat_channel) }
|
users.partition { |user| user.guardian.can_join_chat_channel?(@chat_channel) }
|
||||||
|
|
||||||
participants, welcome_to_join =
|
members, welcome_to_join =
|
||||||
potential_participants.partition do |participant|
|
potential_members.partition { |user| @chat_channel.joined_by?(user) }
|
||||||
participant.user_chat_channel_memberships.any? do |m|
|
|
||||||
predicate = m.chat_channel_id == @chat_channel.id
|
|
||||||
predicate = predicate && m.following == true if @chat_channel.public_channel?
|
|
||||||
predicate
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
{
|
{
|
||||||
already_participating: participants || [],
|
members: members || [],
|
||||||
welcome_to_join: welcome_to_join || [],
|
welcome_to_join: welcome_to_join || [],
|
||||||
unreachable: unreachable || [],
|
unreachable: unreachable || [],
|
||||||
}
|
}
|
||||||
@ -191,7 +185,7 @@ module Chat
|
|||||||
|
|
||||||
grouped = group_users_to_notify(direct_mentions)
|
grouped = group_users_to_notify(direct_mentions)
|
||||||
|
|
||||||
to_notify[:direct_mentions] = grouped[:already_participating].map(&:id)
|
to_notify[:direct_mentions] = grouped[:members].map(&:id)
|
||||||
inaccessible[:welcome_to_join] = grouped[:welcome_to_join]
|
inaccessible[:welcome_to_join] = grouped[:welcome_to_join]
|
||||||
inaccessible[:unreachable] = grouped[:unreachable]
|
inaccessible[:unreachable] = grouped[:unreachable]
|
||||||
already_covered_ids.concat(to_notify[:direct_mentions])
|
already_covered_ids.concat(to_notify[:direct_mentions])
|
||||||
@ -211,7 +205,7 @@ module Chat
|
|||||||
@parsed_mentions.groups_to_mention.each { |g| to_notify[g.name.downcase] = [] }
|
@parsed_mentions.groups_to_mention.each { |g| to_notify[g.name.downcase] = [] }
|
||||||
|
|
||||||
grouped = group_users_to_notify(reached_by_group)
|
grouped = group_users_to_notify(reached_by_group)
|
||||||
grouped[:already_participating].each do |user|
|
grouped[:members].each do |user|
|
||||||
# When a user is a member of multiple mentioned groups,
|
# When a user is a member of multiple mentioned groups,
|
||||||
# the most far to the left should take precedence.
|
# the most far to the left should take precedence.
|
||||||
ordered_group_names =
|
ordered_group_names =
|
||||||
|
Loading…
Reference in New Issue
Block a user