diff --git a/api/src/main/java/telegram/files/repository/impl/FileRepositoryImpl.java b/api/src/main/java/telegram/files/repository/impl/FileRepositoryImpl.java index b42ebd9..533859a 100644 --- a/api/src/main/java/telegram/files/repository/impl/FileRepositoryImpl.java +++ b/api/src/main/java/telegram/files/repository/impl/FileRepositoryImpl.java @@ -155,14 +155,24 @@ public class FileRepositoryImpl implements FileRepository { } } String countClause = whereClause; - if (fromMessageId > 0) { - whereClause += " AND message_id < #{fromMessageId}"; - params.put("fromMessageId", fromMessageId); - } String orderBy = "message_id DESC"; - if (StrUtil.isNotBlank(sort) && StrUtil.isNotBlank(order)) { + boolean customSort = StrUtil.isNotBlank(sort) && StrUtil.isNotBlank(order); + if (customSort) { orderBy = "%s %s".formatted(sort, order); } + if (fromMessageId > 0) { + params.put("fromMessageId", fromMessageId); + if (customSort) { + long fromSortField = Convert.toLong(filter.get("fromSortField")); + whereClause += " AND (%s %s %s OR (%s = %s AND message_id < #{fromMessageId}))".formatted(sort, + Objects.equals(order, "asc") ? ">" : "<", + fromSortField, + sort, + fromSortField); + } else { + whereClause += " AND message_id < #{fromMessageId}"; + } + } log.trace("Get files with where: %s params: %s".formatted(whereClause, params)); return Future.all( SqlTemplate diff --git a/web/src/components/file-extra.tsx b/web/src/components/file-extra.tsx index da18afb..697de2a 100644 --- a/web/src/components/file-extra.tsx +++ b/web/src/components/file-extra.tsx @@ -61,7 +61,7 @@ function FileCaption({ file, rowHeight, ellipsis }: FileExtraProps) {
{file.caption}
@@ -95,7 +95,7 @@ function FilePath({ file, ellipsis }: FileExtraProps) {
+