From e772fe68a4f60411b018cc44317c4a5aefc863db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Sep 2023 20:09:32 +0200 Subject: [PATCH] fix(comments): Use provided offset in best effort when loading comments When we didn't find the "$lastKnownComment" the whole condition was ignored. Now we still use the ID as an offset. This is required as a fall-back for expired messages in Talk and deleted comments in other apps. Signed-off-by: Joas Schilling --- lib/private/Comments/Manager.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index b5bfbc43100fb..e6a174f59ad18 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -548,6 +548,22 @@ public function getCommentsWithVerbForObjectSinceComment( ) ); } + } elseif ($lastKnownCommentId > 0) { + // We didn't find the "$lastKnownComment" but we still use the ID as an offset. + // This is required as a fall-back for expired messages in talk and deleted comments in other apps. + if ($sortDirection === 'desc') { + if ($includeLastKnown) { + $query->andWhere($query->expr()->lte('id', $query->createNamedParameter($lastKnownCommentId))); + } else { + $query->andWhere($query->expr()->lt('id', $query->createNamedParameter($lastKnownCommentId))); + } + } else { + if ($includeLastKnown) { + $query->andWhere($query->expr()->gte('id', $query->createNamedParameter($lastKnownCommentId))); + } else { + $query->andWhere($query->expr()->gt('id', $query->createNamedParameter($lastKnownCommentId))); + } + } } $resultStatement = $query->execute();