mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Eliminate ghost thread when all messages deleted in a thread.
Fixes #2262 Closes #2842 // FREEBIE
This commit is contained in:
parent
dbc28746c0
commit
9ba19df2af
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user