From 96ae430eec7bd75403e42ad098641134d6b8e0cf Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Fri, 16 Feb 2024 12:25:28 +0100 Subject: [PATCH] Improve liking --- .../android/habitica/api/ApiService.kt | 2 +- .../habitica/api/GSonFactoryCreator.java | 1 + .../implementation/SocialRepositoryImpl.kt | 2 +- .../RealmSocialLocalRepository.kt | 19 +++++++++++++------ .../challenges/ChallengeDetailFragment.kt | 3 +++ .../habitica/helpers/ExceptionHandler.kt | 6 +----- fastlane/changelog.txt | 11 +++++------ version.properties | 2 +- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/api/ApiService.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/api/ApiService.kt index d757e7bba3..9768cebcb0 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/api/ApiService.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/api/ApiService.kt @@ -486,5 +486,5 @@ interface ApiService { suspend fun retrievePartySeekingUsers(@Query("page") page: Int): HabitResponse> @POST("challenges/{challengeId}/flag") - suspend fun reportChallenge(@Query("challengeId") challengeid: String, @Body updateData: Map): HabitResponse + suspend fun reportChallenge(@Path("challengeId") challengeid: String, @Body updateData: Map): HabitResponse } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/api/GSonFactoryCreator.java b/Habitica/src/main/java/com/habitrpg/android/habitica/api/GSonFactoryCreator.java index 5613e2a95c..a7cff73fdd 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/api/GSonFactoryCreator.java +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/api/GSonFactoryCreator.java @@ -142,6 +142,7 @@ public static Gson createGson() { .registerTypeAdapter(SocialAuthentication.class, new SocialAuthenticationDeserializer()) .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") .serializeNulls() + .setLenient() .create(); } public static GsonConverterFactory create() { diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/SocialRepositoryImpl.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/SocialRepositoryImpl.kt index bd6c6894d5..6a52e86a8b 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/SocialRepositoryImpl.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/implementation/SocialRepositoryImpl.kt @@ -109,7 +109,7 @@ class SocialRepositoryImpl( val message = apiClient.likeMessage(chatMessage.groupId ?: "", chatMessage.id) message?.groupId = chatMessage.groupId message?.let { localRepository.save(it) } - return null + return message } override suspend fun deleteMessage(chatMessage: ChatMessage): Void? { diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/data/local/implementation/RealmSocialLocalRepository.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/data/local/implementation/RealmSocialLocalRepository.kt index a6d5c8885b..35706b1ebd 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/data/local/implementation/RealmSocialLocalRepository.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/data/local/implementation/RealmSocialLocalRepository.kt @@ -188,23 +188,30 @@ class RealmSocialLocalRepository(realm: Realm) : RealmBaseLocalRepository(realm) } override fun likeMessage(chatMessage: ChatMessage, userId: String, liked: Boolean) { - if (chatMessage.userLikesMessage(userId) == liked) { + val liveMessage = getLiveObject(chatMessage) + if (liveMessage == null) { + executeTransaction { + realm.insertOrUpdate(chatMessage) + return@executeTransaction + } + return + } + if (liveMessage.userLikesMessage(userId) == liked) { return } - val liveMessage = getLiveObject(chatMessage) if (liked) { executeTransaction { - liveMessage?.likes?.add(ChatMessageLike(userId)) - liveMessage?.likeCount = liveMessage?.likes?.size ?: 0 + liveMessage.likes?.add(ChatMessageLike(userId)) + liveMessage.likeCount = liveMessage.likes?.size ?: 0 } } else { - liveMessage?.likes?.filter { userId == it.id && it.isManaged }?.forEach { like -> + liveMessage.likes?.filter { userId == it.id && it.isManaged }?.forEach { like -> executeTransaction { like.deleteFromRealm() } } executeTransaction { - liveMessage?.likeCount = liveMessage?.likes?.size ?: 0 + liveMessage.likeCount = liveMessage.likes?.size ?: 0 } } } diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/challenges/ChallengeDetailFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/challenges/ChallengeDetailFragment.kt index 36dfed0167..8153a3a8c4 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/challenges/ChallengeDetailFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/social/challenges/ChallengeDetailFragment.kt @@ -171,6 +171,8 @@ class ChallengeDetailFragment : BaseMainFragment editMenuItem?.isVisible = isCreator val endChallengeMenuItem = menu.findItem(R.id.action_end_challenge) endChallengeMenuItem?.isVisible = isCreator + val reportMenuItem = menu.findItem(R.id.action_report) + reportMenuItem?.isVisible = challenge?.official == false } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -254,6 +256,7 @@ class ChallengeDetailFragment : BaseMainFragment binding?.gemAmount?.text = challenge.prize.toString() binding?.participantCount?.text = challenge.memberCount.toString() + this.mainActivity?.invalidateOptionsMenu() } private fun set(creator: Member?) { diff --git a/common/src/main/java/com/habitrpg/common/habitica/helpers/ExceptionHandler.kt b/common/src/main/java/com/habitrpg/common/habitica/helpers/ExceptionHandler.kt index 586b6e0d32..ae47486afd 100644 --- a/common/src/main/java/com/habitrpg/common/habitica/helpers/ExceptionHandler.kt +++ b/common/src/main/java/com/habitrpg/common/habitica/helpers/ExceptionHandler.kt @@ -13,7 +13,6 @@ class ExceptionHandler { private var exceptionLogger: ((Throwable) -> Unit)? = null companion object { - private var instance = ExceptionHandler() fun init(exceptionLogger: ((Throwable) -> Unit)? = null) { @@ -34,10 +33,7 @@ class ExceptionHandler { } catch (ignored: Exception) { } } else { - if (throwable !is IOException && - throwable !is HttpException && - throwable !is CancellationException - ) { + if (throwable !is CancellationException) { instance.exceptionLogger?.invoke(throwable) } } diff --git a/fastlane/changelog.txt b/fastlane/changelog.txt index 51007ad8b0..751effd6a5 100644 --- a/fastlane/changelog.txt +++ b/fastlane/changelog.txt @@ -1,7 +1,6 @@ New in 4.3.4: - -To Do reminders should show more reliably -Added password reset option to the Account Reset and Account Delete screens -Group Plan invites will show in the notification center -Added the ability to report a Challenge for community violations -Various other bug fixes and improvements +- To Do reminders should show more reliably +- Added password reset option to the Account Reset and Account Delete screens +- Group Plan invites will show in the notification center +- Added the ability to report a Challenge for community violations +- Various other bug fixes and improvements diff --git a/version.properties b/version.properties index e7a9c161a2..22134b5bcb 100644 --- a/version.properties +++ b/version.properties @@ -1,2 +1,2 @@ NAME=4.3.4 -CODE=6901 \ No newline at end of file +CODE=6921 \ No newline at end of file