Module: Denshobato::ControllerHelper

Includes:
HelperUtils
Defined in:
lib/denshobato/helpers/controller_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_create_conversation?(sender, recipient) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/denshobato/helpers/controller_helper.rb', line 17

def can_create_conversation?(sender, recipient)
  # If current sender is current recipient, return false

  sender == recipient ? false : true
end

#conversation_exists?(sender, recipient) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/denshobato/helpers/controller_helper.rb', line 11

def conversation_exists?(sender, recipient)
  # Check if sender and recipient already have conversation together.

  hato_conversation.find_by(sender: sender, recipient: recipient)
end

#user_in_conversation?(user, room) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/denshobato/helpers/controller_helper.rb', line 5

def user_in_conversation?(user, room)
  # redirect_to :root, notice: 'You can`t join this conversation unless user_in_conversation?(current_account, @conversation)'

  hato_conversation.where(id: room.id, sender: user).present? || hato_conversation.where(id: room.id, recipient: user).present?
end