Skip to content

Commit

Permalink
Merge pull request #495 from supabase-community/fix-status
Browse files Browse the repository at this point in the history
Fix missing UNSUBSCRIBED status after unsubscribing
  • Loading branch information
jan-tennert authored Mar 3, 2024
2 parents b4a7b53 + ae5c74f commit cadbcba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ internal class RealtimeChannelImpl(
Realtime.logger.d { "Subscribed to channel ${message.topic}" }
_status.value = RealtimeChannel.Status.SUBSCRIBED
}
RealtimeMessage.EventType.SYSTEM_REPLY -> {
Realtime.logger.d { "Received system reply: ${message.payload}." }
if(status.value == RealtimeChannel.Status.UNSUBSCRIBING) {
_status.value = RealtimeChannel.Status.UNSUBSCRIBED
Realtime.logger.d { "Unsubscribed from channel ${message.topic}" }
}
}
RealtimeMessage.EventType.POSTGRES_SERVER_CHANGES -> { //check if the server postgres_changes match with the client's and add the given id to the postgres change objects (to identify them later in the events)
val serverPostgresChanges = message.payload["response"]?.jsonObject?.get("postgres_changes")?.jsonArray?.let { Json.decodeFromJsonElement<List<PostgresJoinConfig>>(it) } ?: listOf() //server postgres changes
callbackManager.setServerChanges(serverPostgresChanges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class RealtimeMessage(val topic: String, val event: String, val payload: Js
val eventType: EventType? = when {
event == RealtimeChannel.CHANNEL_EVENT_SYSTEM && payload["status"]?.jsonPrimitive?.content == "ok" -> EventType.SYSTEM
event == RealtimeChannel.CHANNEL_EVENT_REPLY && payload["response"]?.jsonObject?.containsKey(RealtimeChannel.CHANNEL_EVENT_POSTGRES_CHANGES) ?: false -> EventType.POSTGRES_SERVER_CHANGES
event == RealtimeChannel.CHANNEL_EVENT_REPLY && payload["status"]?.jsonPrimitive?.content == "ok" -> EventType.SYSTEM_REPLY
event == RealtimeChannel.CHANNEL_EVENT_POSTGRES_CHANGES -> EventType.POSTGRES_CHANGES
event == RealtimeChannel.CHANNEL_EVENT_BROADCAST -> EventType.BROADCAST
event == RealtimeChannel.CHANNEL_EVENT_CLOSE -> EventType.CLOSE
Expand All @@ -29,7 +30,7 @@ data class RealtimeMessage(val topic: String, val event: String, val payload: Js
}

enum class EventType {
SYSTEM, POSTGRES_SERVER_CHANGES, POSTGRES_CHANGES, BROADCAST, CLOSE, ERROR, PRESENCE_DIFF, PRESENCE_STATE, TOKEN_EXPIRED
SYSTEM, SYSTEM_REPLY, POSTGRES_SERVER_CHANGES, POSTGRES_CHANGES, BROADCAST, CLOSE, ERROR, PRESENCE_DIFF, PRESENCE_STATE, TOKEN_EXPIRED
}

}
Expand Down

0 comments on commit cadbcba

Please sign in to comment.