Skip to content

Reformat files from 4 spaces to 2 spaces #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,064 changes: 532 additions & 532 deletions Sources/client/Channel.swift

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions Sources/client/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,56 @@

/// Data that is received from the Server.
public class Message {

/// Reference number. Empty if missing
public let ref: String

/// Join Reference number
internal let joinRef: String?

/// Message topic
public let topic: String

/// Message event
public let event: String

/// Message payload
public var payload: Payload

/// Convenience accessor. Equivalent to getting the status as such:
/// ```swift
/// message.payload["status"]
/// ```
public var status: String? {
return payload["status"] as? String
}

init(ref: String = "",
topic: String = "",
event: String = "",
payload: Payload = [:],
joinRef: String? = nil) {
self.ref = ref
self.topic = topic
self.event = event
self.payload = payload
self.joinRef = joinRef
}

init?(json: [String: Any]) {
self.ref = json["ref"] as? String ?? ""
self.joinRef = json["join_ref"] as? String

/// Reference number. Empty if missing
public let ref: String

/// Join Reference number
internal let joinRef: String?

/// Message topic
public let topic: String

/// Message event
public let event: String

/// Message payload
public var payload: Payload

/// Convenience accessor. Equivalent to getting the status as such:
/// ```swift
/// message.payload["status"]
/// ```
public var status: String? {
return payload["status"] as? String
}

init(ref: String = "",
topic: String = "",
event: String = "",
payload: Payload = [:],
joinRef: String? = nil) {
self.ref = ref
self.topic = topic
self.event = event
self.payload = payload
self.joinRef = joinRef
}

init?(json: [String: Any]) {
self.ref = json["ref"] as? String ?? ""
self.joinRef = json["join_ref"] as? String

if
let topic = json["topic"] as? String,
let event = json["event"] as? String,
let payload = json["payload"] as? Payload {

self.topic = topic
self.event = event
self.payload = payload
} else {
return nil
}
if
let topic = json["topic"] as? String,
let event = json["event"] as? String,
let payload = json["payload"] as? Payload {

self.topic = topic
self.event = event
self.payload = payload
} else {
return nil
}
}
}
16 changes: 8 additions & 8 deletions Sources/client/Presence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public final class Presence {
// Diff has keys "joins" and "leaves", pointing to a Presence.State each
// containing the users that joined and left.
public typealias Diff = [String: State]

/// Closure signature of OnJoin callbacks
public typealias OnJoin = (_ key: String, _ current: Map?, _ new: Map) -> Void

Expand Down Expand Up @@ -240,7 +240,7 @@ public final class Presence {
self.pendingDiffs = []
self.caller.onSync()
}

self.channel?.delegateOn(diffEvent, to: self) { (self, message) in
guard let diff = message.payload as? Diff else { return }
if self.isPendingSyncState {
Expand Down Expand Up @@ -269,7 +269,7 @@ public final class Presence {
public func filter(by filter: ((String, Map) -> Bool)?) -> State {
return Presence.filter(self.state, by: filter)
}


//----------------------------------------------------------------------
// MARK: - Static
Expand All @@ -289,13 +289,13 @@ public final class Presence {
let state = currentState
var leaves: Presence.State = [:]
var joins: Presence.State = [:]

state.forEach { (key, presence) in
if newState[key] == nil {
leaves[key] = presence
}
}

newState.forEach { (key, newPresence) in
if let currentPresence = state[key] {
let newRefs = newPresence["metas"]!.map({ $0["phx_ref"] as! String })
Expand All @@ -307,7 +307,7 @@ public final class Presence {
let leftMetas = currentPresence["metas"]!.filter({ (meta: Meta) -> Bool in
!newRefs.contains { $0 == meta["phx_ref"] as! String }
})


if joinedMetas.count > 0 {
joins[key] = newPresence
Expand All @@ -322,7 +322,7 @@ public final class Presence {
joins[key] = newPresence
}
}

return Presence.syncDiff(state,
diff: ["joins": joins, "leaves": leaves],
onJoin: onJoin,
Expand Down Expand Up @@ -366,7 +366,7 @@ public final class Presence {

curPresence["metas"] = keepMetas
onLeave(key, curPresence, leftPresence)

if keepMetas.count > 0 {
state[key]!["metas"] = keepMetas
} else {
Expand Down
Loading