Module: Decidim::Messaging::ConversationHelper

Included in:
ConversationsController
Defined in:
app/helpers/decidim/messaging/conversation_helper.rb

Instance Method Summary collapse

Instance Method Details

#conversation_between(one_user, another_user) ⇒ Object



33
34
35
36
37
# File 'app/helpers/decidim/messaging/conversation_helper.rb', line 33

def conversation_between(one_user, another_user)
  UserConversations.for(one_user).find do |conversation|
    conversation.participants.to_set == [one_user, another_user].to_set
  end
end

Builds a link to the conversation between the current user and another user.

  • If there’s no current user, it links to the login form.

  • If there’s no prior existing conversation between the users, it links to the new conversation form.

  • Otherwise, it links to the existing conversation.

Parameters:

  • user (Decidim::User)

    The user to link to a conversation with

Returns:

  • (String)

    The resulting route



21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/decidim/messaging/conversation_helper.rb', line 21

def link_to_current_or_new_conversation_with(user)
  return decidim.new_user_session_path unless user_signed_in?

  conversation = conversation_between(current_user, user)

  if conversation
    decidim.conversation_path(conversation)
  else
    decidim.new_conversation_path(recipient_id: user.id)
  end
end