Skip to content

feat: Add date picker to jump to specific dates in chat history#2

Merged
GeiserX merged 7 commits intomasterfrom
feature/date-picker
Dec 18, 2025
Merged

feat: Add date picker to jump to specific dates in chat history#2
GeiserX merged 7 commits intomasterfrom
feature/date-picker

Conversation

@GeiserX
Copy link
Copy Markdown
Owner

@GeiserX GeiserX commented Dec 18, 2025

Summary

  • Date picker feature: Click on any date separator in the chat to open a date picker modal, allowing users to jump to any date in the chat history
  • Dark theme styling: Custom Flatpickr dark theme that matches the existing UI
  • Smart message loading: Automatically fills gaps between jumped-to messages and previously loaded messages via pagination
  • Timezone-aware queries: Correctly converts user-selected dates from viewer timezone to UTC for accurate database queries

Technical Details

New API Endpoint

  • GET /api/chats/{chat_id}/messages/by-date?date=YYYY-MM-DD&timezone=...
  • Returns the first message on or after the specified date
  • Falls back to nearest message before the date, then first message in chat
  • Includes full user info, reactions, and media metadata (matching regular messages endpoint)

Frontend Changes

  • Date separator spans are now clickable
  • Modal with Flatpickr date picker integration
  • Message deduplication when jumping to dates (handles case where jumped message gets loaded again via pagination)
  • Changed sortedMessages from simple reverse to proper date sorting (required since jump can add messages out of order)

Bug Fixes

  • Race condition prevention when user switches chats during async date jump
  • Proper exception handling and error messages
  • Timezone mismatch fix: dates displayed in viewer timezone now query correctly against UTC database timestamps

Test Plan

  • Click on a date separator → date picker opens with that date pre-selected
  • Select a different date → jumps to first message on/near that date
  • Jump to a date far in the past → messages load to fill the gap
  • Switch chats while jump is in progress → no stale data appears
  • Test with non-UTC timezone configured → dates match correctly

Note

Adds a date picker to jump to specific dates with a new timezone-aware API to fetch the nearest message, and updates frontend sorting/merging to support out-of-order inserts.

  • Frontend (UI/behavior):
    • Date picker: Clickable date separators open a modal with Flatpickr; new modal UI and dark theme styles in src/web/templates/index.html.
    • Jump logic: openDatePicker, closeDatePicker, jumpToDate fetch the nearest message by date (passes timezone), scroll to it, and background-fill gaps via pagination; guards against chat switches.
    • Sorting/Merging: sortedMessages now sorts by date (not simple reverse). Pagination merges messages by ID, preferring richer paginated data over ad-hoc inserts.
  • Backend (API):
    • New endpoint: GET /api/chats/{chat_id}/messages/by-date?date=YYYY-MM-DD&timezone=... in src/web/main.py; finds first message on/after date, falls back to nearest before or first in chat; returns message with user/media joins, parsed raw_data, and aggregated reactions.
    • Timezone handling: Converts user-selected local date start to UTC using zoneinfo.
  • Database:
    • Helper: Database.find_message_by_date(chat_id, target_date) to get first message on/after a date.

Written by Cursor Bugbot for commit a0aa787. This will update automatically on new commits. Configure here.

- Add clickable date separators that open a calendar modal
- Implement date picker using flatpickr library with dark theme
- Add backend API endpoint /api/chats/{chat_id}/messages/by-date
- Add database method find_message_by_date() to locate messages by date
- Implement scroll-to-date functionality with smart message loading
- Handle edge cases: no messages on date, messages not yet loaded
- Telegram-like UX: click date separator → calendar modal → jump to date

This feature allows users to quickly navigate to specific dates in their
chat history, similar to Telegram's date picker functionality.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread src/web/main.py
Comment thread src/web/templates/index.html
Comment thread src/web/templates/index.html
…uplication

- Re-raise HTTPException before generic Exception catch to return proper 404 instead of 500
- Add deduplication in loadMessages to prevent duplicate entries from jumpToDate
- Capture oldest loaded message before jump to correctly trigger gap-filling load
Comment thread src/web/templates/index.html
- Change sortedMessages to sort by date instead of reverse, ensuring
  correct chronological order when jumpToDate adds messages out of order
- Fix gap-filling logic to loop until pagination catches up to target date,
  rather than loading just once (which left visible gaps)
- Capture oldest date before push to ensure correct comparison
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread src/web/main.py Outdated
Comment thread src/web/templates/index.html Outdated
Comment thread src/web/templates/index.html
- Capture chat ID at start of jumpToDate to detect chat switches
- Abort fillGap loop if user navigates to a different chat
- Update by-date API to return full message data with JOINs (user info, reactions)
- Improve message merge logic to prefer complete messages from pagination
Comment thread src/web/templates/index.html
Close the modal when jumpToDate encounters a 404 or any other error,
ensuring consistent UX where the modal always closes after the operation.
Comment thread src/web/main.py Outdated
The date picker had a timezone mismatch: frontend displayed dates in the
viewer's timezone but backend queried using naive UTC dates. This caused
incorrect results for non-UTC timezones (e.g., a message at 23:30 UTC on
Dec 14 displays as Dec 15 in UTC+1, but querying for Dec 15 wouldn't find it).

- Add timezone parameter to /api/chats/{chat_id}/messages/by-date endpoint
- Convert user-selected date from viewer timezone to UTC before querying
- Frontend now passes viewerTimezone when calling the API
Comment thread src/web/templates/index.html Outdated
The previous termination condition checked if the oldest non-target
message was newer than the target date. This caused at least one
unnecessary batch to load because the check would only pass once
pagination loaded messages OLDER than the target.

The fix tracks message IDs before each load and stops as soon as any
newly loaded message has a date at or before the target date, indicating
pagination has reached the target without needing to go past it.
@GeiserX GeiserX merged commit 2ed9810 into master Dec 18, 2025
3 checks passed
calvinturbo pushed a commit to calvinturbo/Telegram-Archive that referenced this pull request Jan 26, 2026
feat: Add date picker to jump to specific dates in chat history
GeiserX added a commit that referenced this pull request Feb 3, 2026
feat: Add date picker to jump to specific dates in chat history
PhenixStar pushed a commit to PhenixStar/Telegram-Archive that referenced this pull request Mar 10, 2026
feat: Add date picker to jump to specific dates in chat history
PhenixStar pushed a commit to PhenixStar/Telegram-Archive that referenced this pull request Mar 11, 2026
feat: Add date picker to jump to specific dates in chat history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant