mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-25 15:16:01 +00:00
Fixes #1544
This commit is contained in:
parent
fd8662129d
commit
c331071d1e
4 changed files with 20 additions and 7 deletions
|
|
@ -126,7 +126,7 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
|
|||
}
|
||||
|
||||
override fun retrieveGroup(id: String): Flowable<Group> {
|
||||
return Flowable.zip(apiClient.getGroup(id).doOnNext { localRepository.saveSyncronous(it) }, retrieveGroupChat(id)
|
||||
return Flowable.zip(apiClient.getGroup(id).doOnNext { localRepository.saveGroup(it) }, retrieveGroupChat(id)
|
||||
.toFlowable(),
|
||||
{ group, _ ->
|
||||
group
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ interface SocialLocalRepository : BaseLocalRepository {
|
|||
fun getGroups(type: String): Flowable<RealmResults<Group>>
|
||||
|
||||
fun getGroup(id: String): Flowable<Group>
|
||||
fun saveGroup(group: Group)
|
||||
|
||||
fun getGroupChat(groupId: String): Flowable<RealmResults<ChatMessage>>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.habitrpg.android.habitica.data.local.implementation
|
||||
|
||||
import com.habitrpg.android.habitica.data.local.SocialLocalRepository
|
||||
import com.habitrpg.android.habitica.models.inventory.Quest
|
||||
import com.habitrpg.android.habitica.models.members.Member
|
||||
import com.habitrpg.android.habitica.models.social.*
|
||||
import com.habitrpg.android.habitica.models.user.ContributorInfo
|
||||
|
|
@ -48,6 +49,16 @@ class RealmSocialLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm)
|
|||
}
|
||||
}
|
||||
|
||||
override fun saveGroup(group: Group) {
|
||||
saveSyncronous(group)
|
||||
if (group.quest == null) {
|
||||
val existingQuest = realm.where(Quest::class.java).equalTo("id", group.id).findFirst()
|
||||
executeTransaction {
|
||||
existingQuest?.deleteFromRealm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun saveInboxMessages(userID: String, recipientID: String, messages: List<ChatMessage>, page: Int) {
|
||||
messages.forEach { it.userID = userID }
|
||||
save(messages)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ import java.util.*
|
|||
class WorldStateSerialization: JsonDeserializer<WorldState> {
|
||||
|
||||
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): WorldState {
|
||||
val worldBossObject = json?.asJsonObject?.get("worldBoss")?.asJsonObject
|
||||
val state = WorldState()
|
||||
val obj = json?.asJsonObject ?: return state
|
||||
val worldBossObject = obj.get("worldBoss")?.asJsonObject
|
||||
if (worldBossObject != null) {
|
||||
if (worldBossObject.has("active") && !worldBossObject["active"].isJsonNull) {
|
||||
state.worldBossActive = worldBossObject["active"].asBoolean
|
||||
|
|
@ -48,17 +49,17 @@ class WorldStateSerialization: JsonDeserializer<WorldState> {
|
|||
}
|
||||
}
|
||||
|
||||
state.npcImageSuffix = json?.asJsonObject.getAsString("npcImageSuffix")
|
||||
state.npcImageSuffix = obj.getAsString("npcImageSuffix")
|
||||
|
||||
try {
|
||||
if (json?.asJsonObject?.has("currentEvent") == true && json.asJsonObject?.get("currentEvent")?.isJsonObject == true) {
|
||||
val event = json.asJsonObject?.getAsJsonObject("currentEvent")
|
||||
if (obj.has("currentEvent") == true && obj.get("currentEvent")?.isJsonObject == true) {
|
||||
val event = obj.getAsJsonObject("currentEvent")
|
||||
if (event != null) {
|
||||
state.currentEvent = context?.deserialize(event, WorldStateEvent::class.java)
|
||||
}
|
||||
if (json.asJsonObject.has("currentEventList")) {
|
||||
if (obj.has("currentEventList")) {
|
||||
val events = RealmList<WorldStateEvent>()
|
||||
for (element in json.asJsonObject.getAsJsonArray("currentEventList")) {
|
||||
for (element in obj.getAsJsonArray("currentEventList")) {
|
||||
context?.deserialize<WorldStateEvent>(element, WorldStateEvent::class.java)?.let { events.add(it) }
|
||||
}
|
||||
state.events = events
|
||||
|
|
|
|||
Loading…
Reference in a new issue