mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -713,6 +713,7 @@ public protocol AccountGroupCallContextCache: class {
|
|||||||
public protocol AccountContext: class {
|
public protocol AccountContext: class {
|
||||||
var sharedContext: SharedAccountContext { get }
|
var sharedContext: SharedAccountContext { get }
|
||||||
var account: Account { get }
|
var account: Account { get }
|
||||||
|
var engine: TelegramEngine { get }
|
||||||
|
|
||||||
var liveLocationManager: LiveLocationManager? { get }
|
var liveLocationManager: LiveLocationManager? { get }
|
||||||
var peersNearbyManager: PeersNearbyManager? { get }
|
var peersNearbyManager: PeersNearbyManager? { get }
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public final class SecureIdAuthController: ViewController, StandalonePresentable
|
|||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
let storedPassword = context.getStoredSecureIdPassword()
|
let storedPassword = context.getStoredSecureIdPassword()
|
||||||
if data.currentPasswordDerivation != nil, let storedPassword = storedPassword {
|
if data.currentPasswordDerivation != nil, let storedPassword = storedPassword {
|
||||||
strongSelf.authenthicateDisposable.set((accessSecureId(network: strongSelf.context.account.network, password: storedPassword)
|
strongSelf.authenthicateDisposable.set((strongSelf.context.engine.secureId.accessSecureId(password: storedPassword)
|
||||||
|> deliverOnMainQueue).start(next: { context in
|
|> deliverOnMainQueue).start(next: { context in
|
||||||
guard let strongSelf = self, strongSelf.state.verificationState == nil else {
|
guard let strongSelf = self, strongSelf.state.verificationState == nil else {
|
||||||
return
|
return
|
||||||
@@ -441,7 +441,7 @@ public final class SecureIdAuthController: ViewController, StandalonePresentable
|
|||||||
state.verificationState = .passwordChallenge(hint: hint, state: .checking, hasRecoveryEmail: hasRecoveryEmail)
|
state.verificationState = .passwordChallenge(hint: hint, state: .checking, hasRecoveryEmail: hasRecoveryEmail)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
self.challengeDisposable.set((accessSecureId(network: self.context.account.network, password: password)
|
self.challengeDisposable.set((self.context.engine.secureId.accessSecureId(password: password)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] context in
|
|> deliverOnMainQueue).start(next: { [weak self] context in
|
||||||
guard let strongSelf = self, let verificationState = strongSelf.state.verificationState, case .passwordChallenge(_, .checking, _) = verificationState else {
|
guard let strongSelf = self, let verificationState = strongSelf.state.verificationState, case .passwordChallenge(_, .checking, _) = verificationState else {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -478,14 +478,14 @@ public func peersNearbyController(context: AccountContext) -> ViewController {
|
|||||||
let _ = (coordinatePromise.get()
|
let _ = (coordinatePromise.get()
|
||||||
|> deliverOnMainQueue).start(next: { coordinate in
|
|> deliverOnMainQueue).start(next: { coordinate in
|
||||||
if let coordinate = coordinate {
|
if let coordinate = coordinate {
|
||||||
let _ = updatePeersNearbyVisibility(account: context.account, update: .visible(latitude: coordinate.latitude, longitude: coordinate.longitude), background: false).start()
|
let _ = context.engine.peersNearby.updatePeersNearbyVisibility(update: .visible(latitude: coordinate.latitude, longitude: coordinate.longitude), background: false).start()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})]), nil)
|
})]), nil)
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let _ = updatePeersNearbyVisibility(account: context.account, update: .invisible, background: false).start()
|
let _ = context.engine.peersNearby.updatePeersNearbyVisibility(update: .invisible, background: false).start()
|
||||||
}
|
}
|
||||||
}, openProfile: { peer, distance in
|
}, openProfile: { peer, distance in
|
||||||
navigateToProfileImpl?(peer, distance)
|
navigateToProfileImpl?(peer, distance)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public enum PeerNearbyVisibilityUpdate {
|
|||||||
case invisible
|
case invisible
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updatePeersNearbyVisibility(account: Account, update: PeerNearbyVisibilityUpdate, background: Bool) -> Signal<Void, NoError> {
|
func _internal_updatePeersNearbyVisibility(account: Account, update: PeerNearbyVisibilityUpdate, background: Bool) -> Signal<Void, NoError> {
|
||||||
var flags: Int32 = 0
|
var flags: Int32 = 0
|
||||||
var geoPoint: Api.InputGeoPoint
|
var geoPoint: Api.InputGeoPoint
|
||||||
var selfExpires: Int32?
|
var selfExpires: Int32?
|
||||||
@@ -138,7 +138,6 @@ public final class PeersNearbyContext {
|
|||||||
}
|
}
|
||||||
|> restartIfError
|
|> restartIfError
|
||||||
|> `catch` { _ -> Signal<[PeerNearby], NoError> in
|
|> `catch` { _ -> Signal<[PeerNearby], NoError> in
|
||||||
return .single([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.disposable.set((combined
|
self.disposable.set((combined
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import SwiftSignalKit
|
||||||
|
|
||||||
|
public extension TelegramEngine {
|
||||||
|
final class PeersNearby {
|
||||||
|
private let account: Account
|
||||||
|
|
||||||
|
init(account: Account) {
|
||||||
|
self.account = account
|
||||||
|
}
|
||||||
|
|
||||||
|
public func updatePeersNearbyVisibility(update: PeerNearbyVisibilityUpdate, background: Bool) -> Signal<Void, NoError> {
|
||||||
|
return _internal_updatePeersNearbyVisibility(account: self.account, update: update, background: background)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -153,7 +153,7 @@ public enum SecureIdAccessError {
|
|||||||
case secretPasswordMismatch
|
case secretPasswordMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
public func accessSecureId(network: Network, password: String) -> Signal<(context: SecureIdAccessContext, settings: TwoStepVerificationSettings), SecureIdAccessError> {
|
func _internal_accessSecureId(network: Network, password: String) -> Signal<(context: SecureIdAccessContext, settings: TwoStepVerificationSettings), SecureIdAccessError> {
|
||||||
return requestTwoStepVerifiationSettings(network: network, password: password)
|
return requestTwoStepVerifiationSettings(network: network, password: password)
|
||||||
|> mapError { error -> SecureIdAccessError in
|
|> mapError { error -> SecureIdAccessError in
|
||||||
return .passwordError(error)
|
return .passwordError(error)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import SwiftSignalKit
|
||||||
|
|
||||||
|
public extension TelegramEngine {
|
||||||
|
final class SecureId {
|
||||||
|
private let account: Account
|
||||||
|
|
||||||
|
init(account: Account) {
|
||||||
|
self.account = account
|
||||||
|
}
|
||||||
|
|
||||||
|
public func accessSecureId(password: String) -> Signal<(context: SecureIdAccessContext, settings: TwoStepVerificationSettings), SecureIdAccessError> {
|
||||||
|
return _internal_accessSecureId(network: self.account.network, password: password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import SwiftSignalKit
|
||||||
|
import Postbox
|
||||||
|
|
||||||
|
public final class TelegramEngine {
|
||||||
|
public let account: Account
|
||||||
|
|
||||||
|
public init(account: Account) {
|
||||||
|
self.account = account
|
||||||
|
}
|
||||||
|
|
||||||
|
public lazy var secureId: SecureId = {
|
||||||
|
return SecureId(account: self.account)
|
||||||
|
}()
|
||||||
|
|
||||||
|
public lazy var peersNearby: PeersNearby = {
|
||||||
|
return PeersNearby(account: self.account)
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -109,6 +109,7 @@ public final class AccountContextImpl: AccountContext {
|
|||||||
return self.sharedContextImpl
|
return self.sharedContextImpl
|
||||||
}
|
}
|
||||||
public let account: Account
|
public let account: Account
|
||||||
|
public let engine: TelegramEngine
|
||||||
|
|
||||||
public let fetchManager: FetchManager
|
public let fetchManager: FetchManager
|
||||||
private let prefetchManager: PrefetchManager?
|
private let prefetchManager: PrefetchManager?
|
||||||
@@ -160,6 +161,7 @@ public final class AccountContextImpl: AccountContext {
|
|||||||
{
|
{
|
||||||
self.sharedContextImpl = sharedContext
|
self.sharedContextImpl = sharedContext
|
||||||
self.account = account
|
self.account = account
|
||||||
|
self.engine = TelegramEngine(account: account)
|
||||||
|
|
||||||
self.downloadedMediaStoreManager = DownloadedMediaStoreManagerImpl(postbox: account.postbox, accountManager: sharedContext.accountManager)
|
self.downloadedMediaStoreManager = DownloadedMediaStoreManagerImpl(postbox: account.postbox, accountManager: sharedContext.accountManager)
|
||||||
|
|
||||||
@@ -180,7 +182,7 @@ public final class AccountContextImpl: AccountContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let locationManager = self.sharedContextImpl.locationManager, sharedContext.applicationBindings.isMainApp && !temp {
|
if let locationManager = self.sharedContextImpl.locationManager, sharedContext.applicationBindings.isMainApp && !temp {
|
||||||
self.peersNearbyManager = PeersNearbyManagerImpl(account: account, locationManager: locationManager, inForeground: sharedContext.applicationBindings.applicationInForeground)
|
self.peersNearbyManager = PeersNearbyManagerImpl(account: account, engine: self.engine, locationManager: locationManager, inForeground: sharedContext.applicationBindings.applicationInForeground)
|
||||||
} else {
|
} else {
|
||||||
self.peersNearbyManager = nil
|
self.peersNearbyManager = nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,23 +7,27 @@ import TelegramApi
|
|||||||
import DeviceLocationManager
|
import DeviceLocationManager
|
||||||
import CoreLocation
|
import CoreLocation
|
||||||
import AccountContext
|
import AccountContext
|
||||||
|
import DeviceAccess
|
||||||
|
|
||||||
private let locationUpdateTimePeriod: Double = 1.0 * 60.0 * 60.0
|
private let locationUpdateTimePeriod: Double = 1.0 * 60.0 * 60.0
|
||||||
private let locationDistanceUpdateThreshold: Double = 1000
|
private let locationDistanceUpdateThreshold: Double = 1000
|
||||||
|
|
||||||
final class PeersNearbyManagerImpl: PeersNearbyManager {
|
final class PeersNearbyManagerImpl: PeersNearbyManager {
|
||||||
private let account: Account
|
private let account: Account
|
||||||
|
private let engine: TelegramEngine
|
||||||
private let locationManager: DeviceLocationManager
|
private let locationManager: DeviceLocationManager
|
||||||
private let inForeground: Signal<Bool, NoError>
|
private let inForeground: Signal<Bool, NoError>
|
||||||
|
|
||||||
private var preferencesDisposable: Disposable?
|
private var preferencesDisposable: Disposable?
|
||||||
private var locationDisposable = MetaDisposable()
|
private var locationDisposable = MetaDisposable()
|
||||||
private var updateDisposable = MetaDisposable()
|
private var updateDisposable = MetaDisposable()
|
||||||
|
private var accessDisposable: Disposable?
|
||||||
|
|
||||||
private var previousLocation: CLLocation?
|
private var previousLocation: CLLocation?
|
||||||
|
|
||||||
init(account: Account, locationManager: DeviceLocationManager, inForeground: Signal<Bool, NoError>) {
|
init(account: Account, engine: TelegramEngine, locationManager: DeviceLocationManager, inForeground: Signal<Bool, NoError>) {
|
||||||
self.account = account
|
self.account = account
|
||||||
|
self.engine = engine
|
||||||
self.locationManager = locationManager
|
self.locationManager = locationManager
|
||||||
self.inForeground = inForeground
|
self.inForeground = inForeground
|
||||||
|
|
||||||
@@ -32,17 +36,34 @@ final class PeersNearbyManagerImpl: PeersNearbyManager {
|
|||||||
let state = view.values[PreferencesKeys.peersNearby] as? PeersNearbyState ?? .default
|
let state = view.values[PreferencesKeys.peersNearby] as? PeersNearbyState ?? .default
|
||||||
return state.visibilityExpires
|
return state.visibilityExpires
|
||||||
}
|
}
|
||||||
|
|> deliverOnMainQueue
|
||||||
|> distinctUntilChanged).start(next: { [weak self] visibility in
|
|> distinctUntilChanged).start(next: { [weak self] visibility in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.visibilityUpdated(visible: visibility != nil)
|
strongSelf.visibilityUpdated(visible: visibility != nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.accessDisposable = (DeviceAccess.authorizationStatus(applicationInForeground: nil, siriAuthorization: nil, subject: .location(.live))
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||||
|
guard let strongSelf = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch status {
|
||||||
|
case .denied:
|
||||||
|
let _ = strongSelf.engine.peersNearby.updatePeersNearbyVisibility(update: .invisible, background: false).start()
|
||||||
|
strongSelf.locationDisposable.set(nil)
|
||||||
|
strongSelf.updateDisposable.set(nil)
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
self.preferencesDisposable?.dispose()
|
self.preferencesDisposable?.dispose()
|
||||||
self.locationDisposable.dispose()
|
self.locationDisposable.dispose()
|
||||||
self.updateDisposable.dispose()
|
self.updateDisposable.dispose()
|
||||||
|
self.accessDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func visibilityUpdated(visible: Bool) {
|
private func visibilityUpdated(visible: Bool) {
|
||||||
@@ -77,9 +98,9 @@ final class PeersNearbyManagerImpl: PeersNearbyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func updateLocation(_ location: CLLocation) {
|
private func updateLocation(_ location: CLLocation) {
|
||||||
self.updateDisposable.set(updatePeersNearbyVisibility(account: self.account, update: .location(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), background: true).start(error: { [weak self] _ in
|
self.updateDisposable.set(self.engine.peersNearby.updatePeersNearbyVisibility(update: .location(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), background: true).start(error: { [weak self] _ in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
let _ = updatePeersNearbyVisibility(account: strongSelf.account, update: .invisible, background: false).start()
|
let _ = strongSelf.engine.peersNearby.updatePeersNearbyVisibility(update: .invisible, background: false).start()
|
||||||
strongSelf.locationDisposable.set(nil)
|
strongSelf.locationDisposable.set(nil)
|
||||||
strongSelf.updateDisposable.set(nil)
|
strongSelf.updateDisposable.set(nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user