From b1896e836bcbe1edb5f8e91fe9a77275d8807c52 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 11 Nov 2024 13:19:20 +0000 Subject: [PATCH] fixup! [ECO-5082] feat: presence basic implementation --- .../src/main/java/com/ably/chat/Presence.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chat-android/src/main/java/com/ably/chat/Presence.kt b/chat-android/src/main/java/com/ably/chat/Presence.kt index d62e9ae..e5239fb 100644 --- a/chat-android/src/main/java/com/ably/chat/Presence.kt +++ b/chat-android/src/main/java/com/ably/chat/Presence.kt @@ -6,6 +6,8 @@ import com.google.gson.JsonElement import com.google.gson.JsonObject import io.ably.lib.realtime.Channel import io.ably.lib.realtime.Presence.GET_CLIENTID +import io.ably.lib.realtime.Presence.GET_CONNECTIONID +import io.ably.lib.realtime.Presence.GET_WAITFORSYNC import io.ably.lib.types.Param import io.ably.lib.types.PresenceMessage import io.ably.lib.realtime.Presence as PubSubPresence @@ -33,6 +35,11 @@ interface Presence : EmitsDiscontinuities { */ suspend fun get(params: List = listOf()): List + /** + * @see #get(params) + */ + suspend fun get(waitForSync: Boolean = false, clientId: String? = null, connectionId: String? = null): List + /** * Method to check if user with supplied clientId is online * @param {string} clientId - The client ID to check if it is present in the room. @@ -152,6 +159,15 @@ internal class DefaultPresence( } } + override suspend fun get(waitForSync: Boolean, clientId: String?, connectionId: String?): List { + val params = buildList { + if (waitForSync) add(Param(GET_WAITFORSYNC, true)) + clientId?.let { add(Param(GET_CLIENTID, it)) } + connectionId?.let { add(Param(GET_CONNECTIONID, it)) } + } + return get(params) + } + override suspend fun isUserPresent(clientId: String): Boolean = presence.getCoroutine(Param(GET_CLIENTID, clientId)).isNotEmpty() override suspend fun enter(data: PresenceData?) {