Add option to send question to own inbox

This commit is contained in:
Karina Kwiatek 2023-12-11 23:14:58 +01:00
parent 5d89e21e33
commit b02375985a
6 changed files with 45 additions and 2 deletions

View File

@ -19,6 +19,7 @@ class Ajax::QuestionController < AjaxController
source_user_id: current_user.id,
content: params[:question],
author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
send_to_own_inbox: params[:sendToOwnInbox],
)
return
end

View File

@ -13,7 +13,8 @@ export function questionboxAllHandler(event: Event): void {
body: {
rcpt: 'followers',
question: document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value,
anonymousQuestion: 'false'
anonymousQuestion: 'false',
sendToOwnInbox: (document.getElementById('qb-send-to-own-inbox') as HTMLInputElement).checked,
},
contentType: 'application/json'
})

View File

@ -12,5 +12,8 @@
%textarea.form-control{ name: "qb-all-question", placeholder: t(".placeholder"), data: { "character-count-warning-target": "input" } }
.alert.alert-warning.mt-3.d-none{ data: { "character-count-warning-target": "warning" } }= t('.long_question_warning')
.modal-footer
.float-start.flex-grow-1
%input.form-check-input#qb-send-to-own-inbox{ type: :checkbox }
%label.form-check-label{ for: 'qb-send-to-own-inbox' }= t('.send_to_own_inbox')
%button.btn.btn-default{ type: :button, data: { bs_dismiss: :modal } }= t("voc.cancel")
%button.btn.btn-primary{ name: "qb-all-ask", type: :button, data: { loading_text: t(".loading") } }= t(".action")

View File

@ -272,6 +272,7 @@ en:
action: "Ask"
loading: "Asking…"
long_question_warning: "This question will only be sent to those who allow long questions in their profile settings."
send_to_own_inbox: "Send copy to my inbox"
list:
title: "Manage list memberships"
tab:

View File

@ -6,6 +6,7 @@ module UseCase
option :source_user_id, type: Types::Coercible::Integer
option :content, type: Types::Coercible::String
option :author_identifier, type: Types::Coercible::String | Types::Nil
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
def call
question = ::Question.create!(
@ -20,6 +21,7 @@ module UseCase
increment_metric
args = source_user.followers.map { |f| [f.id, question.id] }
SendToInboxJob.perform_async(source_user_id, question.id) if send_to_own_inbox
SendToInboxJob.perform_bulk(args)
{

View File

@ -77,9 +77,11 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
{
question: question_content,
anonymousQuestion: anonymous_question,
rcpt: rcpt
rcpt:,
sendToOwnInbox: send_to_own_inbox,
}
end
let(:send_to_own_inbox) { "false" }
subject { post(:create, params: params) }
@ -98,6 +100,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when rcpt is a valid user" do
let(:rcpt) { target_user.id }
let(:send_to_own_inbox) { false }
context "when user allows anonymous questions" do
let(:user_allows_anonymous_questions) { true }
@ -219,10 +222,41 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
include_examples "creates the question", false
include_examples "enqueues SendToInboxJob jobs"
end
context "when sendToOwnInbox is true" do
let(:anonymous_question) { "false" }
let(:expected_question_anonymous) { false }
let(:user_allows_anonymous_questions) { false }
let(:send_to_own_inbox) { "true" }
include_examples "creates the question", false
it "sends question to the current user" do
allow(SendToInboxJob).to receive(:perform_async)
subject
expect(SendToInboxJob).to have_received(:perform_async).with(user.id, Question.last.id)
end
end
context "when sendToOwnInbox is false" do
let(:anonymous_question) { "false" }
let(:expected_question_anonymous) { false }
let(:user_allows_anonymous_questions) { false }
let(:send_to_own_inbox) { "false" }
include_examples "creates the question", false
it "sends question to the current user" do
allow(SendToInboxJob).to receive(:perform_async)
subject
expect(SendToInboxJob).not_to have_received(:perform_async).with(user.id, Question.last.id)
end
end
end
context "when rcpt is an invalid value" do
let(:rcpt) { "tripmeister_eder" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" }
let(:expected_response) do
{
@ -239,6 +273,7 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
context "when rcpt is a non-existent user" do
let(:rcpt) { "-1" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" }
let(:expected_response) do
{