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

fix double subscriptions

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