refactor message creation (conversations)

This commit is contained in:
Florian Staudacher 2013-10-20 21:52:49 +02:00
parent 830747a11e
commit 1c4ad0986c
3 changed files with 10 additions and 4 deletions

View file

@ -11,6 +11,7 @@
* Refactor ConversationsController, move query building to User model. [#4547](https://github.com/diaspora/diaspora/pull/4547) * Refactor ConversationsController, move query building to User model. [#4547](https://github.com/diaspora/diaspora/pull/4547)
* Refactor the Twitter service model [#4387](https://github.com/diaspora/diaspora/pull/4387) * Refactor the Twitter service model [#4387](https://github.com/diaspora/diaspora/pull/4387)
* Refactor ConversationsController#create, move more stuff to User model [#4551](https://github.com/diaspora/diaspora/pull/4551) * Refactor ConversationsController#create, move more stuff to User model [#4551](https://github.com/diaspora/diaspora/pull/4551)
* Refactor MessagesController#create, move stuff to User model [#4556](https://github.com/diaspora/diaspora/pull/4556)
## Bug fixes ## Bug fixes
* Highlight down arrow at the user menu on hover [#4441](https://github.com/diaspora/diaspora/pull/4441) * Highlight down arrow at the user menu on hover [#4441](https://github.com/diaspora/diaspora/pull/4441)

View file

@ -11,10 +11,8 @@ class MessagesController < ApplicationController
def create def create
conversation = Conversation.find(params[:conversation_id]) conversation = Conversation.find(params[:conversation_id])
message = conversation.messages.build( opts = params.require(:message).permit(:text)
:text => params[:message][:text], message = current_user.build_message(conversation, opts)
:author => current_user.person
)
if message.save if message.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}") Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")

View file

@ -36,6 +36,13 @@ module User::SocialActions
end end
end end
def build_message(conversation, opts={})
conversation.messages.build(
text: opts[:text],
author: self.person
)
end
def find_or_create_participation!(target) def find_or_create_participation!(target)
participations.where(:target_id => target).first || participate!(target) participations.where(:target_id => target).first || participate!(target)
end end