Skip to content

Commit

Permalink
Detect achievement notification based on raw type
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Apr 26, 2024
1 parent 76fcd0d commit 49035a2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
14 changes: 0 additions & 14 deletions WordPress/src/main/java/org/wordpress/android/models/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Note {
val title: String by lazy { queryJSON("title", "") }
val iconURL: String by lazy { queryJSON("icon", "") }
val enabledCommentActions: EnumSet<EnabledActions> by lazy { getEnabledActions(commentActions) }
val hasBadge: Boolean by lazy { containsBadgeMediaType() }
private val enabledPostActions: EnumSet<EnabledActions> by lazy { getEnabledActions(postActions) }
private val timestampString: String by lazy { queryJSON("timestamp", "") }
private val commentText: String by lazy { queryJSON("body[last].text", "") }
Expand Down Expand Up @@ -182,19 +181,6 @@ class Note {
""
}

private fun containsBadgeMediaType(): Boolean {
val bodyArray = mNoteJSON?.optJSONArray("body")
if (bodyArray != null && bodyArray.length() > 0) {
for (i in 0 until bodyArray.length()) {
val mediaType = JSONUtils.queryJSON(bodyArray, "body[$i].media[0].type", "")
if ("badge" == mediaType) {
return true
}
}
}
return false
}

/**
* Computed properties
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@file:JvmName("NoteExtensions")
package org.wordpress.android.models


val Note.type
get() = NoteType.from(rawType)

fun Note.isAchievement() = AchievementType.isAchievementType(rawType)

sealed class Notification {
data class PostLike(val url: String, val title: String): Notification()
data object NewPost: Notification()
Expand Down Expand Up @@ -34,3 +37,29 @@ enum class NoteType(val rawType: String) {
fun from(rawType: String) = map[rawType] ?: Unknown
}
}

enum class AchievementType(val rawType: String) {
UserGoalMet("user_goal_met"),
AutomatticianAchievement("automattician_achievement"),
AchieveBurritoFriday("achieve_burrito_friday"),
AchieveDailyStreak("achieve_daily_streak"),
FollowedMilestoneAchievement("followed_milestone_achievement"),
LikeMilestoneAchievement("like_milestone_achievement"),
OnFireAchievement("on_fire_achievement"),
PostMilestoneAchievement("post_milestone_achievement"),
AchieveUserAnniversary("achieve_user_anniversary"),
BestFollowedDayFeat("best_followed_day_feat"),
BestLikedDayFeat("best_liked_day_feat"),
NewTrafficSurge("new_traffic_surge"),
PrivacyChange("privacy_change"),
FreeTrialStart("free_trial_start"),
FreeTrialNearEndNote("free_trial_near_end_note"),
FreeTrialEnd("free_trial_end"),
ViewMilestone(Note.NOTE_VIEW_MILESTONE),
AscProfileRegenerationStarted("asc_profile_regeneration_started"),
AscProfileRegenerationFinished("asc_profile_regeneration_finished");

companion object {
fun isAchievementType(rawType: String) = entries.any { it.rawType == rawType }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.wordpress.android.fluxc.store.SiteStore;
import org.wordpress.android.fluxc.tools.FormattableRangeType;
import org.wordpress.android.models.Note;
import org.wordpress.android.models.NoteExtensions;
import org.wordpress.android.push.GCMMessageHandler;
import org.wordpress.android.ui.ActivityLauncher;
import org.wordpress.android.ui.CollapseFullScreenDialogFragment;
Expand Down Expand Up @@ -366,7 +367,7 @@ private void setActionBarTitleForNote(Note note) {
title = getString(R.string.reader_title_post_detail);
}

if (note.isViewMilestoneType() || note.getHasBadge()) {
if (NoteExtensions.isAchievement(note)) {
title = "";
}

Expand Down

0 comments on commit 49035a2

Please sign in to comment.