Skip to content

Better thread last seen logic#1778

Merged
SessionHero01 merged 47 commits intorefactor-notificationfrom
tidy-up-threads
Mar 2, 2026
Merged

Better thread last seen logic#1778
SessionHero01 merged 47 commits intorefactor-notificationfrom
tidy-up-threads

Conversation

@SessionHero01
Copy link
Collaborator

@SessionHero01 SessionHero01 commented Dec 15, 2025

This PR moves most the last seen logic of messages onto thread level:

  1. Thead's lastSeen is mainly sourced from the config system, a copy is saved into local db so that ancient times that would have been rejected by the config system can be saved in the db
  2. Count unread messages based on the config's last seen when querying threads
  3. Automatically handling the messages being marked as read (sending receipt, starting expiration timer, etc), is now done automatically by listening to config changes
  4. Add isOutgoing virtual column to sms/mms database so we don't have to do the crazy bitmasking stuff
  5. No need to call threadDb.update anymore: now every piece of data is computed using latest data
  6. Finer granularity in message/thread change notification

SessionHero01 and others added 26 commits December 11, 2025 13:18
# Conflicts:
#	app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt
#	app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java
# Conflicts:
#	app/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt
#	app/src/main/java/org/session/libsession/utilities/recipients/RecipientData.kt
#	app/src/main/java/org/thoughtcrime/securesms/auth/AuthAwareComponents.kt
#	app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt
#	app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
#	app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationLoader.kt
#	app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt
#	app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java
#	app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java
#	app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
#	app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java
#	app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java
#	app/src/main/java/org/thoughtcrime/securesms/dependencies/OnAppStartupComponents.kt
#	app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
#	app/src/main/java/org/thoughtcrime/securesms/notifications/AndroidAutoReplyReceiver.kt
#	app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadProcessor.kt
#	app/src/main/java/org/thoughtcrime/securesms/notifications/MarkReadReceiver.kt
#	app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.kt
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR is a significant refactoring that moves the thread last seen logic from being database-based to config-based. The core changes include:

Changes:

  • Thread lastSeen is now fully managed by the config system, removing the need for the thread table to keep it in sync
  • Unread message counts are now computed based on the config's last seen when querying threads
  • Automatic message read handling (receipts, expiration timers) is now done by listening to config changes via MarkReadProcessor as an AuthAwareComponent
  • Added isOutgoing virtual column to SMS/MMS databases to eliminate bitmasking logic
  • Removed the need to call threadDb.update() - all thread data is now computed using the latest data

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Storage.kt Replaces markConversationAsRead with updateConversationLastSeenIfNeeded, manages last seen via config
StorageProtocol.kt Updates interface to reflect new config-based last seen management
ThreadDatabase.java Removes thread update/sync logic, reduces responsibility to basic CRUD operations
ThreadDatabaseExt.kt New file with queryThreads function that computes thread data from config + DB, includes threadContainsOutgoingMessage helper
SmsDatabase.java, MmsDatabase.kt Adds IS_OUTGOING virtual column, updates message read tracking
SmsDatabaseExt.kt New extension with setMessagesRead implementation
MarkReadProcessor.kt Now implements AuthAwareComponent, listens to config changes and processes mark-read automatically
SharedConfigUtils.kt Adds utility functions for config operations: get, erase, getOrConstructConvo
Various notification receivers Updated to use new updateConversationLastSeenIfNeeded API
Test files Updated to use new Contact data structure with configData parameter
RecipientData.kt Contact now wraps config data directly instead of duplicating fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# Conflicts:
#	app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
# Conflicts:
#	app/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt
# Conflicts:
#	app/src/main/java/org/session/libsession/database/StorageProtocol.kt
#	app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java
#	app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt
#	app/src/main/java/org/thoughtcrime/securesms/webrtc/WebRtcCallBridge.kt
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import org.thoughtcrime.securesms.database.RecipientSettingsDatabase
import org.thoughtcrime.securesms.database.SmsDatabase
import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.database.model.GroupThreadStatus
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

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

Unused import: SmsDatabase_Factory is imported but not referenced in this file. Please remove it to keep imports clean.

Suggested change
import org.thoughtcrime.securesms.database.model.GroupThreadStatus

Copilot uses AI. Check for mistakes.
@SessionHero01 SessionHero01 changed the title Move thread last seen logic to fully config based Better thread last seen logic Mar 1, 2026
@SessionHero01 SessionHero01 changed the base branch from dev to refactor-notification March 1, 2026 23:53
@SessionHero01 SessionHero01 merged commit 66a3dfe into refactor-notification Mar 2, 2026
5 checks passed
@SessionHero01 SessionHero01 deleted the tidy-up-threads branch March 2, 2026 02:57
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.

4 participants