Fix issue where bulk-archive wasn't triggering a storage sync.

Also took the opportunity to consolidate our archive code to reduce
duplication.
This commit is contained in:
Greyson Parrelli 2021-05-10 11:18:45 -04:00
parent d3431d227b
commit 877c03e6a1

View file

@ -605,35 +605,6 @@ public class ThreadDatabase extends Database {
return false; return false;
} }
public void setArchived(@NonNull RecipientId recipientId, boolean status) {
setArchived(Collections.singletonMap(recipientId, status));
}
public void setArchived(@NonNull Map<RecipientId, Boolean> status) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
db.beginTransaction();
try {
String query = RECIPIENT_ID + " = ?";
for (Map.Entry<RecipientId, Boolean> entry : status.entrySet()) {
ContentValues values = new ContentValues(2);
if (entry.getValue()) {
values.put(PINNED, "0");
}
values.put(ARCHIVED, entry.getValue() ? "1" : "0");
db.update(TABLE_NAME, values, query, new String[] { entry.getKey().serialize() });
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
notifyConversationListListeners();
}
}
public void setArchived(Set<Long> threadIds, boolean archive) { public void setArchived(Set<Long> threadIds, boolean archive) {
SQLiteDatabase db = databaseHelper.getReadableDatabase(); SQLiteDatabase db = databaseHelper.getReadableDatabase();
@ -650,10 +621,14 @@ public class ThreadDatabase extends Database {
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(threadId)); db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(threadId));
} }
List<RecipientId> recipientIds = getRecipientIdsForThreadIds(threadIds);
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(recipientIds);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
notifyConversationListListeners(); notifyConversationListListeners();
StorageSyncHelper.scheduleSyncForDataChange();
} }
} }
@ -874,34 +849,11 @@ public class ThreadDatabase extends Database {
} }
public void archiveConversation(long threadId) { public void archiveConversation(long threadId) {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); setArchived(Collections.singleton(threadId), true);
ContentValues contentValues = new ContentValues(1);
contentValues.put(PINNED, 0);
contentValues.put(ARCHIVED, 1);
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId + ""});
notifyConversationListListeners();
Recipient recipient = getRecipientForThreadId(threadId);
if (recipient != null) {
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(recipient.getId());
StorageSyncHelper.scheduleSyncForDataChange();
}
} }
public void unarchiveConversation(long threadId) { public void unarchiveConversation(long threadId) {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); setArchived(Collections.singleton(threadId), false);
ContentValues contentValues = new ContentValues(1);
contentValues.put(ARCHIVED, 0);
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId + ""});
notifyConversationListListeners();
Recipient recipient = getRecipientForThreadId(threadId);
if (recipient != null) {
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(recipient.getId());
StorageSyncHelper.scheduleSyncForDataChange();
}
} }
public void setLastSeen(long threadId) { public void setLastSeen(long threadId) {