Return sharing options when answering a question

This commit is contained in:
Andreas Nedbal 2023-02-05 19:17:01 +01:00 committed by Andreas Nedbal
parent 926be13fa6
commit a56db2256b
2 changed files with 15 additions and 6 deletions

View File

@ -1,8 +1,12 @@
require 'cgi'
class Ajax::AnswerController < AjaxController
include SocialHelper::TwitterMethods
include SocialHelper::TumblrMethods
def create
params.require :id
params.require :answer
params.require :share
params.require :inbox
inbox = (params[:inbox] == 'true')
@ -31,15 +35,19 @@ class Ajax::AnswerController < AjaxController
current_user.answer question, params[:answer]
end
services = JSON.parse params[:share]
services.each do |service|
ShareWorker.perform_async(current_user.id, answer.id, service)
end
@response[:status] = :okay
@response[:message] = t(".success")
@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
# this assign is needed because shared/_answerbox relies on it, I think
@question = 1

View File

@ -12,6 +12,7 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
include User::PushNotificationMethods
include User::ReactionMethods
include User::RelationshipMethods
include User::SharingMethods
include User::TimelineMethods
include ActiveModel::OneTimePassword