mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 07:40:08 +09:00
Hello world
First open source release of Campfire 🎉
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
class Users::SidebarsController < ApplicationController
|
||||
DIRECT_PLACEHOLDERS = 20
|
||||
|
||||
def show
|
||||
all_memberships = Current.user.memberships.visible.with_ordered_room
|
||||
@direct_memberships = extract_direct_memberships(all_memberships)
|
||||
@other_memberships = all_memberships.without(@direct_memberships)
|
||||
|
||||
@direct_placeholder_users = find_direct_placeholder_users
|
||||
end
|
||||
|
||||
private
|
||||
def extract_direct_memberships(all_memberships)
|
||||
all_memberships.select { |m| m.room.direct? }.sort_by { |m| m.room.updated_at }.reverse
|
||||
end
|
||||
|
||||
def find_direct_placeholder_users
|
||||
exclude_user_ids = user_ids_already_in_direct_rooms_with_current_user.including(Current.user.id)
|
||||
User.active.where.not(id: exclude_user_ids).order(:created_at).limit(DIRECT_PLACEHOLDERS - exclude_user_ids.count)
|
||||
end
|
||||
|
||||
def user_ids_already_in_direct_rooms_with_current_user
|
||||
Membership.where(room_id: Current.user.rooms.directs.pluck(:id)).pluck(:user_id).uniq
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user