@@ -402,10 +402,7 @@ public function getMessage(int $sessionId, int $messageId): JSONResponse {
402
402
return new JSONResponse (['error ' => $ this ->l10n ->t ('Session not found ' )], Http::STATUS_NOT_FOUND );
403
403
}
404
404
405
- $ message = $ this ->messageMapper ->getMessageById ($ messageId );
406
- if ($ message ->getSessionId () !== $ sessionId ) {
407
- return new JSONResponse (['error ' => $ this ->l10n ->t ('Message not found ' )], Http::STATUS_NOT_FOUND );
408
- }
405
+ $ message = $ this ->messageMapper ->getMessageById ($ sessionId , $ messageId );
409
406
410
407
return new JSONResponse ($ message ->jsonSerialize ());
411
408
} catch (\OCP \DB \Exception $ e ) {
@@ -439,23 +436,19 @@ public function deleteMessage(int $messageId, int $sessionId): JSONResponse {
439
436
if (!$ sessionExists ) {
440
437
return new JSONResponse (['error ' => $ this ->l10n ->t ('Session not found ' )], Http::STATUS_NOT_FOUND );
441
438
}
442
- $ message = $ this ->messageMapper ->getMessageById ($ messageId );
443
- // otherwise one can delete a message from other sessions
444
- if ($ message ->getSessionId () !== $ sessionId ) {
445
- return new JSONResponse (['error ' => $ this ->l10n ->t ('Message not found ' )], Http::STATUS_NOT_FOUND );
446
- }
439
+ $ message = $ this ->messageMapper ->getMessageById ($ sessionId , $ messageId );
440
+ $ ocpTaskId = $ message ->getOcpTaskId ();
441
+
442
+ $ this ->messageMapper ->deleteMessageById ($ sessionId , $ messageId );
447
443
448
444
// delete the related task
449
- $ ocpTaskId = $ message ->getOcpTaskId ();
450
445
if ($ ocpTaskId !== 0 ) {
451
446
try {
452
447
$ task = $ this ->taskProcessingManager ->getTask ($ ocpTaskId );
453
448
$ this ->taskProcessingManager ->deleteTask ($ task );
454
449
} catch (\OCP \TaskProcessing \Exception \Exception ) {
455
450
}
456
451
}
457
-
458
- $ this ->messageMapper ->deleteMessageById ($ messageId );
459
452
return new JSONResponse ();
460
453
} catch (\OCP \DB \Exception |\RuntimeException $ e ) {
461
454
$ this ->logger ->warning ('Failed to delete a chat message ' , ['exception ' => $ e ]);
@@ -633,7 +626,7 @@ public function regenerateForSession(int $sessionId, int $messageId): JSONRespon
633
626
}
634
627
635
628
try {
636
- $ this ->messageMapper ->deleteMessageById ($ messageId );
629
+ $ this ->messageMapper ->deleteMessageById ($ sessionId , $ messageId );
637
630
} catch (\OCP \DB \Exception |\RuntimeException $ e ) {
638
631
$ this ->logger ->warning ('Failed to delete the last message ' , ['exception ' => $ e ]);
639
632
return new JSONResponse (['error ' => $ this ->l10n ->t ('Failed to delete the last message ' )], Http::STATUS_INTERNAL_SERVER_ERROR );
0 commit comments