Commit c9b65d19 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

dont remove default subscriptions on result

parent 1ebfa604
...@@ -41,15 +41,16 @@ class AuthContractModule @Inject constructor( ...@@ -41,15 +41,16 @@ class AuthContractModule @Inject constructor(
.flatMap{ db.upsertUser(it) } .flatMap{ db.upsertUser(it) }
.flatMap {user -> .flatMap {user ->
val userSubs = user.subscriptions?.map { it as SubscriptionEntity } val userSubs = user.subscriptions?.map { it as SubscriptionEntity }
var newSubs = defaultSubsList(user)
if (!userSubs.isNullOrEmpty()){ if (!userSubs.isNullOrEmpty()){
val newSubs = defaultSubsList(user).filter {defSub -> newSubs = newSubs.filter {defSub ->
!userSubs.map { it.topic }.contains(defSub.topic) !userSubs.map { it.topic }.contains(defSub.topic)
}.toList() }.toList()
return@flatMap db.upsert(newSubs)
.toObservable()
.flatMap { db.refreshUser(user) }
} }
else return@flatMap Observable.just(user) if (newSubs.isNullOrEmpty()) return@flatMap Observable.just(user)
return@flatMap db.upsert(newSubs)
.toObservable()
.flatMap { db.refreshUser(user) }
} }
.doOnNext{ Timber.d("user id: ${it.uuid}")} .doOnNext{ Timber.d("user id: ${it.uuid}")}
.doOnNext { local.setRecentUser(it.uuid.toString()).blockingAwait() } .doOnNext { local.setRecentUser(it.uuid.toString()).blockingAwait() }
...@@ -75,7 +76,7 @@ class AuthContractModule @Inject constructor( ...@@ -75,7 +76,7 @@ class AuthContractModule @Inject constructor(
} }
private fun defaultSubsList(owner:UserEntity) = arrayListOf( private fun defaultSubsList(owner:UserEntity) : List<SubscriptionEntity> = arrayListOf(
SubscriptionEntity().apply { SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_1().topicName) setTopic(SubscriptionTopic.Progress_1().topicName)
setOwner(owner) setOwner(owner)
...@@ -89,7 +90,7 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf( ...@@ -89,7 +90,7 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf(
,SubscriptionEntity().apply { ,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_3().topicName) setTopic(SubscriptionTopic.Progress_3().topicName)
setOwner(owner) setOwner(owner)
setState(false) setState(true)
} }
,SubscriptionEntity().apply { ,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Progress_kindergarden().topicName) setTopic(SubscriptionTopic.Progress_kindergarden().topicName)
...@@ -99,7 +100,7 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf( ...@@ -99,7 +100,7 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf(
,SubscriptionEntity().apply { ,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.News().topicName) setTopic(SubscriptionTopic.News().topicName)
setOwner(owner) setOwner(owner)
setState(false) setState(true)
} }
,SubscriptionEntity().apply { ,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Blog().topicName) setTopic(SubscriptionTopic.Blog().topicName)
...@@ -109,6 +110,6 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf( ...@@ -109,6 +110,6 @@ private fun defaultSubsList(owner:UserEntity) = arrayListOf(
,SubscriptionEntity().apply { ,SubscriptionEntity().apply {
setTopic(SubscriptionTopic.Construction().topicName) setTopic(SubscriptionTopic.Construction().topicName)
setOwner(owner) setOwner(owner)
setState(false) setState(true)
} }
) )
\ No newline at end of file
...@@ -80,11 +80,15 @@ class SubscriptionRepository @Inject constructor( ...@@ -80,11 +80,15 @@ class SubscriptionRepository @Inject constructor(
cachedSub.setState(apiSub.active) cachedSub.setState(apiSub.active)
newSubList.add(cachedSub) newSubList.add(cachedSub)
} }
userSubs?.filter { !newSubList.map { s ->s.id }.contains(it.id) }?.toList()
?.let { userSubs?.filter { !newSubList.map { s ->s.id }.contains(it.id) }?.forEach {
Timber.w("to delete; ${it.size}") (it as SubscriptionEntity).setState(false)
db.deleteSubscriptions(it) }
}
userSubs?.forEach {s ->
if (newSubList.firstOrNull { s.topic == it.topic && s.number == it.number} == null)
newSubList.add(s as SubscriptionEntity)
}
return db.upsert(newSubList) return db.upsert(newSubList)
.map {list -> list.map { .map {list -> list.map {
......
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