Module: Decidim::Messaging::ConversationHelper

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

Instance Method Summary collapse

Instance Method Details

#conversation_between(*participants) ⇒ Decidim::Messaging::Conversation

Finds the conversation between the given participants

Parameters:

  • participants (Array<Decidim::User>)

    The participants to find a conversation between.

Returns:



50
51
52
53
54
55
56
# File 'app/helpers/decidim/messaging/conversation_helper.rb', line 50

def conversation_between(*participants)
  return if participants.to_set.length <= 1

  UserConversations.for(participants.first).find do |conversation|
    conversation.participants.to_set == participants.to_set
  end
end

#current_or_new_conversation_path_with(user) ⇒ String

Finds the right path to the conversation the current user and another user.

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

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

  • Otherwise, it returns the path to the existing conversation.

Parameters:

  • user (Decidim::User)

    The user to link to a conversation with

Returns:

  • (String)

    The resulting route



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/decidim/messaging/conversation_helper.rb', line 30

def current_or_new_conversation_path_with(user)
  decidim_routes = Decidim::Core::Engine.routes.url_helpers
  return decidim_routes.new_user_session_path unless user_signed_in?

  conversation = conversation_between(current_user, user)

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

Links to the conversation between the current user and another user



9
10
11
12
13
# File 'app/helpers/decidim/messaging/conversation_helper.rb', line 9

def link_to_current_or_new_conversation_with(user, title = t("decidim.contact"))
  link_to current_or_new_conversation_path_with(user), title: title do
    icon "envelope-closed", aria_label: title, class: "icon--small"
  end
end