Commit 3d63a790 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

subscriptions token fix;

subscriptions new api model
parent 9b458a8a
......@@ -100,19 +100,10 @@ class StartToursDownloadingDialogController : Controller {
view.findViewById<Button>(R.id.alert_ok_button)
.clicks()
.debounce(200, TimeUnit.MILLISECONDS)
.observeOn(
Schedulers.io())
.flatMap{ downloader.startToursDownloading()
// .subscribeOn(Schedulers.computation())
.doOnComplete { Timber.d(" C ") }
}
.doOnComplete { Timber.d(" X ") }
// .subscribeOn(AndroidSchedulers.mainThread())
.doOnComplete { Timber.d(" Xss ") }
.observeOn(Schedulers.io())
.flatMap{ downloader.startToursDownloading()}
.observeOn(AndroidSchedulers.mainThread())
.subscribe ({
Timber.d(" SUBSCRIBER ")
snackbar.showSnackBar(R.string.download_all_tours_start_snackbar_message)
handleBack()
},{
......
......@@ -25,8 +25,6 @@ import javax.inject.Inject
*/
//
const val TEST_DEAL_TOKEN =
"183|PQZi0LmaYswPmFHcLb0pHITkg_7aJNC4x2IIC90kbRKE1GBt2m48tdi-1jb9jo9MYoxCGyvJtDy3ret7_nAoAg=="
class EstateRepository @Inject constructor(
local: ILocalStore,
......@@ -53,7 +51,7 @@ class EstateRepository @Inject constructor(
.doOnNext{ db.refreshUser(user) }
override fun fetchDeals(user:UserEntity): Observable<List<EstateEntity>> =
api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken)
api.getDeals(user.authToken)//api.getDeals(user.authToken)
.doOnError(Timber::e)
.map { List(it.size){index -> fromRaw(it[index],user)} }
.flatMap(db::upsertDeals)
......@@ -126,7 +124,7 @@ class EstateRepository @Inject constructor(
}
.doOnError (Timber::e)
.flatMap { user ->
api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken)
api.getDeals(user.authToken)//api.getDeals(user.authToken)
.doOnError(Timber::e)
.map { List(it.size){index -> fromRaw(it[index],user)} }
.doOnNext(db::blockingUpsert)
......
package com.biganto.visual.roompark.data.data_provider
import com.biganto.visual.roompark.data.repository.api.room_park.IRoomParkApi
import com.biganto.visual.roompark.data.repository.api.room_park.raw.SubscriptionStatusRaw
import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.model.SubscriptionEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.UserEntity
......@@ -37,23 +38,49 @@ class SubscriptionRepository @Inject constructor(
subInnerId:Int?,
topic: String,
topic_id: String?,
nuewState:Boolean
newState:Boolean
): Observable<SubscriptionEntity> {
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)
sub.setTopic(topic)
sub.setNumber(topic_id)
val userSubs = userEntity.subscriptions
val sub = subInnerId?.let { id ->
userEntity.subscriptions?.firstOrNull { sub -> sub.id == id } as SubscriptionEntity?
}?:SubscriptionEntity()
.apply {
setOwner(userEntity)
setTopic(topic)
setNumber(topic_id)
}
(sub as SubscriptionEntity).setState(nuewState)
Timber.d("before save _subsc: $sub / ${sub?.id}")
sub.setState(newState)
return db.saveSubscription(sub)
}
fun saveSubscribtions(
userEntity: UserEntity,
apiSubs: List<SubscriptionStatusRaw>
): Observable<SubscriptionEntity> {
val userSubs = userEntity.subscriptions
val newSubList = mutableListOf<SubscriptionEntity>()
apiSubs.forEach { apiSub ->
val cachedSub =
userSubs?.firstOrNull { s -> s.topic == apiSub.topic && s.number == apiSub.estate_id }
as SubscriptionEntity?
?: SubscriptionEntity()
.apply {
setOwner(userEntity)
setTopic(apiSub.topic)
setNumber(apiSub.estate_id)
}
cachedSub.setState(apiSub.state)
newSubList.add(cachedSub)
}
userSubs?.let { db.deleteSubscriptions(it) }
return db.upsert(newSubList).map { it as SubscriptionEntity }.toObservable()
}
override fun subscribeTopic(
user:UserEntity,
subInnerId:Int,
......@@ -61,14 +88,13 @@ class SubscriptionRepository @Inject constructor(
topic: String,
topic_id: String?
): Completable = api.subscribeTopic(
userToken = if (topic_id!=null) TEST_DEAL_TOKEN else user.authToken,
userToken = user.authToken,
deviceToken = deviceToken
,topicName = topic
,topicId = topic_id)
.flatMapCompletable {
if (it.status == SUBSCRIPTION_RESULT_STATUS){
saveSubscribeState(user,subInnerId,topic,topic_id,true)
.doOnNext { Timber.d("zzz $it") }
.ignoreElements()
}
else error("Error subscription state!")
......@@ -83,7 +109,7 @@ class SubscriptionRepository @Inject constructor(
topic_id: String?
): Completable =
api.unSuubscribeTopic(
userToken = if (topic_id!=null) TEST_DEAL_TOKEN else user.authToken,
userToken = user.authToken,
deviceToken = deviceToken
,topicName = topic
,topicId = topic_id)
......
......@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L
private const val WRITE_SECONDS=120L
private const val READ_SECONDS=120L
val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.NONE
val INTERCEPT_LOG_LEVEL = HttpLoggingInterceptor.Level.BODY
@Module
class RetrofitModule{
......
package com.biganto.visual.roompark.data.repository.api.room_park.raw
import com.google.gson.annotations.Expose
import java.util.*
/**
......@@ -13,7 +14,17 @@ data class AuthRaw(
val name:String
)
data class StatusResponse(val status:String)
data class StatusResponse(
val status:String,
val subscriptions:List<SubscriptionStatusRaw>?
)
data class SubscriptionStatusRaw(
val topic:String,
val estate_id: String,
@Expose
val state: Boolean = true
)
data class DealRaw(
val id:String,
......
......@@ -77,4 +77,5 @@ interface IDb {
fun refreshEstatesWithTours(): Completable
fun upsertEstates(entity: List<EstateEntity>): Observable<Iterable<EstateEntity>>?
fun upsertDeals(entity: List<DealEntity>): Observable<Iterable<DealEntity>>
fun deleteSubscriptions(entities: List<Subscription>)
}
\ No newline at end of file
......@@ -415,6 +415,9 @@ class RequeryRepository @Inject constructor(
override fun deleteTourPreview(entity: TourPreviewEntity) = deleteBlocking(entity)
override fun deleteSubscriptions(entities: List<Subscription>) =
deleteBlocking(entities)
override fun deleteTourPreview(id:String) = store
.delete(TourPreview::class)
......
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