Allow +1 via email

This commit is contained in:
James Kiesel
2015-12-30 12:17:45 +01:00
parent e45caa7e2e
commit 86da47880a
5 changed files with 132 additions and 2 deletions

View File

@ -21,6 +21,7 @@ module Email
class ReplyUserNotFoundError < ProcessingError; end
class ReplyUserNotMatchingError < ProcessingError; end
class InactiveUserError < ProcessingError; end
class InvalidPostAction < ProcessingError; end
attr_reader :body, :email_log
@ -103,7 +104,11 @@ module Email
raise ReplyUserNotFoundError if user.blank?
raise ReplyUserNotMatchingError if @email_log.user_id != user.id
create_reply(@email_log)
if post_action_type = post_action_for(@body)
create_post_action(@email_log, post_action_type)
else
create_reply(@email_log)
end
end
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError => e
@ -239,6 +244,18 @@ module Email
@body = "[quote=\"#{user_email}\"]\n#{@body}\n[/quote]"
end
def create_post_action(email_log, type)
PostAction.act(email_log.user, email_log.post, type)
rescue PostAction::AlreadyActed => e
raise InvalidPostAction.new(e)
end
def post_action_for(body)
if ['+1', I18n.t('post_action_types.like.title').downcase].include? body.downcase
PostActionType.types[:like]
end
end
def create_reply(email_log)
create_post_with_attachments(email_log.user,
raw: @body,