Return sharing options when answering a question
This commit is contained in:
parent
926be13fa6
commit
a56db2256b
|
@ -1,8 +1,12 @@
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
class Ajax::AnswerController < AjaxController
|
class Ajax::AnswerController < AjaxController
|
||||||
|
include SocialHelper::TwitterMethods
|
||||||
|
include SocialHelper::TumblrMethods
|
||||||
|
|
||||||
def create
|
def create
|
||||||
params.require :id
|
params.require :id
|
||||||
params.require :answer
|
params.require :answer
|
||||||
params.require :share
|
|
||||||
params.require :inbox
|
params.require :inbox
|
||||||
|
|
||||||
inbox = (params[:inbox] == 'true')
|
inbox = (params[:inbox] == 'true')
|
||||||
|
@ -31,15 +35,19 @@ class Ajax::AnswerController < AjaxController
|
||||||
current_user.answer question, params[:answer]
|
current_user.answer question, params[:answer]
|
||||||
end
|
end
|
||||||
|
|
||||||
services = JSON.parse params[:share]
|
|
||||||
services.each do |service|
|
|
||||||
ShareWorker.perform_async(current_user.id, answer.id, service)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
@response[:status] = :okay
|
@response[:status] = :okay
|
||||||
@response[:message] = t(".success")
|
@response[:message] = t(".success")
|
||||||
@response[:success] = true
|
@response[:success] = true
|
||||||
|
|
||||||
|
if current_user.sharing_enabled
|
||||||
|
@response[:sharing] = {
|
||||||
|
twitter: twitter_share_url(answer),
|
||||||
|
tumblr: tumblr_share_url(answer),
|
||||||
|
custom: CGI.escape(prepare_tweet(answer))
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
unless inbox
|
unless inbox
|
||||||
# this assign is needed because shared/_answerbox relies on it, I think
|
# this assign is needed because shared/_answerbox relies on it, I think
|
||||||
@question = 1
|
@question = 1
|
||||||
|
|
|
@ -12,6 +12,7 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
|
||||||
include User::PushNotificationMethods
|
include User::PushNotificationMethods
|
||||||
include User::ReactionMethods
|
include User::ReactionMethods
|
||||||
include User::RelationshipMethods
|
include User::RelationshipMethods
|
||||||
|
include User::SharingMethods
|
||||||
include User::TimelineMethods
|
include User::TimelineMethods
|
||||||
include ActiveModel::OneTimePassword
|
include ActiveModel::OneTimePassword
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue