Skip to content

Commit

Permalink
Changes for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Dec 10, 2024
1 parent e5f1dce commit e2b9acd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions browser/ai_chat/android/ai_chat_utils_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void JNI_BraveLeoUtils_OpenLeoQuery(
content::WebContents::FromJavaWebContents(jweb_contents);
AIChatService* ai_chat_service = AIChatServiceFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
DCHECK(ai_chat_service);
CHECK(ai_chat_service);
auto conversation_uuid_str =
base::android::ConvertJavaStringToUTF8(conversation_uuid);
// This function is either targeted at a specific conversation
Expand Down Expand Up @@ -58,7 +58,7 @@ static void JNI_BraveLeoUtils_OpenLeoQuery(
GURL(base::StrCat({kChatUIURL, conversation->get_conversation_uuid()})),
content::Referrer(), WindowOpenDisposition::CURRENT_TAB,
ui::PAGE_TRANSITION_FROM_API, false);
CHECK(web_contents->OpenURL(params, {}));
web_contents->OpenURL(params, {});
}

static void JNI_BraveLeoUtils_OpenLeoUrlForTab(
Expand Down
12 changes: 0 additions & 12 deletions browser/ui/webui/ai_chat/ai_chat_ui_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ void AIChatUIPageHandler::HandleVoiceRecognition(
#endif
}

void AIChatUIPageHandler::ConversationExists(
const std::string& conversation_uuid,
ConversationExistsCallback callback) {
AIChatServiceFactory::GetForBrowserContext(profile_)->GetConversation(
conversation_uuid, base::BindOnce(
[](ConversationExistsCallback callback,
ConversationHandler* conversation) {
std::move(callback).Run(conversation != nullptr);
},
std::move(callback)));
}

void AIChatUIPageHandler::OpenAIChatSettings() {
content::WebContents* contents_to_navigate =
(active_chat_tab_helper_) ? active_chat_tab_helper_->web_contents()
Expand Down
2 changes: 0 additions & 2 deletions browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class AIChatUIPageHandler : public mojom::AIChatUIHandler,
void RefreshPremiumSession() override;
void ManagePremium() override;
void HandleVoiceRecognition(const std::string& conversation_uuid) override;
void ConversationExists(const std::string& conversation_uuid,
ConversationExistsCallback callback) override;
void CloseUI() override;
void SetChatUI(mojo::PendingRemote<mojom::ChatUI> chat_ui,
SetChatUICallback callback) override;
Expand Down
11 changes: 11 additions & 0 deletions components/ai_chat/core/browser/ai_chat_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ void AIChatService::RenameConversation(const std::string& id,
OnConversationTitleChanged(conversation_handler, new_name);
}

void AIChatService::ConversationExists(const std::string& conversation_uuid,
ConversationExistsCallback callback) {
GetConversation(conversation_uuid,
base::BindOnce(
[](ConversationExistsCallback callback,
ConversationHandler* conversation) {
std::move(callback).Run(conversation != nullptr);
},
std::move(callback)));
}

void AIChatService::OnPremiumStatusReceived(GetPremiumStatusCallback callback,
mojom::PremiumStatus status,
mojom::PremiumInfoPtr info) {
Expand Down
3 changes: 2 additions & 1 deletion components/ai_chat/core/browser/ai_chat_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class AIChatService : public KeyedService,
void DeleteConversation(const std::string& id) override;
void RenameConversation(const std::string& id,
const std::string& new_name) override;

void ConversationExists(const std::string& conversation_uuid,
ConversationExistsCallback callback) override;
void BindConversation(
const std::string& uuid,
mojo::PendingReceiver<mojom::ConversationHandler> receiver,
Expand Down
10 changes: 5 additions & 5 deletions components/ai_chat/core/common/mojom/ai_chat.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ interface Service {
DeleteConversation(string id);
RenameConversation(string id, string new_name);

// Determines whether a conversation exists - we need this so we can determine
// whether a URL is bogus (i.e. made up) or if it corresponds to a
// not-visible-in-sidebar conversation.
ConversationExists(string conversation_uuid) => (bool exists);

// Bind ability to send events to the UI and receive current state
BindObserver(pending_remote<ServiceObserver> ui) => (ServiceState state);

Expand Down Expand Up @@ -354,11 +359,6 @@ interface AIChatUIHandler {
// so that we can use [EnableIfNot=is_android] here.
OpenConversationFullPage(string conversation_uuid);

// Determines whether a conversation exists - we need this so we can determine
// whether a URL is bogus (i.e. made up) or if it corresponds to a
// not-visible-in-sidebar conversation.
ConversationExists(string conversation_uuid) => (bool exists);

OpenURL(url.mojom.Url url);
OpenLearnMoreAboutBraveSearchWithLeo();
OpenModelSupportUrl();
Expand Down
2 changes: 1 addition & 1 deletion components/ai_chat/resources/page/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const defaultUIState: State = {
isPremiumUserDisconnected: false,
isStorageNoticeDismissed: false,
canShowPremiumPrompt: false,
isMobile: true,// loadTimeData.getBoolean('isMobile'),
isMobile: loadTimeData.getBoolean('isMobile'),
isHistoryFeatureEnabled: loadTimeData.getBoolean('isHistoryEnabled'),
allActions: [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function ActiveChatProvider({ children, selectedConversationId, updateSelectedCo
// If this isn't a visible conversation, it could be an empty tab bound
// conversation.
let cancelled = false
getAPI().uiHandler.conversationExists(selectedConversationId).then(({ exists }) => {
getAPI().service.conversationExists(selectedConversationId).then(({ exists }) => {
if (cancelled) return
if (exists) return
updateSelectedConversationId(undefined)
Expand Down

0 comments on commit e2b9acd

Please sign in to comment.