Skip to content

Commit

Permalink
fixup! add thread summary ui
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Aug 5, 2023
1 parent 652418a commit b029448
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
],
[
'name' => 'thread#summarize',
'url' => '/api/thread/{id}/summary/',
'url' => '/api/thread/{id}/summary',
'verb' => 'GET'
],
[
Expand Down
21 changes: 12 additions & 9 deletions lib/Controller/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,26 @@ public function delete(int $id): JSONResponse {
/**
* @NoAdminRequired
*
* @param string $id
* @param int $accountId
* @param int $id
*
* @return JSONResponse
*/
public function summarize(string $id, int $accountId): JSONResponse {
public function summarize(int $id): JSONResponse {
try {
$account = $this->accountService->find($this->currentUserId, $accountId);
$messages = $this->mailManager->getThread($account, $id);
} catch (ClientException $e) {
$message = $this->mailManager->getMessage($this->currentUserId, $id);
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId());
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
} catch (DoesNotExistException $e) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

if (empty($message->getThreadRootId())) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
$thread = $this->mailManager->getThread($account, $message->getThreadRootId());
try {
$summary = $this->aiIntergrationsService->summarizeThread(
$id,
$messages,
$message->getThreadRootId(),
$thread,
$this->currentUserId,
);
} catch (\Throwable $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Thread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default {
if (this.thread.length < 2 && !this.enabledThreadSummary) return
this.summaryLoading = true
const summary = await summarizeThread(this.thread[0].threadRootId, this.accountId)
const summary = await summarizeThread(this.thread[0].databaseId)
this.summaryText = summary
this.summaryLoading = false
},
Expand Down
3 changes: 1 addition & 2 deletions src/service/AiIntergrationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'

export const summarizeThread = async (threadId, accountId) => {
const url = generateUrl('/apps/mail/api/thread/{threadId}/summary?accountId={accountId}', {
const url = generateUrl('/apps/mail/api/thread/{threadId}/summary', {
threadId,
accountId,
})

const resp = await axios.get(url)
Expand Down

0 comments on commit b029448

Please sign in to comment.