mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
Debounce thread updates for incoming messages.
This commit is contained in:
@@ -113,6 +113,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange
|
||||
import org.thoughtcrime.securesms.insights.InsightsConstants
|
||||
import org.thoughtcrime.securesms.jobs.OptimizeMessageSearchIndexJob
|
||||
import org.thoughtcrime.securesms.jobs.ThreadUpdateJob
|
||||
import org.thoughtcrime.securesms.jobs.TrimThreadJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview
|
||||
@@ -1058,7 +1059,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
threads.update(threadId, true)
|
||||
ThreadUpdateJob.enqueue(threadId)
|
||||
TrimThreadJob.enqueueAsync(threadId)
|
||||
}
|
||||
|
||||
@@ -2467,7 +2468,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
if (!MessageTypes.isPaymentsActivated(mailbox) && !MessageTypes.isPaymentsRequestToActivate(mailbox) && !MessageTypes.isExpirationTimerUpdate(mailbox) && !retrieved.storyType.isStory && isNotStoryGroupReply) {
|
||||
val incrementUnreadMentions = retrieved.mentions.isNotEmpty() && retrieved.mentions.any { it.recipientId == Recipient.self().id }
|
||||
threads.incrementUnread(threadId, 1, if (incrementUnreadMentions) 1 else 0)
|
||||
threads.update(threadId, true)
|
||||
ThreadUpdateJob.enqueue(threadId)
|
||||
}
|
||||
|
||||
notifyConversationListeners(threadId)
|
||||
|
||||
@@ -9,12 +9,18 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
|
||||
/**
|
||||
* A job that effectively debounces thread updates through a combination of having a max instance count
|
||||
* and sleeping at the end of the job to make sure it takes a minimum amount of time.
|
||||
*/
|
||||
public final class ThreadUpdateJob extends BaseJob {
|
||||
|
||||
public static final String KEY = "ThreadUpdateJob";
|
||||
|
||||
private static final String KEY_THREAD_ID = "thread_id";
|
||||
|
||||
private static final long DEBOUNCE_INTERVAL = 3000;
|
||||
|
||||
private final long threadId;
|
||||
|
||||
private ThreadUpdateJob(long threadId) {
|
||||
@@ -47,7 +53,7 @@ public final class ThreadUpdateJob extends BaseJob {
|
||||
@Override
|
||||
protected void onRun() throws Exception {
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
ThreadUtil.sleep(1000);
|
||||
ThreadUtil.sleep(DEBOUNCE_INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user