mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 12:57:17 +08:00
Allow +1 via email
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user