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);
}
@Override
public void setThreadId(long threadId) {
this.threadId = threadId;
}
@Override
public void onAttachmentChanged() {
initializeSecurity();

View File

@ -212,10 +212,17 @@ public class ConversationFragment extends ListFragment
@Override
protected Void doInBackground(MessageRecord... messageRecords) {
for (MessageRecord messageRecord : messageRecords) {
boolean threadDeleted;
if (messageRecord.isMms()) {
DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
} 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 void setComposeText(String text);
public void setThreadId(long threadId);
}
public interface SelectionClickListener extends

View File

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

View File

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

View File

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