Always delete all messages when deleting a conversation.
This commit is contained in:
parent
8950100bd7
commit
be4b687e48
1 changed files with 62 additions and 47 deletions
|
@ -240,35 +240,6 @@ public class ThreadDatabase extends Database {
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteThread(long threadId) {
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
||||||
db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId + ""});
|
|
||||||
notifyConversationListListeners();
|
|
||||||
ConversationUtil.clearShortcuts(context, Collections.singleton(threadId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteThreads(Set<Long> threadIds) {
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
||||||
String where = "";
|
|
||||||
|
|
||||||
for (long threadId : threadIds) {
|
|
||||||
where += ID + " = '" + threadId + "' OR ";
|
|
||||||
}
|
|
||||||
|
|
||||||
where = where.substring(0, where.length() - 4);
|
|
||||||
|
|
||||||
db.delete(TABLE_NAME, where, null);
|
|
||||||
notifyConversationListListeners();
|
|
||||||
ConversationUtil.clearShortcuts(context, threadIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteAllThreads() {
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
||||||
db.delete(TABLE_NAME, null, null);
|
|
||||||
notifyConversationListListeners();
|
|
||||||
ConversationUtil.clearAllShortcuts(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void trimAllThreads(int length, long trimBeforeDate) {
|
public void trimAllThreads(int length, long trimBeforeDate) {
|
||||||
if (length == NO_TRIM_MESSAGE_COUNT_SET && trimBeforeDate == NO_TRIM_BEFORE_DATE_SET) {
|
if (length == NO_TRIM_MESSAGE_COUNT_SET && trimBeforeDate == NO_TRIM_BEFORE_DATE_SET) {
|
||||||
return;
|
return;
|
||||||
|
@ -978,28 +949,74 @@ public class ThreadDatabase extends Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteConversation(long threadId) {
|
public void deleteConversation(long threadId) {
|
||||||
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
|
db.beginTransaction();
|
||||||
|
try {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteThread(threadId);
|
DatabaseFactory.getSmsDatabase(context).deleteThread(threadId);
|
||||||
DatabaseFactory.getMmsDatabase(context).deleteThread(threadId);
|
DatabaseFactory.getMmsDatabase(context).deleteThread(threadId);
|
||||||
DatabaseFactory.getDraftDatabase(context).clearDrafts(threadId);
|
DatabaseFactory.getDraftDatabase(context).clearDrafts(threadId);
|
||||||
deleteThread(threadId);
|
|
||||||
notifyConversationListeners(threadId);
|
db.delete(TABLE_NAME, ID_WHERE, new String[]{threadId + ""});
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
|
notifyConversationListeners(threadId);
|
||||||
|
ConversationUtil.clearShortcuts(context, Collections.singleton(threadId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteConversations(Set<Long> selectedConversations) {
|
public void deleteConversations(Set<Long> selectedConversations) {
|
||||||
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
|
db.beginTransaction();
|
||||||
|
try {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteThreads(selectedConversations);
|
DatabaseFactory.getSmsDatabase(context).deleteThreads(selectedConversations);
|
||||||
DatabaseFactory.getMmsDatabase(context).deleteThreads(selectedConversations);
|
DatabaseFactory.getMmsDatabase(context).deleteThreads(selectedConversations);
|
||||||
DatabaseFactory.getDraftDatabase(context).clearDrafts(selectedConversations);
|
DatabaseFactory.getDraftDatabase(context).clearDrafts(selectedConversations);
|
||||||
deleteThreads(selectedConversations);
|
|
||||||
notifyConversationListeners(selectedConversations);
|
StringBuilder where = new StringBuilder();
|
||||||
|
|
||||||
|
for (long threadId : selectedConversations) {
|
||||||
|
if (where.length() > 0) {
|
||||||
|
where.append(" OR ");
|
||||||
|
}
|
||||||
|
where.append(ID + " = '").append(threadId).append("'");
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete(TABLE_NAME, where.toString(), null);
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
|
notifyConversationListeners(selectedConversations);
|
||||||
|
ConversationUtil.clearShortcuts(context, selectedConversations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAllConversations() {
|
public void deleteAllConversations() {
|
||||||
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
|
||||||
|
db.beginTransaction();
|
||||||
|
try {
|
||||||
DatabaseFactory.getSmsDatabase(context).deleteAllThreads();
|
DatabaseFactory.getSmsDatabase(context).deleteAllThreads();
|
||||||
DatabaseFactory.getMmsDatabase(context).deleteAllThreads();
|
DatabaseFactory.getMmsDatabase(context).deleteAllThreads();
|
||||||
DatabaseFactory.getDraftDatabase(context).clearAllDrafts();
|
DatabaseFactory.getDraftDatabase(context).clearAllDrafts();
|
||||||
deleteAllThreads();
|
|
||||||
|
db.delete(TABLE_NAME, null, null);
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyConversationListListeners();
|
||||||
|
ConversationUtil.clearAllShortcuts(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadIdIfExistsFor(@NonNull RecipientId recipientId) {
|
public long getThreadIdIfExistsFor(@NonNull RecipientId recipientId) {
|
||||||
|
@ -1229,8 +1246,7 @@ public class ThreadDatabase extends Database {
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
if (allowDeletion) {
|
if (allowDeletion) {
|
||||||
deleteThread(threadId);
|
deleteConversation(threadId);
|
||||||
notifyConversationListListeners();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1249,8 +1265,7 @@ public class ThreadDatabase extends Database {
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
deleteThread(threadId);
|
deleteConversation(threadId);
|
||||||
notifyConversationListListeners();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Add table
Reference in a new issue