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