Commit 0a690861 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

up database version due subscriptions table changes

parent 3c99913b
......@@ -50,6 +50,7 @@ class AuthContractModule @Inject constructor(
override fun currentUser(): Observable<UserEntity> =
local.recentUser()
.doOnNext { Timber.w("recentUSer: $it") }
.flatMap{ when(it){
is UserState.NotAuthenticated -> throw CustomApiException.NotAuthorizedException()
is UserState.Authenticated -> db.fetchUser(it.uuid.toInt())
......
......@@ -21,7 +21,7 @@ const val ESTATES_CACHE_LIMIT_SECONDS_INACTIVE = 200L
const val FILES_CACHE_LIMIT_SIZE = 10000
const val FILES_CACHE_LIMIT_SECONDS_INACTIVE = 60L
const val DATABASE_VERSION = 11
const val DATABASE_VERSION = 12
@Module
abstract class AppModule{
......
......@@ -13,5 +13,5 @@ interface AuthContract {
fun signIn(email:String,password:String) : Observable<AuthInfoModel>
fun signOut() : Completable
fun validateAuthState(): Observable<Boolean>
fun currentUser(): Observable<UserEntity>
fun currentUser(): Observable<UserEntity>
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ import com.biganto.visual.roompark.domain.model.SubscriptionTopic
import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Observable
import io.reactivex.rxkotlin.Observables
import timber.log.Timber
import javax.inject.Inject
//import io.reactivex.rxkotlin
......@@ -47,6 +48,7 @@ class SubscriptionUseCase @Inject constructor(
fun getSubscriptions(topic: SubscriptionTopic): Observable<SubscriptionModel> =
auth.currentUser()
.map {
Timber.w("user is : $it")
var sub = it.subscriptions
?.firstOrNull { it.topic == topic.topicName && it.number == topic.topicId }
if (sub == null) {
......@@ -56,6 +58,7 @@ class SubscriptionUseCase @Inject constructor(
sub.setNumber(topic.topicId)
sub.setState(false)
}
Timber.w("sub is : $sub")
subscription.saveSubscribeState(sub as SubscriptionEntity).blockingFirst()
}
.map(::fromEntity)
......
......@@ -38,6 +38,7 @@ class ArticlesScreenPresenter @Inject constructor(
Timber.d("feedId : $feedId")
val onSubChecked = intent(ArticlesScreen::feedSubscription)
.filter { restoreModel.sub!=null }
.flatMap { newState ->
interactor.switchSubscription(restoreModel.sub!!,newState)
.andThen(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.SubscriptionStatus(newState)))
......@@ -61,6 +62,7 @@ class ArticlesScreenPresenter @Inject constructor(
.onErrorReturn(::parseError)
val fetchSubscription = interactor.getSubscriptions(feedId)
.doOnNext { Timber.w("got smthng: $it") }
.doAfterNext { restoreModel.sub = it }
.map<ArticlesScreenViewState> { ArticlesScreenViewState.SubscriptionStatus(it.state) }
.startWith(Observable.just<ArticlesScreenViewState>(ArticlesScreenViewState.Idle()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment