Skip to content

Commit

Permalink
chore(examples): track presence on channel subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Mar 13, 2024
1 parent 7defc02 commit 966d095
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Examples/SlackClone/UserStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ final class UserStore {
let channel = await supabase.realtimeV2.channel("public:users")
let changes = await channel.postgresChange(AnyAction.self, table: "users")

let prenseces = await channel.presenceChange()
let presences = await channel.presenceChange()

await channel.subscribe()

let userId = try await supabase.auth.session.user.id
try await channel.track(UserPresence(userId: userId, onlineAt: Date()))
Task {
let statusChange = await channel.statusChange
for await _ in statusChange.filter({ $0 == .subscribed }) {
let userId = try await supabase.auth.session.user.id
try await channel.track(UserPresence(userId: userId, onlineAt: Date()))
}
}

Task {
for await change in changes {
Expand All @@ -36,7 +41,7 @@ final class UserStore {
}

Task {
for await presence in prenseces {
for await presence in presences {
let joins = try presence.decodeJoins(as: UserPresence.self)
let leaves = try presence.decodeLeaves(as: UserPresence.self)

Expand Down

0 comments on commit 966d095

Please sign in to comment.