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); MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
long count = mmsSmsDatabase.getConversationCount(threadId); long count = mmsSmsDatabase.getConversationCount(threadId);
boolean shouldDeleteEmptyThread = deleteThreadOnEmpty(threadId);
if (count == 0 && shouldDeleteEmptyThread) {
if (count == 0) {
deleteThread(threadId); deleteThread(threadId);
notifyConversationListListeners(); notifyConversationListListeners();
return true; return true;
@ -534,9 +534,12 @@ public class ThreadDatabase extends Database {
notifyConversationListListeners(); notifyConversationListListeners();
return false; return false;
} else { } else {
deleteThread(threadId); if (shouldDeleteEmptyThread) {
notifyConversationListListeners(); deleteThread(threadId);
return true; notifyConversationListListeners();
return true;
}
return false;
} }
} finally { } finally {
if (reader != null) if (reader != null)
@ -544,6 +547,11 @@ public class ThreadDatabase extends Database {
} }
} }
private boolean deleteThreadOnEmpty(long threadId) {
Recipient threadRecipient = getRecipientForThreadId(threadId);
return threadRecipient != null && !threadRecipient.isOpenGroupRecipient();
}
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) { private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
if (messageRecord.isMms()) { if (messageRecord.isMms()) {
MmsMessageRecord record = (MmsMessageRecord) messageRecord; MmsMessageRecord record = (MmsMessageRecord) messageRecord;

View File

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