Skip to content

Commit 002a45d

Browse files
committed
small formatting changes to make the code in line with the existing code
Signed-off-by: Anna Visman <a.c.visman@student.tudelft.nl>
1 parent ef7416b commit 002a45d

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

lib/Controller/ChattyLLMController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,14 @@ public function deleteMessage(int $messageId, int $sessionId): JSONResponse {
480480
#[NoAdminRequired]
481481
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT, tags: ['chat_api'])]
482482
public function searchMessages(string $query): JSONResponse {
483+
483484
try {
484485
$result = $this->chatService->searchMessages($this->userId, $query);
485486
return new JSONResponse($result);
486487
} catch (InternalException $e) {
487488
$this->logger->warning('Failed to search chat messages', ['exception' => $e]);
488489
return new JSONResponse(['error' => $this->l10n->t('Failed to search chat messages')], Http::STATUS_INTERNAL_SERVER_ERROR);
489-
} catch (UnauthorizedException $e) {
490+
} catch (\OCA\Assistant\Service\UnauthorizedException $e) {
490491
return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED);
491492
}
492493
}

lib/Db/ChattyLLM/MessageMapper.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,9 @@ public function searchMessages(string $userId, string $query, int $limit = 100):
193193
$qb = $this->db->getQueryBuilder();
194194
$qb->select(Message::$columns)
195195
->from($this->getTableName(), 'm')
196-
->join('m', 'assistant_chat_sns', 's',
197-
$qb->expr()->eq('m.session_id', 's.id')
198-
)
199-
->where($qb->expr()->eq('s.user_id',
200-
$qb->createPositionalParameter($userId, IQueryBuilder::PARAM_STR)
201-
))
202-
->andWhere($qb->expr()->iLike('m.content',
203-
$qb->createPositionalParameter(
204-
'%' . $this->db->escapeLikeParameter($query) . '%',
205-
IQueryBuilder::PARAM_STR
206-
)
207-
))
196+
->join('m', 'assistant_chat_sns', 's', $qb->expr()->eq('m.session_id', 's.id'))
197+
->where($qb->expr()->eq('s.user_id', $qb->createPositionalParameter($userId, IQueryBuilder::PARAM_STR)))
198+
->andWhere($qb->expr()->iLike('m.content', $qb->createPositionalParameter('%' . $this->db->escapeLikeParameter($query) . '%', IQueryBuilder::PARAM_STR)))
208199
->orderBy('m.timestamp', 'DESC')
209200
->setMaxResults($limit);
210201

lib/Service/ChatService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function searchMessages(?string $userId, string $query): array {
177177
if ($userId === null) {
178178
throw new UnauthorizedException($this->l10n->t('Unauthorized'));
179179
}
180+
// For empty queries return two empty lists right away
180181
if (trim($query) === '') {
181182
return ['messages' => [], 'sessionIds' => []];
182183
}
@@ -189,7 +190,7 @@ public function searchMessages(?string $userId, string $query): array {
189190
array_map(fn(Message $m) => $m->getSessionId(), $messages)
190191
));
191192
return [
192-
'messages' => array_map(fn(Message $m) => $m->jsonSerialize(), $messages),
193+
'messages' => array_map(fn(Message $m) => $m->jsonSerialize(), $messages), // convert Message objects into plain arrays
193194
'sessionIds' => $sessionIds,
194195
];
195196
}

0 commit comments

Comments
 (0)