Skip to content

Commit

Permalink
Merge branch 'develop' into change/add-additional-space-when-mentioni…
Browse files Browse the repository at this point in the history
…ng-user
  • Loading branch information
nuno-vieira authored Dec 11, 2023
2 parents 5191e0c + ba3d74a commit ba9d269
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### 🐞 Fixed
- Fix `UserInfo.isInvisible` not nullable [#2920](https://github.com/GetStream/stream-chat-swift/pull/2920)
- Fix CocoaPods minimum iOS target not in sync with the Xcode project [#2924](https://github.com/GetStream/stream-chat-swift/pull/2924)
- Improve `InternetConnection.Monitor` stability [#2923](https://github.com/GetStream/stream-chat-swift/pull/2923)
### 🔄 Changed
- The `UserInfo.isInvisible` is now nullable and `nil` by default [#2920](https://github.com/GetStream/stream-chat-swift/pull/2920)

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
name: "StreamChat",
defaultLocalization: "en",
platforms: [
.iOS(.v11), .macOS(.v10_15)
.iOS(.v12), .macOS(.v10_15)
],
products: [
.library(
Expand Down
4 changes: 1 addition & 3 deletions Sources/StreamChat/ChatClient+Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ extension ChatClient {
var internetMonitor: InternetConnectionMonitor {
if let monitor = monitor {
return monitor
} else if #available(iOS 12, *) {
return InternetConnection.Monitor()
} else {
return InternetConnection.LegacyMonitor()
return InternetConnection.Monitor()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ extension InternetConnection.Status {
// MARK: - Internet Connection Monitor

extension InternetConnection {
/// The default Internet connection monitor for iOS 12+.
/// It uses Apple Network API.
@available(iOS 12, *)
class Monitor: InternetConnectionMonitor {
private var monitor: NWPathMonitor?
private let queue = DispatchQueue(label: "io.getstream.internet-monitor")

weak var delegate: InternetConnectionDelegate?

Expand All @@ -169,7 +167,7 @@ extension InternetConnection {
guard monitor == nil else { return }

monitor = createMonitor()
monitor?.start(queue: .global())
monitor?.start(queue: queue)
}

func stop() {
Expand Down Expand Up @@ -214,83 +212,3 @@ extension InternetConnection {
}
}
}

// MARK: Legacy Internet Connection Monitor for iOS 11 only

extension InternetConnection {
class LegacyMonitor: InternetConnectionMonitor {
/// A Reachability instance for Internet connection monitoring.
private lazy var reachability = createReachability()

weak var delegate: InternetConnectionDelegate?

var status: InternetConnection.Status {
if let reachability = reachability {
return status(from: reachability)
}

return .unknown
}

func start() {
do {
try reachability?.startNotifier()
} catch {
log.error(error)
}
}

func stop() {
reachability?.stopNotifier()
}

private func createReachability() -> Reachability? {
var reachability: Reachability?

do {
reachability = try Reachability()
reachability?.whenReachable = { [weak self] in self?.updateStatus(with: $0) }
reachability?.whenUnreachable = { [weak self] in self?.updateStatus(with: $0) }
} catch {
log.error(error)
}

return reachability
}

private func updateStatus(with reachability: Reachability) {
log.info("Internet Connection info: \(reachability.description)")

if case .unavailable = reachability.connection {
delegate?.internetConnectionStatusDidChange(status: .unavailable)
return
}

let quality: InternetConnection.Quality

if case .cellular = reachability.connection {
quality = .expensive
} else {
quality = .great
}

delegate?.internetConnectionStatusDidChange(status: .available(quality))
}

private func status(from reachability: Reachability) -> InternetConnection.Status {
if case .unavailable = reachability.connection {
return .unavailable
}

let quality: InternetConnection.Quality

if case .cellular = reachability.connection {
quality = .expensive
} else {
quality = .great
}

return .available(quality)
}
}
}

0 comments on commit ba9d269

Please sign in to comment.