Class: Decidim::UserConversationsController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- Decidim::UserConversationsController
- Defined in:
- decidim-core/app/controllers/decidim/user_conversations_controller.rb
Overview
The controller to show all the conversations for a user or group This controller places conversations in the public profile page. Only for groups at the moment but it will make conversations_controller obsolete in the future
Constant Summary
Constants included from Paginable
Instance Method Summary collapse
- #create ⇒ Object
- #index ⇒ Object
-
#new ⇒ Object
Shows the form to initiate a conversation with one or more users/groups (the recipients) recipients are passed via GET parameters: - if no recipient are valid, redirects back to the users profile page - if the user already has a conversation with the user(s), redirects to the initiated conversation.
-
#show ⇒ Object
shows a conversation thread and presents a form to reply in ajax.
-
#update ⇒ Object
receive replies in ajax, messages are returned through the view update.js.erb and printed over the form instead of using flash messages.
Methods included from Messaging::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 UserGroups
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 RegistersPermissions
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'decidim-core/app/controllers/decidim/user_conversations_controller.rb', line 72 def create @form = form(Messaging::ConversationForm).from_params(params, sender: user) @conversation = new_conversation(@form.recipient) :create, :conversation, interlocutor: user, conversation: @conversation # do not allow to create multiple conversation to the same actors if already started if @conversation.id flash[:alert] = I18n.t("user_conversations.create.existing_error", scope: "decidim") return redirect_to profile_conversation_path(nickname: user.nickname, id: @conversation.id) end Messaging::StartConversation.call(@form) do on(:ok) do |_conversation| flash[:notice] = I18n.t("user_conversations.create.success", scope: "decidim") return redirect_to profile_conversations_path(nickname: user.nickname) end on(:invalid) do flash[:alert] = I18n.t("user_conversations.create.error", scope: "decidim") render action: :show end end end |
#index ⇒ Object
24 25 26 |
# File 'decidim-core/app/controllers/decidim/user_conversations_controller.rb', line 24 def index :list, :conversation, interlocutor: user end |
#new ⇒ Object
Shows the form to initiate a conversation with one or more users/groups (the recipients) recipients are passed via GET parameters:
- if no recipient are valid, redirects back to the users profile page
- if the user already has a conversation with the user(s), redirects to the initiated conversation
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'decidim-core/app/controllers/decidim/user_conversations_controller.rb', line 57 def new @form = form(Messaging::ConversationForm).from_params(params, sender: user) return redirect_back(fallback_location: profile_path(user.nickname)) if @form.recipient.empty? @conversation = new_conversation(@form.recipient) # redirect to existing conversation if already started return redirect_to profile_conversation_path(nickname: user.nickname, id: @conversation.id) if @conversation.id :create, :conversation, interlocutor: user, conversation: @conversation render :show end |
#show ⇒ Object
shows a conversation thread and presents a form to reply in ajax
29 30 31 32 33 |
# File 'decidim-core/app/controllers/decidim/user_conversations_controller.rb', line 29 def show (:show, :conversation, interlocutor: user, conversation:) conversation.mark_as_read(current_user) end |
#update ⇒ Object
receive replies in ajax, messages are returned through the view update.js.erb and printed over the form instead of using flash messages
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'decidim-core/app/controllers/decidim/user_conversations_controller.rb', line 37 def update (:update, :conversation, interlocutor: user, conversation:) @form = form(Messaging::MessageForm).from_params(params, sender: user) Messaging::ReplyToConversation.call(conversation, @form) do on(:ok) do || render action: :update, locals: { message: } end on(:invalid) do render_unprocessable_entity I18n.t("user_conversations.update.error", scope: "decidim") end end end |