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 7, 2023
1 parent b029448 commit 831be1d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function deleteAntiSpamEmail(): JSONResponse {
public function setAllowNewMailAccounts(bool $allowed) {
$this->config->setAppValue('mail', 'allow_new_mail_accounts', $allowed ? 'yes' : 'no');
}

public function setEnabledThreadSummary(bool $enabled) {
$this->config->setAppValue('mail', 'enabled_thread_summary', $enabled ? 'yes' : 'no');
}
Expand Down
14 changes: 6 additions & 8 deletions lib/Controller/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ class ThreadController extends Controller {
private LoggerInterface $logger;


public function __construct(string $appName,
IRequest $request,
string $UserId,
AccountService $accountService,
IMailManager $mailManager,
public function __construct(string $appName,
IRequest $request,
string $UserId,
AccountService $accountService,
IMailManager $mailManager,
AiIntegrationsService $aiIntergrationsService,
LoggerInterface $logger,
) {
LoggerInterface $logger) {
parent::__construct($appName, $request);

$this->currentUserId = $UserId;
$this->accountService = $accountService;
$this->mailManager = $mailManager;
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadingSkeleton.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<div v-for="i in numberOfLines" :key="i" class="item-list__entry">
<div
<div v-if="withAvatar"
class="item-avatar" />
<div class="item__details">
<h3>&nbsp;</h3>
Expand Down
21 changes: 16 additions & 5 deletions src/components/Thread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</div>
</div>
</div>
<ThreadSummary v-if="thread.length > 2 && enabledThreadSummary" :loading="summaryLoading" :summary="summaryText" />
<ThreadSummary v-if="showSummaryBox" :loading="summaryLoading" :summary="summaryText" />
<ThreadEnvelope v-for="env in thread"
:key="env.databaseId"
:envelope="env"
Expand All @@ -55,6 +55,7 @@

<script>
import { NcAppContentDetails as AppContentDetails, NcPopover as Popover } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import { prop, uniqBy } from 'ramda'
import debounce from 'lodash/fp/debounce'
Expand Down Expand Up @@ -99,6 +100,7 @@ export default {
resizeDebounced: debounce(500, this.updateParticipantsToDisplay),
enabledThreadSummary: loadState('mail', 'enabled_thread_summary', false),
summaryText: '',
summaryError: false,
}
},
Expand Down Expand Up @@ -148,6 +150,9 @@ export default {
}
return thread[0].subject || this.t('mail', 'No subject')
},
showSummaryBox() {
return this.thread.length > 2 && this.enabledThreadSummary && !this.summaryError
},
},
watch: {
$route(to, from) {
Expand All @@ -173,12 +178,18 @@ export default {
},
methods: {
async updateSummary() {
if (this.thread.length < 2 && !this.enabledThreadSummary) return
if (this.thread.length < 2 || !this.enabledThreadSummary) return
this.summaryLoading = true
const summary = await summarizeThread(this.thread[0].databaseId)
this.summaryText = summary
this.summaryLoading = false
try {
this.summaryText = await summarizeThread(this.thread[0].databaseId)
} catch (error) {
this.summaryError = true
showError(t('mail', 'Summarizing thread failed.'))
logger.error('Summarizing thread failed',{ error})

Check failure on line 189 in src/components/Thread.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required after ','

Check failure on line 189 in src/components/Thread.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required before '}'
} finally {
this.summaryLoading = false
}
},
updateParticipantsToDisplay() {
// Wait until everything is in place
Expand Down
11 changes: 8 additions & 3 deletions src/service/AiIntergrationsService.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { convertAxiosError } from '../errors/convert'

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

const resp = await axios.get(url)
return resp.data.data
try {
const resp = await axios.get(url)
return resp.data.data
} catch (e) {
throw convertAxiosError(e)
}
}
3 changes: 2 additions & 1 deletion src/service/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ export const updateEnabledThreadSummary = async (enabled) => {
const data = {
enabled,
}
return await axios.post(url, data).then((resp) => resp.data)
const resp = await axios.post(url, data)
return resp.data
}

0 comments on commit 831be1d

Please sign in to comment.