discourse/plugins/chat/app/queries/chat_channel_memberships_query.rb
Joffrey JAFFEUX 6b0aeced7e
DEV: rework the chat-live-pane (#20519)
This PR is introducing glimmer usage in the chat-live-pane, for components but also for models. RestModel usage has been dropped in favor of native classes.

Other changes/additions in this PR:

sticky dates, scrolling will now keep the date separator of the current section at the top of the screen
better unread management, marking a channel as unread will correctly mark the correct message and not mark the whole channel as read. Tracking state will also now correctly return unread count and unread mentions.
adds an animation on bottom arrow
better scrolling behavior, we should now always correctly keep the scroll position while loading more
reactions are now more reactive, and will update their tooltip without needed to close/reopen it
skeleton has been improved with placeholder images and reactions
when making a reaction on the desktop message actions, the menu won't move anymore
simplify logic and stop maintaining a list of unloaded messages
2023-03-03 13:09:25 +01:00

48 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class ChatChannelMembershipsQuery
def self.call(channel:, limit: 50, offset: 0, username: nil, count_only: false)
query =
UserChatChannelMembership
.joins(:user)
.includes(:user)
.where(user: User.activated.not_suspended.not_staged)
.where(chat_channel: channel, following: true)
return query.count if count_only
if channel.category_channel? && channel.read_restricted? && channel.allowed_group_ids
query =
query.where(
"user_id IN (SELECT user_id FROM group_users WHERE group_id IN (?))",
channel.allowed_group_ids,
)
end
if username.present?
if SiteSetting.prioritize_username_in_ux || !SiteSetting.enable_names
query = query.where("users.username_lower ILIKE ?", "%#{username}%")
else
query =
query.where(
"LOWER(users.name) ILIKE ? OR users.username_lower ILIKE ?",
"%#{username}%",
"%#{username}%",
)
end
end
if SiteSetting.prioritize_username_in_ux || !SiteSetting.enable_names
query = query.order("users.username_lower ASC")
else
query = query.order("users.name ASC, users.username_lower ASC")
end
query.offset(offset).limit(limit)
end
def self.count(channel)
call(channel: channel, count_only: true)
end
end