Skip to content

Commit

Permalink
fixup! [ECO-5082] feat: presence basic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Nov 11, 2024
1 parent 2cbf2f6 commit b1896e8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Presence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +35,11 @@ interface Presence : EmitsDiscontinuities {
*/
suspend fun get(params: List<Param> = listOf()): List<PresenceMember>

/**
* @see #get(params)
*/
suspend fun get(waitForSync: Boolean = false, clientId: String? = null, connectionId: String? = null): List<PresenceMember>

/**
* 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.
Expand Down Expand Up @@ -152,6 +159,15 @@ internal class DefaultPresence(
}
}

override suspend fun get(waitForSync: Boolean, clientId: String?, connectionId: String?): List<PresenceMember> {
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?) {
Expand Down

0 comments on commit b1896e8

Please sign in to comment.