Class: Decidim::Messaging::ConversationsController
Overview
The controller to handle the user’s conversations.
Instance Method Summary
collapse
#conversation_between, #current_or_new_conversation_path_with, #link_to_current_or_new_conversation_with
#disable_http_caching
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 26
def create
enforce_permission_to :create, :conversation
@form = form(ConversationForm).from_params(params)
StartConversation.call(@form) do
on(:ok) do |conversation|
redirect_to conversation_path(conversation)
end
on(:invalid) do
render json: { error: I18n.t("messaging.conversations.create.error", scope: "decidim") }, status: 422
end
end
end
|
#index ⇒ Object
42
43
44
45
46
|
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 42
def index
enforce_permission_to :list, :conversation
@conversations = UserConversations.for(current_user)
end
|
#new ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 16
def new
enforce_permission_to :create, :conversation
@form = form(ConversationForm).from_params(params)
redirect_back(fallback_location: profile_path(current_user.nickname)) && return unless @form.recipient
conversation = conversation_between(current_user, @form.recipient)
redirect_to conversation_path(conversation) if conversation
end
|
#show ⇒ Object
48
49
50
51
52
|
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 48
def show
enforce_permission_to :read, :conversation, conversation: conversation
@conversation.mark_as_read(current_user)
end
|
#update ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/decidim/messaging/conversations_controller.rb', line 54
def update
enforce_permission_to :update, :conversation, conversation: conversation
@form = form(MessageForm).from_params(params)
ReplyToConversation.call(conversation, @form) do
on(:ok) do |message|
render action: :update, locals: { message: message }
end
on(:invalid) do
render json: { error: I18n.t("messaging.conversations.update.error", scope: "decidim") }, status: 422
end
end
end
|