🐛 fix: Enhance file retrieval logic with custom sorting and improved filter handling

This commit is contained in:
jarvis2f 2025-02-21 17:00:58 +08:00
parent 7192e1bf2f
commit f12ed8ec6d
5 changed files with 29 additions and 13 deletions

View file

@ -155,14 +155,24 @@ public class FileRepositoryImpl implements FileRepository {
} }
} }
String countClause = whereClause; String countClause = whereClause;
if (fromMessageId > 0) {
whereClause += " AND message_id < #{fromMessageId}";
params.put("fromMessageId", fromMessageId);
}
String orderBy = "message_id DESC"; 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); 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)); log.trace("Get files with where: %s params: %s".formatted(whereClause, params));
return Future.all( return Future.all(
SqlTemplate SqlTemplate

View file

@ -61,7 +61,7 @@ function FileCaption({ file, rowHeight, ellipsis }: FileExtraProps) {
<p <p
className={cn( className={cn(
(rowHeight !== "l" || ellipsis) && "line-clamp-1", (rowHeight !== "l" || ellipsis) && "line-clamp-1",
"overflow-hidden text-wrap text-start text-sm", "overflow-hidden text-wrap text-start text-sm px-1",
)} )}
> >
{file.caption} {file.caption}
@ -95,7 +95,7 @@ function FilePath({ file, ellipsis }: FileExtraProps) {
<FileCheck className="h-4 w-4 flex-shrink-0" /> <FileCheck className="h-4 w-4 flex-shrink-0" />
<p <p
className={cn( className={cn(
"group cursor-pointer overflow-hidden text-wrap rounded px-1 hover:bg-gray-100 dark:hover:bg-gray-800", "group cursor-pointer overflow-hidden text-nowrap rounded px-1 hover:bg-gray-100 dark:hover:bg-gray-800",
ellipsis && "line-clamp-1", ellipsis && "line-clamp-1",
isMobile && "px-0", isMobile && "px-0",
)} )}
@ -139,7 +139,7 @@ function FileTime({ file }: FileExtraProps) {
{!isMobile && file.completionDate && ( {!isMobile && file.completionDate && (
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<p className="flex items-center gap-2"> <p className="items-center gap-2 hidden lg:flex">
<ClockArrowDown className="h-4 w-4" /> <ClockArrowDown className="h-4 w-4" />
<span className="rounded px-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800"> <span className="rounded px-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800">
{formatDistanceToNow(new Date(file.completionDate), { {formatDistanceToNow(new Date(file.completionDate), {

View file

@ -501,7 +501,7 @@ export default function FileFilters({
/> />
{!localFilters.offline && ( {!localFilters.offline && (
<div className="flex items-center justify-between rounded-md border bg-zinc-100 px-2 py-3 dark:bg-zinc-800"> <div className="flex items-center justify-between rounded-md border bg-gray-100/50 px-2 py-3 dark:bg-gray-600/50">
<Label htmlFor="notDownload">Filter Not Download</Label> <Label htmlFor="notDownload">Filter Not Download</Label>
<Switch <Switch
id="notDownload" id="notDownload"

View file

@ -41,10 +41,6 @@ export default function FileViewer({
handleLoadMore, handleLoadMore,
}); });
useEffect(() => {
console.log("FileViewer rendered", file);
}, [file]);
useEffect(() => { useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => { const handleKeyDown = (e: KeyboardEvent) => {
if (file === undefined || !open) return; if (file === undefined || !open) return;

View file

@ -70,6 +70,16 @@ export function useFiles(accountId: string, chatId: string) {
} }
params.set("fromMessageId", previousPageData.nextFromMessageId.toString()); params.set("fromMessageId", previousPageData.nextFromMessageId.toString());
if (filters.offline && previousPageData.files.length > 0) {
const lastFile = previousPageData.files[previousPageData.files.length - 1];
if (filters.sort === "size") {
params.set("fromSortField", lastFile!.size.toString());
} else if (filters.sort === "completion_date") {
params.set("fromSortField", lastFile!.completionDate.toString());
} else if (filters.sort === "date") {
params.set("fromSortField", lastFile!.date.toString());
}
}
return `/telegram/${accountId}/chat/${chatId}/files?${params.toString()}`; return `/telegram/${accountId}/chat/${chatId}/files?${params.toString()}`;
}; };