mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add chat folder support to storage service.
This commit is contained in:
@@ -176,9 +176,10 @@ public class ApplicationMigrations {
|
||||
static final int AVATAR_COLOR_MIGRATION_JOB = 132;
|
||||
static final int DUPLICATE_E164_FIX_2 = 133;
|
||||
static final int E164_FORMATTING = 134;
|
||||
static final int CHAT_FOLDER_STORAGE_SYNC = 135;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 134;
|
||||
public static final int CURRENT_VERSION = 135;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -813,6 +814,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.E164_FORMATTING, new E164FormattingMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.CHAT_FOLDER_STORAGE_SYNC) {
|
||||
jobs.put(Version.CHAT_FOLDER_STORAGE_SYNC, new SyncChatFoldersMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.readToList
|
||||
import org.signal.core.util.requireLong
|
||||
import org.signal.core.util.select
|
||||
import org.thoughtcrime.securesms.database.ChatFolderTables
|
||||
import org.thoughtcrime.securesms.database.ChatFolderTables.ChatFolderTable
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
|
||||
/**
|
||||
* Marks all chat folders as needing to be synced for storage service.
|
||||
*/
|
||||
internal class SyncChatFoldersMigrationJob(parameters: Parameters = Parameters.Builder().build()) : MigrationJob(parameters) {
|
||||
companion object {
|
||||
const val KEY = "SyncChatFoldersMigrationJob"
|
||||
|
||||
private val TAG = Log.tag(SyncChatFoldersMigrationJob::class)
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
if (SignalStore.account.aci == null) {
|
||||
Log.w(TAG, "Self not available yet.")
|
||||
return
|
||||
}
|
||||
|
||||
val folderIds = SignalDatabase.chatFolders.getAllFoldersForSync()
|
||||
|
||||
SignalDatabase.chatFolders.markNeedsSync(folderIds)
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
private fun ChatFolderTables.getAllFoldersForSync(): List<Long> {
|
||||
return readableDatabase
|
||||
.select(ChatFolderTable.ID)
|
||||
.from(ChatFolderTable.TABLE_NAME)
|
||||
.run()
|
||||
.readToList { cursor -> cursor.requireLong(ChatFolderTable.ID) }
|
||||
}
|
||||
|
||||
class Factory : Job.Factory<SyncChatFoldersMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): SyncChatFoldersMigrationJob {
|
||||
return SyncChatFoldersMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user