mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Fix stale thread id when a conversation is deleted.
This commit is contained in:
@@ -43,6 +43,7 @@ public class DatabaseObserver {
|
||||
private static final String KEY_RECIPIENT = "Recipient";
|
||||
private static final String KEY_STORY_OBSERVER = "Story";
|
||||
private static final String KEY_SCHEDULED_MESSAGES = "ScheduledMessages";
|
||||
private static final String KEY_CONVERSATION_DELETES = "ConversationDeletes";
|
||||
|
||||
private final Application application;
|
||||
private final Executor executor;
|
||||
@@ -50,6 +51,7 @@ public class DatabaseObserver {
|
||||
private final Set<Observer> conversationListObservers;
|
||||
private final Map<Long, Set<Observer>> conversationObservers;
|
||||
private final Map<Long, Set<Observer>> verboseConversationObservers;
|
||||
private final Map<Long, Set<Observer>> conversationDeleteObservers;
|
||||
private final Map<UUID, Set<Observer>> paymentObservers;
|
||||
private final Map<Long, Set<Observer>> scheduledMessageObservers;
|
||||
private final Set<Observer> allPaymentsObservers;
|
||||
@@ -68,6 +70,7 @@ public class DatabaseObserver {
|
||||
this.conversationListObservers = new HashSet<>();
|
||||
this.conversationObservers = new HashMap<>();
|
||||
this.verboseConversationObservers = new HashMap<>();
|
||||
this.conversationDeleteObservers = new HashMap<>();
|
||||
this.paymentObservers = new HashMap<>();
|
||||
this.allPaymentsObservers = new HashSet<>();
|
||||
this.chatColorsObservers = new HashSet<>();
|
||||
@@ -99,6 +102,12 @@ public class DatabaseObserver {
|
||||
});
|
||||
}
|
||||
|
||||
public void registerConversationDeleteObserver(long threadId, @NonNull Observer listener) {
|
||||
executor.execute(() -> {
|
||||
registerMapped(conversationDeleteObservers, threadId, listener);
|
||||
});
|
||||
}
|
||||
|
||||
public void registerPaymentObserver(@NonNull UUID paymentId, @NonNull Observer listener) {
|
||||
executor.execute(() -> {
|
||||
registerMapped(paymentObservers, paymentId, listener);
|
||||
@@ -181,6 +190,7 @@ public class DatabaseObserver {
|
||||
notificationProfileObservers.remove(listener);
|
||||
unregisterMapped(storyObservers, listener);
|
||||
unregisterMapped(scheduledMessageObservers, listener);
|
||||
unregisterMapped(conversationDeleteObservers, listener);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -212,6 +222,18 @@ public class DatabaseObserver {
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyConversationDeleteListeners(Set<Long> threadIds) {
|
||||
for (long threadId : threadIds) {
|
||||
notifyConversationDeleteListeners(threadId);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyConversationDeleteListeners(long threadId) {
|
||||
runPostSuccessfulTransaction(KEY_CONVERSATION_DELETES + threadId, () -> {
|
||||
notifyMapped(conversationDeleteObservers, threadId);
|
||||
});
|
||||
}
|
||||
|
||||
public void notifyConversationListListeners() {
|
||||
runPostSuccessfulTransaction(KEY_CONVERSATION_LIST, () -> {
|
||||
for (Observer listener : conversationListObservers) {
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
|
||||
import org.thoughtcrime.securesms.database.model.serialize
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.groups.BadGroupIdException
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.jobs.OptimizeMessageSearchIndexJob
|
||||
@@ -1040,6 +1041,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
notifyConversationListListeners()
|
||||
notifyConversationListeners(threadId)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyConversationDeleteListeners(threadId)
|
||||
ConversationUtil.clearShortcuts(context, setOf(recipientIdForThreadId))
|
||||
}
|
||||
|
||||
@@ -1056,6 +1058,7 @@ class ThreadTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
|
||||
notifyConversationListListeners()
|
||||
notifyConversationListeners(selectedConversations)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyConversationDeleteListeners(selectedConversations)
|
||||
ConversationUtil.clearShortcuts(context, recipientIdsForThreadIds)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user