Module: CommandTower::Messaging::Inbox::Scope

Defined in:
app/services/command_tower/messaging/inbox/scope.rb

Overview

Recipient-scoped InboxItem relation — never load globally then check ownership.

Class Method Summary collapse

Class Method Details

.find_for_recipient(recipient_id:, inbox_item_id:, lock: false) ⇒ Object



16
17
18
19
20
# File 'app/services/command_tower/messaging/inbox/scope.rb', line 16

def find_for_recipient(recipient_id:, inbox_item_id:, lock: false)
  relation = for_recipient(recipient_id)
  relation = relation.lock if lock
  relation.find_by(id: inbox_item_id)
end

.for_recipient(recipient_id) ⇒ Object



10
11
12
13
14
# File 'app/services/command_tower/messaging/inbox/scope.rb', line 10

def for_recipient(recipient_id)
  Messaging::InboxItem
    .joins(:communication)
    .where(messaging_communications: { user_id: recipient_id })
end