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);
|
this.composeText.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setThreadId(long threadId) {
|
||||||
|
this.threadId = threadId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachmentChanged() {
|
public void onAttachmentChanged() {
|
||||||
initializeSecurity();
|
initializeSecurity();
|
||||||
|
@ -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
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user