Commit 9c1dc92c authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix double subscriptions

parent 55509395
......@@ -42,6 +42,7 @@ class SubscriptionRepository @Inject constructor(
var sub = subInnerId?.let {id ->
userEntity.subscriptions?.firstOrNull { sub -> sub.id == id }
}
Timber.d("before nullch _subsc: $sub / ${sub?.id}")
if (sub == null) {
sub = SubscriptionEntity()
sub.setOwner(userEntity)
......@@ -49,8 +50,8 @@ class SubscriptionRepository @Inject constructor(
sub.setNumber(topic_id)
}
(sub as SubscriptionEntity).setState(nuewState)
return db.saveSubscription(sub).toObservable()
Timber.d("before save _subsc: $sub / ${sub?.id}")
return db.saveSubscription(sub)
}
override fun subscribeTopic(
......@@ -64,10 +65,11 @@ class SubscriptionRepository @Inject constructor(
deviceToken = deviceToken
,topicName = topic
,topicId = topic_id)
.doOnNext { Timber.d("UUUUUUUU $it") }
.flatMapCompletable {
if (it.status == SUBSCRIPTION_RESULT_STATUS){
saveSubscribeState(user,subInnerId,topic,topic_id,true).ignoreElements()
saveSubscribeState(user,subInnerId,topic,topic_id,true)
.doOnNext { Timber.d("zzz $it") }
.ignoreElements()
}
else error("Error subscription state!")
}
......@@ -88,7 +90,9 @@ class SubscriptionRepository @Inject constructor(
.doOnNext { Timber.d("$it") }
.flatMapCompletable {
if (it.status == SUBSCRIPTION_RESULT_STATUS){
saveSubscribeState(user,subInnerId,topic,topic_id,false).ignoreElements()
saveSubscribeState(user,subInnerId,topic,topic_id,false)
.doOnNext { Timber.d("zz -z $it") }
.ignoreElements()
}
else error("Error subscription state!")
}
......
......@@ -16,7 +16,7 @@ import io.requery.reactivex.ReactiveScalar
* Created by Vladislav Bogdashkin on 29.10.2019.
*/
interface IDb {
fun upsertUser(entity: UserEntity): Observable<UserEntity>?
fun upsertUser(entity: UserEntity): Observable<UserEntity>
fun <T : Persistable> upsert(entity: T): Single<T>
fun <T : List<Persistable>> upsert(entity: T): Single<Iterable<Persistable>>
fun fetchFeeds(): Observable<FeedEntity>
......@@ -39,7 +39,7 @@ interface IDb {
fun fetchEstateByNumber(building: Int, number: String): ReactiveResult<EstateEntity>
fun setArticleReadState(id: Int, state: Boolean): Completable
fun setDealReadState(id: String, state: Boolean): Completable
fun saveSubscription(subscription: SubscriptionEntity): Single<SubscriptionEntity>
fun saveSubscription(subscription: SubscriptionEntity): Observable<SubscriptionEntity>
fun getSubscription(id: Int): ReactiveResult<SubscriptionEntity>
fun deleteTourPreview(id: String): Int?
fun deleteTourPreview(entity: TourPreviewEntity)
......@@ -53,7 +53,7 @@ interface IDb {
fun upsertFileEntity(entity: FileEntity): Observable<FileEntity>
fun flowableFileEntityes(uris: List<RevisionString>): Flowable<FileEntity>
fun getDownloadedSumFileEntityes(uris: List<RevisionString>): Long
fun fetchTouresWithStates(states: List<DownloadState>): MutableList<TourPreviewEntity>?
fun fetchTouresWithStates(states: List<DownloadState>): MutableList<TourPreviewEntity>
fun fetchFileEntityes(uris: List<RevisionString>): MutableList<FileEntity>
fun pushFileEntities(uris: List<FileEntity>): Observable<Iterable<FileEntity>>
fun getFileEntity(uri: RevisionString): ReactiveResult<FileEntity>
......
......@@ -182,8 +182,11 @@ class RequeryRepository @Inject constructor(
.single()
.ignoreElement()
override fun saveSubscription(subscription:SubscriptionEntity) =
store.upsert(subscription)
override fun saveSubscription(subscription:SubscriptionEntity)
: Observable<SubscriptionEntity> = store.upsert(subscription)
.toObservable()
.doOnNext { store.refresh(subscription.owner).blockingGet() }
override fun getSubscription(id:Int): ReactiveResult<SubscriptionEntity> =
store.select(SubscriptionEntity::class)
......
......@@ -92,7 +92,9 @@ class SubscriptionUseCase @Inject constructor(
sub.setState(false)
}
Timber.w("sub is : $sub")
subscription.saveSubscribeState(sub as SubscriptionEntity).blockingFirst()
subscription.saveSubscribeState(sub as SubscriptionEntity)
.doOnNext { Timber.d("zzz blocking $it") }
.blockingFirst()
}
.map(::fromEntity)
}
......
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