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, source_user_id: current_user.id,
content: params[:question], content: params[:question],
author_identifier: AnonymousBlock.get_identifier(request.remote_ip), author_identifier: AnonymousBlock.get_identifier(request.remote_ip),
send_to_own_inbox: params[:sendToOwnInbox],
) )
return return
end end

View File

@ -13,7 +13,8 @@ export function questionboxAllHandler(event: Event): void {
body: { body: {
rcpt: 'followers', rcpt: 'followers',
question: document.querySelector<HTMLInputElement>('textarea[name=qb-all-question]').value, 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' 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" } } %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') .alert.alert-warning.mt-3.d-none{ data: { "character-count-warning-target": "warning" } }= t('.long_question_warning')
.modal-footer .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-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") %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" action: "Ask"
loading: "Asking…" loading: "Asking…"
long_question_warning: "This question will only be sent to those who allow long questions in their profile settings." 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: list:
title: "Manage list memberships" title: "Manage list memberships"
tab: tab:

View File

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

View File

@ -77,9 +77,11 @@ describe Ajax::QuestionController, :ajax_controller, type: :controller do
{ {
question: question_content, question: question_content,
anonymousQuestion: anonymous_question, anonymousQuestion: anonymous_question,
rcpt: rcpt rcpt:,
sendToOwnInbox: send_to_own_inbox,
} }
end end
let(:send_to_own_inbox) { "false" }
subject { post(:create, params: params) } 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 context "when rcpt is a valid user" do
let(:rcpt) { target_user.id } let(:rcpt) { target_user.id }
let(:send_to_own_inbox) { false }
context "when user allows anonymous questions" do context "when user allows anonymous questions" do
let(:user_allows_anonymous_questions) { true } 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 "creates the question", false
include_examples "enqueues SendToInboxJob jobs" include_examples "enqueues SendToInboxJob jobs"
end 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 end
context "when rcpt is an invalid value" do context "when rcpt is an invalid value" do
let(:rcpt) { "tripmeister_eder" } let(:rcpt) { "tripmeister_eder" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" } let(:anonymous_question) { "false" }
let(:expected_response) do 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 context "when rcpt is a non-existent user" do
let(:rcpt) { "-1" } let(:rcpt) { "-1" }
let(:send_to_own_inbox) { false }
let(:anonymous_question) { "false" } let(:anonymous_question) { "false" }
let(:expected_response) do let(:expected_response) do
{ {