fix opening guilds. Fixes #1185

This commit is contained in:
Phillip Thelen 2019-06-13 08:14:33 +02:00
parent 202e85dcc9
commit 15f6052bdb
4 changed files with 19 additions and 17 deletions

View file

@ -7,8 +7,8 @@ import io.reactivex.Single
fun <S, T : Optional<S>> Flowable<T>.filterOptionalDoOnEmpty(function: () -> Unit): Flowable<S> {
return this.filter { !it.isEmpty }
.doOnNext { function() }
return this.doOnNext { if (it.isEmpty) function() }
.filter { !it.isEmpty }
.map { it.value }
}
@ -18,8 +18,8 @@ fun <S, T : Optional<S>> Flowable<T>.filterMapEmpty(): Flowable<S> {
}
fun <S, T : Optional<S>> Observable<T>.filterOptionalDoOnEmpty(function: () -> Unit): Observable<S> {
return this.filter { !it.isEmpty }
.doOnNext { function() }
return this.doOnNext { if (it.isEmpty) function() }
.filter { !it.isEmpty }
.map { it.value }
}
@ -29,8 +29,8 @@ fun <S, T : Optional<S>> Observable<T>.filterMapEmpty(): Observable<S> {
}
fun <S, T : Optional<S>> Single<T>.filterOptionalDoOnEmpty(function: () -> Unit): Maybe<S> {
return this.filter { !it.isEmpty }
.doAfterSuccess { function() }
return this.doAfterSuccess { if (it.isEmpty) function() }
.filter { !it.isEmpty }
.map { it.value }
}
@ -40,8 +40,8 @@ fun <S, T : Optional<S>> Single<T>.filterMapEmpty(): Maybe<S> {
}
fun <S, T : Optional<S>> Maybe<T>.filterOptionalDoOnEmpty(function: () -> Unit): Maybe<S> {
return this.filter { !it.isEmpty }
.doAfterSuccess { function() }
return this.doAfterSuccess { if (it.isEmpty) function() }
.filter { !it.isEmpty }
.map { it.value }
}

View file

@ -66,6 +66,8 @@ class GuildFragment : BaseMainFragment() {
if (viewModel.groupID == "f2db2a7f-13c5-454d-b3ee-ea1f5089e601") {
context?.let { FirebaseAnalytics.getInstance(it).logEvent("opened_no_party_guild", null) }
}
viewModel.retrieveGroup { }
}
private fun setFragments() {

View file

@ -24,7 +24,6 @@ import io.realm.RealmResults
import java.util.*
import javax.inject.Inject
enum class GroupViewType(internal val order: String) {
PARTY("party"),
GUILD("guild"),
@ -53,6 +52,7 @@ open class GroupViewModel : BaseViewModel() {
}
protected val groupIDSubject = BehaviorSubject.create<Optional<String>>()
val groupIDFlowable = groupIDSubject.toFlowable(BackpressureStrategy.BUFFER)
var gotNewMessages: Boolean = false
init {
@ -95,7 +95,7 @@ open class GroupViewModel : BaseViewModel() {
fun getIsMemberData(): LiveData<Boolean?> = isMemberData
private fun loadGroupFromLocal() {
disposable.add(groupIDSubject.toFlowable(BackpressureStrategy.LATEST)
disposable.add(groupIDFlowable
.filterOptionalDoOnEmpty { group.value = null }
.flatMap { socialRepository.getGroup(it) }
.observeOn(AndroidSchedulers.mainThread())
@ -103,8 +103,8 @@ open class GroupViewModel : BaseViewModel() {
}
private fun loadLeaderFromLocal() {
disposable.add(groupIDSubject.toFlowable(BackpressureStrategy.LATEST)
.filterOptionalDoOnEmpty { group.value = null }
disposable.add(groupIDFlowable
.filterOptionalDoOnEmpty { leader.value = null }
.flatMap { socialRepository.getGroup(it) }
.distinctUntilChanged { group1, group2 -> group1.id == group2.id }
.flatMap { socialRepository.getMember(it.leaderID) }
@ -113,8 +113,8 @@ open class GroupViewModel : BaseViewModel() {
}
private fun loadMembershipFromLocal() {
disposable.add(groupIDSubject.toFlowable(BackpressureStrategy.LATEST)
.filterOptionalDoOnEmpty { group.value = null }
disposable.add(groupIDFlowable
.filterOptionalDoOnEmpty { isMemberData.value = null }
.flatMap { socialRepository.getGroupMemberships() }
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
@ -123,13 +123,13 @@ open class GroupViewModel : BaseViewModel() {
}
fun getChatMessages(): Flowable<RealmResults<ChatMessage>> {
return groupIDSubject.toFlowable(BackpressureStrategy.BUFFER)
return groupIDFlowable
.filterMapEmpty()
.flatMapMaybe { socialRepository.getGroupChat(it).firstElement() }
}
fun retrieveGroup(function: (() -> Unit)?) {
disposable.add(socialRepository.retrieveGroup("party")
disposable.add(socialRepository.retrieveGroup(groupID ?: "")
.filter { groupViewType == GroupViewType.PARTY }
.flatMap { group1 ->
socialRepository.retrieveGroupMembers(group1.id, true)

View file

@ -258,7 +258,7 @@ open class NotificationsViewModel : BaseViewModel() {
}
}
fun clickGroupInvitation(notification: Notification, navController: MainNavigationController) {
private fun clickGroupInvitation(notification: Notification, navController: MainNavigationController) {
when (notification.type) {
Notification.Type.GUILD_INVITATION.type -> {
val bundle = Bundle()