mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Not deleting a thread when it's empty - showing an empty snippet when thread is empty or only made up of 'marked as deleted' messages
This commit is contained in:
parent
4b01fcec5e
commit
c9c9078c2e
@ -175,7 +175,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
)
|
)
|
||||||
get(context).groupReceiptDatabase()
|
get(context).groupReceiptDatabase()
|
||||||
.update(ourAddress, id, status, timestamp)
|
.update(ourAddress, id, status, timestamp)
|
||||||
get(context).threadDatabase().update(threadId, false, true)
|
get(context).threadDatabase().update(threadId, false)
|
||||||
notifyConversationListeners(threadId)
|
notifyConversationListeners(threadId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,7 +274,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
" WHERE " + ID + " = ?", arrayOf(id.toString() + "")
|
" WHERE " + ID + " = ?", arrayOf(id.toString() + "")
|
||||||
)
|
)
|
||||||
if (threadId.isPresent) {
|
if (threadId.isPresent) {
|
||||||
get(context).threadDatabase().update(threadId.get(), false, true)
|
get(context).threadDatabase().update(threadId.get(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,7 +646,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
)
|
)
|
||||||
if (!MmsSmsColumns.Types.isExpirationTimerUpdate(mailbox)) {
|
if (!MmsSmsColumns.Types.isExpirationTimerUpdate(mailbox)) {
|
||||||
if (runThreadUpdate) {
|
if (runThreadUpdate) {
|
||||||
get(context).threadDatabase().update(threadId, true, true)
|
get(context).threadDatabase().update(threadId, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyConversationListeners(threadId)
|
notifyConversationListeners(threadId)
|
||||||
@ -791,7 +791,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
setHasSent(threadId, true)
|
setHasSent(threadId, true)
|
||||||
if (runThreadUpdate) {
|
if (runThreadUpdate) {
|
||||||
update(threadId, true, true)
|
update(threadId, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messageId
|
return messageId
|
||||||
@ -930,7 +930,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
groupReceiptDatabase.deleteRowsForMessage(messageId)
|
groupReceiptDatabase.deleteRowsForMessage(messageId)
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
database!!.delete(TABLE_NAME, ID_WHERE, arrayOf(messageId.toString()))
|
database!!.delete(TABLE_NAME, ID_WHERE, arrayOf(messageId.toString()))
|
||||||
val threadDeleted = get(context).threadDatabase().update(threadId, false, true)
|
val threadDeleted = get(context).threadDatabase().update(threadId, false)
|
||||||
notifyConversationListeners(threadId)
|
notifyConversationListeners(threadId)
|
||||||
notifyStickerListeners()
|
notifyStickerListeners()
|
||||||
notifyStickerPackListeners()
|
notifyStickerPackListeners()
|
||||||
@ -948,7 +948,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
argValues
|
argValues
|
||||||
)
|
)
|
||||||
|
|
||||||
val threadDeleted = get(context).threadDatabase().update(threadId, false, true)
|
val threadDeleted = get(context).threadDatabase().update(threadId, false)
|
||||||
notifyConversationListeners(threadId)
|
notifyConversationListeners(threadId)
|
||||||
notifyStickerListeners()
|
notifyStickerListeners()
|
||||||
notifyStickerPackListeners()
|
notifyStickerPackListeners()
|
||||||
@ -1145,7 +1145,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
val threadDb = get(context).threadDatabase()
|
val threadDb = get(context).threadDatabase()
|
||||||
for (threadId in threadIds) {
|
for (threadId in threadIds) {
|
||||||
val threadDeleted = threadDb.update(threadId, false, true)
|
val threadDeleted = threadDb.update(threadId, false)
|
||||||
notifyConversationListeners(threadId)
|
notifyConversationListeners(threadId)
|
||||||
}
|
}
|
||||||
notifyStickerListeners()
|
notifyStickerListeners()
|
||||||
|
@ -158,7 +158,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
|
|
||||||
long threadId = getThreadIdForMessage(id);
|
long threadId = getThreadIdForMessage(id);
|
||||||
|
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, false, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
|
|
||||||
long threadId = getThreadIdForMessage(id);
|
long threadId = getThreadIdForMessage(id);
|
||||||
|
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, false, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
ID + " = ?",
|
ID + " = ?",
|
||||||
new String[] {String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ID)))});
|
new String[] {String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ID)))});
|
||||||
|
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, false, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
foundMessage = true;
|
foundMessage = true;
|
||||||
}
|
}
|
||||||
@ -429,7 +429,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
|
|
||||||
long threadId = getThreadIdForMessage(messageId);
|
long threadId = getThreadIdForMessage(messageId);
|
||||||
|
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, true, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, true);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
long messageId = db.insert(TABLE_NAME, null, values);
|
long messageId = db.insert(TABLE_NAME, null, values);
|
||||||
|
|
||||||
if (runThreadUpdate) {
|
if (runThreadUpdate) {
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, true, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getSubscriptionId() != -1) {
|
if (message.getSubscriptionId() != -1) {
|
||||||
@ -596,7 +596,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (runThreadUpdate) {
|
if (runThreadUpdate) {
|
||||||
DatabaseComponent.get(context).threadDatabase().update(threadId, true, true);
|
DatabaseComponent.get(context).threadDatabase().update(threadId, true);
|
||||||
}
|
}
|
||||||
long lastSeen = DatabaseComponent.get(context).threadDatabase().getLastSeenAndHasSent(threadId).first();
|
long lastSeen = DatabaseComponent.get(context).threadDatabase().getLastSeenAndHasSent(threadId).first();
|
||||||
if (lastSeen < message.getSentTimestampMillis()) {
|
if (lastSeen < message.getSentTimestampMillis()) {
|
||||||
@ -656,7 +656,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
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+""});
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
boolean threadDeleted = DatabaseComponent.get(context).threadDatabase().update(threadId, false, false);
|
boolean threadDeleted = DatabaseComponent.get(context).threadDatabase().update(threadId, false);
|
||||||
return threadDeleted;
|
return threadDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,7 +676,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
ID + " IN (" + StringUtils.join(argsArray, ',') + ")",
|
ID + " IN (" + StringUtils.join(argsArray, ',') + ")",
|
||||||
argValues
|
argValues
|
||||||
);
|
);
|
||||||
boolean threadDeleted = DatabaseComponent.get(context).threadDatabase().update(threadId, false, true);
|
boolean threadDeleted = DatabaseComponent.get(context).threadDatabase().update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
return threadDeleted;
|
return threadDeleted;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ open class Storage(
|
|||||||
|
|
||||||
override fun updateThread(threadId: Long, unarchive: Boolean) {
|
override fun updateThread(threadId: Long, unarchive: Boolean) {
|
||||||
val threadDb = DatabaseComponent.get(context).threadDatabase()
|
val threadDb = DatabaseComponent.get(context).threadDatabase()
|
||||||
threadDb.update(threadId, unarchive, false)
|
threadDb.update(threadId, unarchive)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun persist(message: VisibleMessage,
|
override fun persist(message: VisibleMessage,
|
||||||
|
@ -188,6 +188,16 @@ public class ThreadDatabase extends Database {
|
|||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearSnippet(long threadId){
|
||||||
|
ContentValues contentValues = new ContentValues(1);
|
||||||
|
|
||||||
|
contentValues.put(SNIPPET, "");
|
||||||
|
|
||||||
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId + ""});
|
||||||
|
notifyConversationListListeners();
|
||||||
|
}
|
||||||
|
|
||||||
public void updateSnippet(long threadId, String snippet, @Nullable Uri attachment, long date, long type, boolean unarchive) {
|
public void updateSnippet(long threadId, String snippet, @Nullable Uri attachment, long date, long type, boolean unarchive) {
|
||||||
ContentValues contentValues = new ContentValues(4);
|
ContentValues contentValues = new ContentValues(4);
|
||||||
|
|
||||||
@ -281,7 +291,7 @@ public class ThreadDatabase extends Database {
|
|||||||
DatabaseComponent.get(context).smsDatabase().deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
DatabaseComponent.get(context).smsDatabase().deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
||||||
DatabaseComponent.get(context).mmsDatabase().deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
DatabaseComponent.get(context).mmsDatabase().deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
||||||
|
|
||||||
update(threadId, false, true);
|
update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -294,7 +304,7 @@ public class ThreadDatabase extends Database {
|
|||||||
Log.i("ThreadDatabase", "Trimming thread: " + threadId + " before :"+timestamp);
|
Log.i("ThreadDatabase", "Trimming thread: " + threadId + " before :"+timestamp);
|
||||||
DatabaseComponent.get(context).smsDatabase().deleteMessagesInThreadBeforeDate(threadId, timestamp);
|
DatabaseComponent.get(context).smsDatabase().deleteMessagesInThreadBeforeDate(threadId, timestamp);
|
||||||
DatabaseComponent.get(context).mmsDatabase().deleteMessagesInThreadBeforeDate(threadId, timestamp);
|
DatabaseComponent.get(context).mmsDatabase().deleteMessagesInThreadBeforeDate(threadId, timestamp);
|
||||||
update(threadId, false, true);
|
update(threadId, false);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,18 +732,10 @@ public class ThreadDatabase extends Database {
|
|||||||
notifyConversationListListeners();
|
notifyConversationListListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean update(long threadId, boolean unarchive, boolean shouldDeleteOnEmpty) {
|
public boolean update(long threadId, boolean unarchive) {
|
||||||
MmsSmsDatabase mmsSmsDatabase = DatabaseComponent.get(context).mmsSmsDatabase();
|
MmsSmsDatabase mmsSmsDatabase = DatabaseComponent.get(context).mmsSmsDatabase();
|
||||||
long count = mmsSmsDatabase.getConversationCount(threadId);
|
long count = mmsSmsDatabase.getConversationCount(threadId);
|
||||||
|
|
||||||
boolean shouldDeleteEmptyThread = shouldDeleteOnEmpty && possibleToDeleteThreadOnEmpty(threadId);
|
|
||||||
|
|
||||||
if (count == 0 && shouldDeleteEmptyThread) {
|
|
||||||
deleteThread(threadId);
|
|
||||||
notifyConversationListListeners();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (MmsSmsDatabase.Reader reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId))) {
|
try (MmsSmsDatabase.Reader reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId))) {
|
||||||
MessageRecord record = null;
|
MessageRecord record = null;
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
@ -748,11 +750,8 @@ public class ThreadDatabase extends Database {
|
|||||||
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (shouldDeleteEmptyThread) {
|
// for empty threads or if there is only deleted messages, show an empty snippet
|
||||||
deleteThread(threadId);
|
clearSnippet(threadId);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// todo: add empty snippet that clears existing data
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -800,11 +799,6 @@ public class ThreadDatabase extends Database {
|
|||||||
return setLastSeen(threadId, lastSeenTime);
|
return setLastSeen(threadId, lastSeenTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean possibleToDeleteThreadOnEmpty(long threadId) {
|
|
||||||
Recipient threadRecipient = getRecipientForThreadId(threadId);
|
|
||||||
return threadRecipient != null && !threadRecipient.isCommunityRecipient();
|
|
||||||
}
|
|
||||||
|
|
||||||
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
|
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
|
||||||
if (messageRecord.isMms()) {
|
if (messageRecord.isMms()) {
|
||||||
MmsMessageRecord record = (MmsMessageRecord) messageRecord;
|
MmsMessageRecord record = (MmsMessageRecord) messageRecord;
|
||||||
|
Loading…
Reference in New Issue
Block a user