Skip to content

Contacts: Sort by Last Seen does not sort by last seen; add has-unread filter #59

Description

@MrSurly

Bug: "Sort by Last Seen" does not actually sort by recency

lib/screens/contacts_screen.dart:88:

if (_sort == _SortOrder.lastSeen) return searched;

When the user selects "Sort by Last Seen," the screen does not sort at all -- it just returns the list in whatever order the underlying stream already provided, assuming that order is last-seen-descending. It is not.

The underlying stream comes from _buildContactsWithUnread() / getAllContactsWithUnread() (lib/database/daos/contacts_dao.dart, around lines 323-345 and 369-383), which applies a compound comparator in this priority order:

  1. Non-repeaters before repeaters
  2. Has unread messages before no unread
  3. Has any message history before no history
  4. Higher unread count
  5. Only then, lastSeen descending

So any of criteria 1-4 can silently override recency. Confirmed report: two contacts ("P3", "Stormlove...") with message history and 0 unread were sorted above a third contact with a more recent "last seen: Just now," despite none of the three being repeaters and none having unread messages -- i.e. even after criteria 1, 2, and 4 are tied, criterion 5 (lastSeen desc) should have produced the correct order and did not. This suggests either the comparator is not actually the thing powering the observed list in this case, or there is a discrepancy between the lastSeen value used for sorting and the "X ago" text displayed to the user, worth checking as part of the fix -- e.g. whether the displayed relative time and the sorted lastSeen field can drift apart, or whether contacts_dao.dart:161 updateLastSeen (which appears to have no callers anywhere in the app) is dead code that should be wired up to keep last_seen current on actual contact activity rather than only being set once from the advert timestamp during contact sync (lib/repositories/contact_repository.dart:356).

Suggested fix: when _sort == _SortOrder.lastSeen, explicitly sort the list by contact.lastSeen descending in contacts_screen.dart, instead of trusting the source stream's order:

if (_sort == _SortOrder.lastSeen) {
  final sorted = [...searched];
  sorted.sort((a, b) => b.contact.lastSeen.compareTo(a.contact.lastSeen));
  return sorted;
}

Feature: add a "has unread" filter

_ContactFilter (lib/screens/contacts_screen.dart:19) currently has: endNodes, repeaters, hasLocation, noLocation, favorites. There is no way to filter the contacts list down to only contacts with unread messages -- unread status currently only affects sort priority (and only under the "Last Seen" sort, per the bug above), never inclusion/exclusion. Add a new filter option (same pattern as favorites) to show only contacts with unreadCount > 0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions