Eliminate ghost thread when all messages deleted in a thread.

Fixes #2262
Closes #2842

// FREEBIE
This commit is contained in:
Rhodey Orbits 2015-03-31 13:36:04 -07:00 committed by Moxie Marlinspike
parent dbc28746c0
commit 9ba19df2af
5 changed files with 28 additions and 10 deletions

View File

@ -1168,6 +1168,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
this.composeText.setText(text); this.composeText.setText(text);
} }
@Override
public void setThreadId(long threadId) {
this.threadId = threadId;
}
@Override @Override
public void onAttachmentChanged() { public void onAttachmentChanged() {
initializeSecurity(); initializeSecurity();

View File

@ -212,10 +212,17 @@ public class ConversationFragment extends ListFragment
@Override @Override
protected Void doInBackground(MessageRecord... messageRecords) { protected Void doInBackground(MessageRecord... messageRecords) {
for (MessageRecord messageRecord : messageRecords) { for (MessageRecord messageRecord : messageRecords) {
boolean threadDeleted;
if (messageRecord.isMms()) { if (messageRecord.isMms()) {
DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId()); threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
} else { } else {
DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId()); threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
}
if (threadDeleted) {
threadId = -1;
listener.setThreadId(threadId);
} }
} }
@ -297,6 +304,8 @@ public class ConversationFragment extends ListFragment
public interface ConversationFragmentListener { public interface ConversationFragmentListener {
public void setComposeText(String text); public void setComposeText(String text);
public void setThreadId(long threadId);
} }
public interface SelectionClickListener extends public interface SelectionClickListener extends

View File

@ -760,7 +760,7 @@ public class MmsDatabase extends MessagingDatabase {
return messageId; return messageId;
} }
public void delete(long messageId) { public boolean delete(long messageId) {
long threadId = getThreadIdForMessage(messageId); long threadId = getThreadIdForMessage(messageId);
MmsAddressDatabase addrDatabase = DatabaseFactory.getMmsAddressDatabase(context); MmsAddressDatabase addrDatabase = DatabaseFactory.getMmsAddressDatabase(context);
PartDatabase partDatabase = DatabaseFactory.getPartDatabase(context); PartDatabase partDatabase = DatabaseFactory.getPartDatabase(context);
@ -769,8 +769,9 @@ public class MmsDatabase extends MessagingDatabase {
SQLiteDatabase database = databaseHelper.getWritableDatabase(); SQLiteDatabase database = databaseHelper.getWritableDatabase();
database.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""}); database.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""});
DatabaseFactory.getThreadDatabase(context).update(threadId); boolean threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId);
notifyConversationListeners(threadId); notifyConversationListeners(threadId);
return threadDeleted;
} }
public void deleteThread(long threadId) { public void deleteThread(long threadId) {

View File

@ -482,13 +482,14 @@ public class SmsDatabase extends MessagingDatabase {
return cursor; return cursor;
} }
public void deleteMessage(long messageId) { public boolean deleteMessage(long messageId) {
Log.w("MessageDatabase", "Deleting: " + messageId); Log.w("MessageDatabase", "Deleting: " + messageId);
SQLiteDatabase db = databaseHelper.getWritableDatabase(); SQLiteDatabase db = databaseHelper.getWritableDatabase();
long threadId = getThreadIdForMessage(messageId); long threadId = getThreadIdForMessage(messageId);
db.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""}); db.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""});
DatabaseFactory.getThreadDatabase(context).update(threadId); boolean threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId);
notifyConversationListeners(threadId); notifyConversationListeners(threadId);
return threadDeleted;
} }
/*package */void deleteThread(long threadId) { /*package */void deleteThread(long threadId) {

View File

@ -391,14 +391,14 @@ public class ThreadDatabase extends Database {
return null; return null;
} }
public void update(long threadId) { public boolean update(long threadId) {
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context); MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
long count = mmsSmsDatabase.getConversationCount(threadId); long count = mmsSmsDatabase.getConversationCount(threadId);
if (count == 0) { if (count == 0) {
deleteThread(threadId); deleteThread(threadId);
notifyConversationListListeners(); notifyConversationListListeners();
return; return true;
} }
MmsSmsDatabase.Reader reader = null; MmsSmsDatabase.Reader reader = null;
@ -414,15 +414,17 @@ public class ThreadDatabase extends Database {
else timestamp = record.getDateReceived(); else timestamp = record.getDateReceived();
updateThread(threadId, count, record.getBody().getBody(), timestamp, record.getType()); updateThread(threadId, count, record.getBody().getBody(), timestamp, record.getType());
notifyConversationListListeners();
return false;
} else { } else {
deleteThread(threadId); deleteThread(threadId);
notifyConversationListListeners();
return true;
} }
} finally { } finally {
if (reader != null) if (reader != null)
reader.close(); reader.close();
} }
notifyConversationListListeners();
} }
public static interface ProgressListener { public static interface ProgressListener {