Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Controller from "@ember/controller";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
import UppyUpload from "discourse/lib/uppy/uppy-upload";
import UppyMediaOptimization from "discourse/lib/uppy-media-optimization-plugin";
import { clipboardHelpers } from "discourse/lib/utilities";
Expand Down Expand Up @@ -172,10 +173,15 @@ export default class DiscourseAiBotConversations extends Controller {
}

@action
prepareAndSubmitToBot() {
async prepareAndSubmitToBot() {
// Pass uploads to the service before submitting
this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
this.aiBotConversationsHiddenSubmit.submitToBot();
try {
await this.aiBotConversationsHiddenSubmit.submitToBot();
this.uploads.clear();
} catch (error) {
popupAjaxError(error);
}
}

_autoExpandTextarea() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { next } from "@ember/runloop";
import Service, { service } from "@ember/service";
import { tracked } from "@ember-compat/tracked-built-ins";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { getUploadMarkdown } from "discourse/lib/uploads";
import { i18n } from "discourse-i18n";

Expand All @@ -13,6 +12,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
@service composer;
@service dialog;
@service router;
@service siteSettings;

@tracked loading = false;

Expand All @@ -33,10 +33,14 @@ export default class AiBotConversationsHiddenSubmit extends Service {

@action
async submitToBot() {
if (this.inputValue.length < 10) {
if (
this.inputValue.length <
this.siteSettings.min_personal_message_post_length
) {
return this.dialog.alert({
message: i18n(
"discourse_ai.ai_bot.conversations.min_input_length_message"
"discourse_ai.ai_bot.conversations.min_input_length_message",
{ count: this.siteSettings.min_personal_message_post_length }
),
didConfirm: () => this.focusInput(),
didCancel: () => this.focusInput(),
Expand Down Expand Up @@ -89,8 +93,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
});

this.router.transitionTo(response.post_url);
} catch (e) {
popupAjaxError(e);
} finally {
this.loading = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export default {

// force Glimmer to re-render that one link
this.links = this.links.map((link) =>
link.topic.id === topic.id
link?.topic?.id === topic.id
? new AiConversationLink(topic)
: link
);
Expand Down
4 changes: 3 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ en:
disclaimer: "Generative AI can make mistakes. Verify important information."
placeholder: "Ask a question..."
new: "New Question"
min_input_length_message: "Message must be longer than 10 characters"
min_input_length_message:
one: "Message must be 1 character or longer"
other: "Message must be %{count} characters or longer"
messages_sidebar_title: "Conversations"
today: "Today"
last_7_days: "Last 7 days"
Expand Down
4 changes: 4 additions & 0 deletions spec/system/ai_bot/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
expect(topic_page).to have_content("Here are two image attachments")
expect(page).to have_css(".cooked img", count: 2)
end

find(".ai-new-question-button").click
expect(ai_pm_homepage).to have_homepage
expect(page).to have_no_css(".ai-bot-upload")
end

it "allows removing an upload before submission" do
Expand Down
6 changes: 5 additions & 1 deletion spec/system/page_objects/components/ai_pm_homepage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def submit
def has_too_short_dialog?
page.find(
".dialog-content",
text: I18n.t("js.discourse_ai.ai_bot.conversations.min_input_length_message"),
text:
I18n.t(
"js.discourse_ai.ai_bot.conversations.min_input_length_message",
count: SiteSetting.min_personal_message_post_length,
),
)
end

Expand Down
Loading