Merge pull request #4556 from Raven24/conversations

refactor conversation message creation
This commit is contained in:
Jonne Haß 2013-10-21 03:46:57 -07:00
commit 76c75af373
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 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 MessagesController#create, move stuff to User model [#4556](https://github.com/diaspora/diaspora/pull/4556)
## Bug fixes
* 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
conversation = Conversation.find(params[:conversation_id])
message = conversation.messages.build(
:text => params[:message][:text],
:author => current_user.person
)
opts = params.require(:message).permit(:text)
message = current_user.build_message(conversation, opts)
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}")

View file

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