Skip to content

Commit b1896e8

Browse files
committed
fixup! [ECO-5082] feat: presence basic implementation
1 parent 2cbf2f6 commit b1896e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

chat-android/src/main/java/com/ably/chat/Presence.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.google.gson.JsonElement
66
import com.google.gson.JsonObject
77
import io.ably.lib.realtime.Channel
88
import io.ably.lib.realtime.Presence.GET_CLIENTID
9+
import io.ably.lib.realtime.Presence.GET_CONNECTIONID
10+
import io.ably.lib.realtime.Presence.GET_WAITFORSYNC
911
import io.ably.lib.types.Param
1012
import io.ably.lib.types.PresenceMessage
1113
import io.ably.lib.realtime.Presence as PubSubPresence
@@ -33,6 +35,11 @@ interface Presence : EmitsDiscontinuities {
3335
*/
3436
suspend fun get(params: List<Param> = listOf()): List<PresenceMember>
3537

38+
/**
39+
* @see #get(params)
40+
*/
41+
suspend fun get(waitForSync: Boolean = false, clientId: String? = null, connectionId: String? = null): List<PresenceMember>
42+
3643
/**
3744
* Method to check if user with supplied clientId is online
3845
* @param {string} clientId - The client ID to check if it is present in the room.
@@ -152,6 +159,15 @@ internal class DefaultPresence(
152159
}
153160
}
154161

162+
override suspend fun get(waitForSync: Boolean, clientId: String?, connectionId: String?): List<PresenceMember> {
163+
val params = buildList {
164+
if (waitForSync) add(Param(GET_WAITFORSYNC, true))
165+
clientId?.let { add(Param(GET_CLIENTID, it)) }
166+
connectionId?.let { add(Param(GET_CONNECTIONID, it)) }
167+
}
168+
return get(params)
169+
}
170+
155171
override suspend fun isUserPresent(clientId: String): Boolean = presence.getCoroutine(Param(GET_CLIENTID, clientId)).isNotEmpty()
156172

157173
override suspend fun enter(data: PresenceData?) {

0 commit comments

Comments
 (0)