-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #794 from ably/feature/wait-for-presence-sync
Process initial presence messages before returning a Subscriber instance
- Loading branch information
Showing
12 changed files
with
327 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
subscribing-sdk/src/main/java/com/ably/tracking/subscriber/PresenceMessageProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.ably.tracking.subscriber | ||
|
||
import com.ably.tracking.common.ClientTypes | ||
import com.ably.tracking.common.PresenceAction | ||
import com.ably.tracking.common.PresenceMessage | ||
|
||
internal fun processPresenceMessage( | ||
presenceMessage: PresenceMessage, | ||
properties: Properties, | ||
subscriberInteractor: SubscriberInteractor, | ||
) { | ||
when (presenceMessage.action) { | ||
PresenceAction.PRESENT_OR_ENTER -> { | ||
if (presenceMessage.data.type == ClientTypes.PUBLISHER) { | ||
subscriberInteractor.updatePublisherPresence(properties, true) | ||
subscriberInteractor.updateTrackableState(properties) | ||
subscriberInteractor.updatePublisherResolutionInformation(presenceMessage.data) | ||
} | ||
} | ||
PresenceAction.LEAVE_OR_ABSENT -> { | ||
if (presenceMessage.data.type == ClientTypes.PUBLISHER) { | ||
subscriberInteractor.updatePublisherPresence(properties, false) | ||
subscriberInteractor.updateTrackableState(properties) | ||
} | ||
} | ||
PresenceAction.UPDATE -> { | ||
if (presenceMessage.data.type == ClientTypes.PUBLISHER) { | ||
subscriberInteractor.updatePublisherResolutionInformation(presenceMessage.data) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../com/ably/tracking/subscriber/workerqueue/workers/ProcessInitialPresenceMessagesWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ably.tracking.subscriber.workerqueue.workers | ||
|
||
import com.ably.tracking.common.PresenceMessage | ||
import com.ably.tracking.common.ResultCallbackFunction | ||
import com.ably.tracking.subscriber.Properties | ||
import com.ably.tracking.subscriber.SubscriberInteractor | ||
import com.ably.tracking.subscriber.processPresenceMessage | ||
import com.ably.tracking.subscriber.workerqueue.CallbackWorker | ||
import com.ably.tracking.subscriber.workerqueue.WorkerSpecification | ||
|
||
internal class ProcessInitialPresenceMessagesWorker( | ||
private val presenceMessages: List<PresenceMessage>, | ||
private val subscriberInteractor: SubscriberInteractor, | ||
callbackFunction: ResultCallbackFunction<Unit>, | ||
) : CallbackWorker(callbackFunction) { | ||
override fun doWork( | ||
properties: Properties, | ||
doAsyncWork: (suspend () -> Unit) -> Unit, | ||
postWork: (WorkerSpecification) -> Unit | ||
): Properties { | ||
presenceMessages.forEach { presenceMessage -> | ||
processPresenceMessage(presenceMessage, properties, subscriberInteractor) | ||
} | ||
postWork(WorkerSpecification.SubscribeToChannel(callbackFunction)) | ||
return properties | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.