Class: Decidim::Messaging::ConversationsController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- Decidim::Messaging::ConversationsController
- Includes:
- FormFactory, HasSpecificBreadcrumb, ConversationHelper
- Defined in:
- app/controllers/decidim/messaging/conversations_controller.rb
Overview
The controller to handle the user’s conversations.
Instance Method Summary collapse
- #check_multiple ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
-
#new ⇒ Object
Shows the form to initiate a conversation with an user (the recipient) recipient is passed via GET parameter: - if the recipient does not exists, goes back to the users profile page - if the user already has a conversation with the user, redirects to the initiated conversation.
- #show ⇒ Object
- #update ⇒ Object
Methods included from ConversationHelper
#conversation_between, #conversation_between_multiple, #conversation_label_for, #conversation_name_for, #current_or_new_conversation_path_with, #current_or_new_conversation_path_with_multiple, #current_or_new_profile_conversation_path, #current_or_new_user_conversation_path, #link_to_current_or_new_conversation_with, #text_link_to_current_or_new_conversation_with, #username_list
Methods included from UserBlockedChecker
#check_user_block_status, #check_user_not_blocked
Methods included from NeedsSnippets
Methods included from Headers::HttpCachingDisabler
Methods included from HasStoredPath
#skip_store_location?, #store_current_location
Methods included from TranslatableAttributes
Methods included from RegistersPermissions
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#check_multiple ⇒ Object
97 98 99 100 101 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 97 def check_multiple @form = form(ConversationForm).from_params(params, sender: current_user) redirect_link = current_or_new_conversation_path_with_multiple(@form.recipient, nickname: params[:nickname]) redirect_to redirect_link end |
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 40 def create @form = form(ConversationForm).from_params(params, sender: current_user) :create, :conversation, conversation: new_conversation(@form.recipient) StartConversation.call(@form) do on(:ok) do |conversation| render action: :create, locals: { conversation:, form: MessageForm.new } end on(:invalid) do || render action: :error, locals: { error: I18n.t("messaging.conversations.create.error", scope: "decidim"), messages: }, status: :unprocessable_entity end end end |
#index ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 61 def index :list, :conversation @conversations = UserConversations.for(current_user) @form = MessageForm.new << t("decidim.messaging.conversations.index.no_conversations") if @conversations.blank? end |
#new ⇒ Object
Shows the form to initiate a conversation with an user (the recipient) recipient is passed via GET parameter:
- if the recipient does not exists, goes back to the users profile page
- if the user already has a conversation with the user, redirects to the initiated conversation
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 23 def new @form = form(ConversationForm).from_params(params, sender: current_user) if @form.recipient.is_a? Enumerable participants = @form.recipient.to_a.prepend(current_user) conversation = conversation_between_multiple(participants) else conversation = conversation_between(current_user, @form.recipient) end return redirect_back(fallback_location: profile_path(current_user.nickname)) if @form.recipient.empty? return redirect_to conversation_path(conversation) if conversation :create, :conversation, conversation: new_conversation(@form.recipient) end |
#show ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 70 def show (:read, :conversation, conversation:) @conversation.mark_as_read(current_user) @form = MessageForm.new end |
#update ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 78 def update (:update, :conversation, conversation:) @form = form(MessageForm).from_params(params, sender: current_user) ReplyToConversation.call(conversation, @form) do on(:ok) do || render action: :update, locals: { message: } end on(:invalid) do || render action: :error, locals: { error: I18n.t("messaging.conversations.update.error", scope: "decidim"), messages: }, status: :unprocessable_entity end end end |