Fix crash when deleting threads directly after backup restore.
This commit is contained in:
parent
0a7a7cf5a9
commit
51a521594f
2 changed files with 9 additions and 10 deletions
|
@ -905,7 +905,8 @@ public class ThreadDatabase extends Database {
|
|||
}
|
||||
|
||||
public void deleteConversation(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
RecipientId recipientIdForThreadId = getRecipientIdForThreadId(threadId);
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
|
@ -922,11 +923,12 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
notifyConversationListListeners();
|
||||
notifyConversationListeners(threadId);
|
||||
ConversationUtil.clearShortcuts(context, Collections.singleton(threadId));
|
||||
ConversationUtil.clearShortcuts(context, Collections.singleton(recipientIdForThreadId));
|
||||
}
|
||||
|
||||
public void deleteConversations(Set<Long> selectedConversations) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
List<RecipientId> recipientIdsForThreadIds = getRecipientIdsForThreadIds(selectedConversations);
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
|
@ -952,7 +954,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
notifyConversationListListeners();
|
||||
notifyConversationListeners(selectedConversations);
|
||||
ConversationUtil.clearShortcuts(context, selectedConversations);
|
||||
ConversationUtil.clearShortcuts(context, recipientIdsForThreadIds);
|
||||
}
|
||||
|
||||
public void deleteAllConversations() {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.core.app.Person;
|
||||
import androidx.core.content.pm.ShortcutInfoCompat;
|
||||
|
@ -26,10 +25,10 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
|||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ConversationUtil encapsulates support for Android 11+'s new Conversations system
|
||||
|
@ -92,11 +91,9 @@ public final class ConversationUtil {
|
|||
/**
|
||||
* Clears the shortcuts tied to a given thread.
|
||||
*/
|
||||
public static void clearShortcuts(@NonNull Context context, @NonNull Set<Long> threadIds) {
|
||||
public static void clearShortcuts(@NonNull Context context, @NonNull Collection<RecipientId> recipientIds) {
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
List<RecipientId> recipientIds = DatabaseFactory.getThreadDatabase(context).getRecipientIdsForThreadIds(threadIds);
|
||||
|
||||
ShortcutManagerCompat.removeLongLivedShortcuts(context, Stream.of(recipientIds).map(ConversationUtil::getShortcutId).toList());
|
||||
ShortcutManagerCompat.removeLongLivedShortcuts(context, Stream.of(recipientIds).withoutNulls().map(ConversationUtil::getShortcutId).toList());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue