Skip to content

Commit

Permalink
Change isSubscribed() behaviour to return target state instead of cur…
Browse files Browse the repository at this point in the history
…rent
  • Loading branch information
mklkj committed Jun 11, 2024
1 parent 79ad813 commit 8a28bf6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class NotificationStatusChecker private constructor(
if (pref.subscriberId.isNotBlank()) {
checkerScope.launch(errorHandler) {
logDebug("Notifications disabled, but subscribed. Unregistering subscriber...")
PushPushGo.getInstance().getNetwork().unregisterSubscriber(pref.isSubscribed)
PushPushGo.getInstance().getNetwork().unregisterSubscriber()
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pushpushgo/sdk/PushPushGo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class PushPushGo private constructor(
return logError("Notifications disabled! Subscriber registration canceled")
}

networkModule.sharedPref.isSubscribed = true
getUploadManager().sendRegister(null)
}

Expand All @@ -298,6 +299,7 @@ class PushPushGo private constructor(
}

getNetwork().registerToken(null)
networkModule.sharedPref.isSubscribed = true
getSubscriberId()
}
}
Expand All @@ -307,6 +309,7 @@ class PushPushGo private constructor(
*/
fun unregisterSubscriber() {
getUploadManager().sendUnregister()
networkModule.sharedPref.isSubscribed = false
}

fun unregisterSubscriber(projectId: String, projectToken: String, subscriberId: String): ListenableFuture<Unit> {
Expand All @@ -316,6 +319,7 @@ class PushPushGo private constructor(
token = projectToken,
subscriberId = subscriberId,
)
networkModule.sharedPref.isSubscribed = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@ internal class ApiRepository(
)
if (data.id.isNotBlank()) {
sharedPref.subscriberId = data.id
sharedPref.isSubscribed = true
}
logDebug("RegisterSubscriber received: $data")
}

suspend fun unregisterSubscriber(isSubscribed: Boolean = false) {
logDebug("unregisterSubscriber($isSubscribed) invoked")
suspend fun unregisterSubscriber() {
logDebug("unregisterSubscriber() invoked")

apiService.unregisterSubscriber(
token = apiKey,
projectId = projectId,
subscriberId = sharedPref.subscriberId,
)
sharedPref.subscriberId = ""
sharedPref.isSubscribed = isSubscribed
}

suspend fun unregisterSubscriber(projectId: String, token: String, subscriberId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class UploadDelegate {
with(PushPushGo.getInstance().getNetwork()) {
when (type) {
UploadWorker.REGISTER -> registerToken(data)
UploadWorker.UNREGISTER -> unregisterSubscriber(isSubscribed = false)
UploadWorker.UNREGISTER -> unregisterSubscriber()
else -> logDebug("Unknown upload data type")
}
}
Expand Down

0 comments on commit 8a28bf6

Please sign in to comment.