mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Perform sync when permissions are already in place, but sync hasn't been performed yet
This commit is contained in:
@@ -27,6 +27,7 @@ import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.Realm
|
||||
import manager.KeyManager
|
||||
import mapper.CursorToContact
|
||||
import mapper.CursorToConversation
|
||||
import mapper.CursorToMessage
|
||||
@@ -36,6 +37,7 @@ import model.Conversation
|
||||
import model.Message
|
||||
import model.MmsPart
|
||||
import model.Recipient
|
||||
import model.SyncLog
|
||||
import util.extensions.insertOrUpdate
|
||||
import util.extensions.map
|
||||
import util.tryOrNull
|
||||
@@ -50,6 +52,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
private val cursorToMessage: CursorToMessage,
|
||||
private val cursorToRecipient: CursorToRecipient,
|
||||
private val cursorToContact: CursorToContact,
|
||||
private val keys: KeyManager,
|
||||
private val rxPrefs: RxSharedPreferences
|
||||
) : SyncRepository {
|
||||
|
||||
@@ -83,6 +86,8 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
realm.delete(MmsPart::class.java)
|
||||
realm.delete(Recipient::class.java)
|
||||
|
||||
keys.reset()
|
||||
|
||||
|
||||
// Sync messages
|
||||
cursorToMessage.getMessagesCursor()?.use { messageCursor ->
|
||||
@@ -119,6 +124,8 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
realm.insertOrUpdate(recipients)
|
||||
}
|
||||
|
||||
|
||||
realm.insert(SyncLog())
|
||||
realm.commitTransaction()
|
||||
realm.close()
|
||||
|
||||
|
||||
@@ -19,20 +19,17 @@
|
||||
package interactor
|
||||
|
||||
import io.reactivex.Flowable
|
||||
import manager.KeyManager
|
||||
import repository.SyncRepository
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class SyncMessages @Inject constructor(
|
||||
private val syncManager: SyncRepository,
|
||||
private val keys: KeyManager
|
||||
private val syncManager: SyncRepository
|
||||
) : Interactor<Unit>() {
|
||||
|
||||
override fun buildObservable(params: Unit): Flowable<Long> {
|
||||
return Flowable.just(System.currentTimeMillis())
|
||||
.doOnNext { keys.reset() }
|
||||
.doOnNext { syncManager.syncMessages() }
|
||||
.map { startTime -> System.currentTimeMillis() - startTime }
|
||||
.map { elapsed -> TimeUnit.MILLISECONDS.toSeconds(elapsed) }
|
||||
|
||||
@@ -35,8 +35,10 @@ import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.realm.Realm
|
||||
import manager.PermissionManager
|
||||
import manager.RatingManager
|
||||
import model.SyncLog
|
||||
import repository.MessageRepository
|
||||
import repository.SyncRepository
|
||||
import util.extensions.removeAccents
|
||||
@@ -83,6 +85,14 @@ class MainViewModel @Inject constructor(
|
||||
// Migrate the preferences from 2.7.3
|
||||
migratePreferences.execute(Unit)
|
||||
|
||||
|
||||
// If we have all permissions and we've never run a sync, run a sync. This will be the case
|
||||
// when upgrading from 2.7.3, or if the app's data was cleared
|
||||
val lastSync = Realm.getDefaultInstance().use { realm -> realm.where(SyncLog::class.java)?.max("date") ?: 0 }
|
||||
if (lastSync == 0 && permissionManager.isDefaultSms() && permissionManager.hasSmsAndContacts()) {
|
||||
syncMessages.execute(Unit)
|
||||
}
|
||||
|
||||
ratingManager.addSession()
|
||||
markAllSeen.execute(Unit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user