refactor: don't delete empty threads if they're open groups

This commit is contained in:
jubb 2021-05-20 15:43:29 +10:00
parent 6ac534482f
commit 1cc0b0ee7d
2 changed files with 13 additions and 9 deletions

View File

@ -513,9 +513,9 @@ public class ThreadDatabase extends Database {
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
long count = mmsSmsDatabase.getConversationCount(threadId);
boolean shouldDeleteEmptyThread = deleteThreadOnEmpty(threadId);
if (count == 0) {
if (count == 0 && shouldDeleteEmptyThread) {
deleteThread(threadId);
notifyConversationListListeners();
return true;
@ -534,16 +534,24 @@ public class ThreadDatabase extends Database {
notifyConversationListListeners();
return false;
} else {
if (shouldDeleteEmptyThread) {
deleteThread(threadId);
notifyConversationListListeners();
return true;
}
return false;
}
} finally {
if (reader != null)
reader.close();
}
}
private boolean deleteThreadOnEmpty(long threadId) {
Recipient threadRecipient = getRecipientForThreadId(threadId);
return threadRecipient != null && !threadRecipient.isOpenGroupRecipient();
}
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
if (messageRecord.isMms()) {
MmsMessageRecord record = (MmsMessageRecord) messageRecord;

View File

@ -70,10 +70,6 @@ public class GroupManager {
final ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false);
if (!groupDatabase.getGroup(groupId).isPresent()) {
return false;
}
long threadId = threadDatabase.getThreadIdIfExistsFor(groupRecipient);
if (threadId != -1L) {
threadDatabase.deleteConversation(threadId);