Skip to content

Commit

Permalink
fix: Add private topic to Realtime (#442)
Browse files Browse the repository at this point in the history
* fix: Add private topic to Realtime

* rename struct field

* fix tests

* remove public access control

---------

Co-authored-by: Guilherme Souza <[email protected]>
  • Loading branch information
filipecabaco and grdsdev authored Jul 4, 2024
1 parent 8a80aae commit a491b29
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/Realtime/V2/RealtimeChannelV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Helpers
public struct RealtimeChannelConfig: Sendable {
public var broadcast: BroadcastJoinConfig
public var presence: PresenceJoinConfig
public var isPrivate: Bool
}

struct Socket: Sendable {
Expand Down Expand Up @@ -111,7 +112,8 @@ public final class RealtimeChannelV2: Sendable {
let joinConfig = RealtimeJoinConfig(
broadcast: config.broadcast,
presence: config.presence,
postgresChanges: mutableState.clientChanges
postgresChanges: mutableState.clientChanges,
isPrivate: config.isPrivate
)

let payload = RealtimeJoinPayload(
Expand Down
3 changes: 2 additions & 1 deletion Sources/Realtime/V2/RealtimeClientV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ public final class RealtimeClientV2: Sendable {
) -> RealtimeChannelV2 {
var config = RealtimeChannelConfig(
broadcast: BroadcastJoinConfig(acknowledgeBroadcasts: false, receiveOwnBroadcasts: false),
presence: PresenceJoinConfig(key: "")
presence: PresenceJoinConfig(key: ""),
isPrivate: false
)
options(&config)

Expand Down
2 changes: 2 additions & 0 deletions Sources/Realtime/V2/RealtimeJoinConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ struct RealtimeJoinConfig: Codable, Hashable {
var broadcast: BroadcastJoinConfig = .init()
var presence: PresenceJoinConfig = .init()
var postgresChanges: [PostgresJoinConfig] = []
var isPrivate: Bool = false

enum CodingKeys: String, CodingKey {
case broadcast
case presence
case isPrivate = "private"
case postgresChanges = "postgres_changes"
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/RealtimeTests/RealtimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ extension RealtimeMessageV2 {
["schema": "public", "table": "messages", "event": "DELETE"],
],
"presence": ["key": ""],
"private": false,
],
]
)
Expand Down
3 changes: 2 additions & 1 deletion Tests/RealtimeTests/_PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ final class _PushTests: XCTestCase {
topic: "realtime:users",
config: RealtimeChannelConfig(
broadcast: .init(acknowledgeBroadcasts: false),
presence: .init()
presence: .init(),
isPrivate: false
),
socket: Socket(client: socket),
logger: nil
Expand Down

0 comments on commit a491b29

Please sign in to comment.