mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
e789170a1a
commit
b711016755
@ -9,9 +9,9 @@ public enum DeviceLocationMode: Int32 {
|
||||
private final class DeviceLocationSubscriber {
|
||||
let id: Int32
|
||||
let mode: DeviceLocationMode
|
||||
let update: (CLLocationCoordinate2D, Double, Double?) -> Void
|
||||
let update: (CLLocation, Double?) -> Void
|
||||
|
||||
init(id: Int32, mode: DeviceLocationMode, update: @escaping (CLLocationCoordinate2D, Double, Double?) -> Void) {
|
||||
init(id: Int32, mode: DeviceLocationMode, update: @escaping (CLLocation, Double?) -> Void) {
|
||||
self.id = id
|
||||
self.mode = mode
|
||||
self.update = update
|
||||
@ -39,7 +39,7 @@ public final class DeviceLocationManager: NSObject {
|
||||
private var subscribers: [DeviceLocationSubscriber] = []
|
||||
private var currentTopMode: DeviceLocationMode?
|
||||
|
||||
private var currentLocation: (CLLocationCoordinate2D, Double)?
|
||||
private var currentLocation: CLLocation?
|
||||
private var currentHeading: CLHeading?
|
||||
|
||||
public init(queue: Queue, log: ((String) -> Void)? = nil) {
|
||||
@ -56,12 +56,12 @@ public final class DeviceLocationManager: NSObject {
|
||||
}
|
||||
self.manager.delegate = self
|
||||
self.manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
|
||||
self.manager.distanceFilter = 10.0
|
||||
self.manager.distanceFilter = 5.0
|
||||
self.manager.activityType = .other
|
||||
self.manager.pausesLocationUpdatesAutomatically = false
|
||||
}
|
||||
|
||||
public func push(mode: DeviceLocationMode, updated: @escaping (CLLocationCoordinate2D, Double, Double?) -> Void) -> Disposable {
|
||||
public func push(mode: DeviceLocationMode, updated: @escaping (CLLocation, Double?) -> Void) -> Disposable {
|
||||
assert(self.queue.isCurrent())
|
||||
|
||||
let id = self.nextSubscriberId
|
||||
@ -69,7 +69,7 @@ public final class DeviceLocationManager: NSObject {
|
||||
self.subscribers.append(DeviceLocationSubscriber(id: id, mode: mode, update: updated))
|
||||
|
||||
if let currentLocation = self.currentLocation {
|
||||
updated(currentLocation.0, currentLocation.1, self.currentHeading?.magneticHeading)
|
||||
updated(currentLocation, self.currentHeading?.magneticHeading)
|
||||
}
|
||||
|
||||
self.updateTopMode()
|
||||
@ -125,9 +125,9 @@ extension DeviceLocationManager: CLLocationManagerDelegate {
|
||||
|
||||
if let location = locations.first {
|
||||
if self.currentTopMode != nil {
|
||||
self.currentLocation = (location.coordinate, location.horizontalAccuracy)
|
||||
self.currentLocation = location
|
||||
for subscriber in self.subscribers {
|
||||
subscriber.update(location.coordinate, location.horizontalAccuracy, self.currentHeading?.magneticHeading)
|
||||
subscriber.update(location, self.currentHeading?.magneticHeading)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,7 +140,7 @@ extension DeviceLocationManager: CLLocationManagerDelegate {
|
||||
self.currentHeading = newHeading
|
||||
if let currentLocation = self.currentLocation {
|
||||
for subscriber in self.subscribers {
|
||||
subscriber.update(currentLocation.0, currentLocation.1, newHeading.magneticHeading)
|
||||
subscriber.update(currentLocation, newHeading.magneticHeading)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,8 +150,8 @@ extension DeviceLocationManager: CLLocationManagerDelegate {
|
||||
public func currentLocationManagerCoordinate(manager: DeviceLocationManager, timeout timeoutValue: Double) -> Signal<CLLocationCoordinate2D?, NoError> {
|
||||
return (
|
||||
Signal { subscriber in
|
||||
let disposable = manager.push(mode: .precise, updated: { coordinate, _, _ in
|
||||
subscriber.putNext(coordinate)
|
||||
let disposable = manager.push(mode: .precise, updated: { location, _ in
|
||||
subscriber.putNext(location.coordinate)
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
return disposable
|
||||
|
@ -45,6 +45,9 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
|
||||
|
||||
private var prevoiusHorizontalStrideInterval: Int = 1
|
||||
|
||||
public var hourly: Bool = false
|
||||
public var min5: Bool = false
|
||||
|
||||
override public init(chartsCollection: ChartsCollection) {
|
||||
self.initialChartCollection = chartsCollection
|
||||
graphControllers = chartsCollection.chartValues.map { _ in GraphController() }
|
||||
@ -252,8 +255,19 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController {
|
||||
}
|
||||
|
||||
func updateHorizontalLimits(horizontalRange: ClosedRange<CGFloat>, animated: Bool) {
|
||||
var scaleType: ChartScaleType = .day
|
||||
if isZoomed {
|
||||
scaleType = .minutes5
|
||||
} else {
|
||||
if self.hourly {
|
||||
scaleType = .hour
|
||||
} else if self.min5 {
|
||||
scaleType = .minutes5
|
||||
}
|
||||
}
|
||||
|
||||
if let (stride, labels) = horizontalLimitsLabels(horizontalRange: horizontalRange,
|
||||
scaleType: isZoomed ? .minutes5 : .day,
|
||||
scaleType: scaleType,
|
||||
prevoiusHorizontalStrideInterval: prevoiusHorizontalStrideInterval) {
|
||||
self.horizontalScalesRenderer.setup(labels: labels, animated: animated)
|
||||
self.prevoiusHorizontalStrideInterval = stride
|
||||
|
@ -16,6 +16,8 @@ public enum ChartType {
|
||||
case step
|
||||
case twoAxisStep
|
||||
case hourlyStep
|
||||
case twoAxisHourlyStep
|
||||
case twoAxis5MinStep
|
||||
}
|
||||
|
||||
public extension ChartTheme {
|
||||
@ -90,6 +92,16 @@ public func createChartController(_ data: String, type: ChartType, getDetailsDat
|
||||
case .hourlyStep:
|
||||
controller = StepBarsChartController(chartsCollection: collection, hourly: true)
|
||||
controller.isZoomable = false
|
||||
case .twoAxisHourlyStep:
|
||||
let stepController = TwoAxisStepBarsChartController(chartsCollection: collection)
|
||||
stepController.hourly = true
|
||||
controller = stepController
|
||||
controller.isZoomable = false
|
||||
case .twoAxis5MinStep:
|
||||
let stepController = TwoAxisStepBarsChartController(chartsCollection: collection)
|
||||
stepController.min5 = true
|
||||
controller = stepController
|
||||
controller.isZoomable = false
|
||||
}
|
||||
controller.getDetailsData = { date, completion in
|
||||
getDetailsData(date, { detailsData in
|
||||
|
@ -107,9 +107,13 @@ public final class LiveLocationManagerImpl: LiveLocationManager {
|
||||
if let strongSelf = self {
|
||||
if value {
|
||||
let queue = strongSelf.queue
|
||||
strongSelf.deviceLocationDisposable.set(strongSelf.locationManager.push(mode: .precise, updated: { coordinate, accuracyRadius, heading in
|
||||
strongSelf.deviceLocationDisposable.set(strongSelf.locationManager.push(mode: .precise, updated: { location, heading in
|
||||
queue.async {
|
||||
self?.updateDeviceCoordinate(coordinate, accuracyRadius: accuracyRadius, heading: heading)
|
||||
var effectiveHeading = heading ?? location.course
|
||||
if location.speed > 1.0 {
|
||||
effectiveHeading = location.course
|
||||
}
|
||||
self?.updateDeviceCoordinate(location.coordinate, accuracyRadius: location.horizontalAccuracy, heading: effectiveHeading)
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
@ -213,7 +217,7 @@ public final class LiveLocationManagerImpl: LiveLocationManager {
|
||||
let ids = self.broadcastToMessageIds
|
||||
let remainingIds = Atomic<Set<MessageId>>(value: Set(ids.keys))
|
||||
for id in ids.keys {
|
||||
self.editMessageDisposables.set((requestEditLiveLocation(postbox: self.postbox, network: self.network, stateManager: self.stateManager, messageId: id, stop: false, coordinate: (latitude: coordinate.latitude, longitude: coordinate.longitude, accuracyRadius: Int32(accuracyRadius)), heading: Int32(heading ?? 0), proximityNotificationRadius: nil)
|
||||
self.editMessageDisposables.set((requestEditLiveLocation(postbox: self.postbox, network: self.network, stateManager: self.stateManager, messageId: id, stop: false, coordinate: (latitude: coordinate.latitude, longitude: coordinate.longitude, accuracyRadius: Int32(accuracyRadius)), heading: heading.flatMap { Int32($0) }, proximityNotificationRadius: nil)
|
||||
|> deliverOn(self.queue)).start(completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.editMessageDisposables.set(nil, forKey: id)
|
||||
|
@ -364,7 +364,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
|
||||
timeout = nil
|
||||
}
|
||||
|
||||
if let channel = subject.author as? TelegramChannel, case .broadcast = channel.info {
|
||||
if let channel = subject.author as? TelegramChannel, case .broadcast = channel.info, activeOwnLiveLocation == nil {
|
||||
} else {
|
||||
entries.append(.toggleLiveLocation(presentationData.theme, title, subtitle, userLocation?.coordinate, beginTime, timeout))
|
||||
}
|
||||
@ -388,6 +388,10 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
|
||||
}
|
||||
|
||||
for message in effectiveLiveLocations {
|
||||
if let channel = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = channel.info, message.threadId != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var liveBroadcastingTimeout: Int32 = 0
|
||||
if let location = getLocation(from: message), let timeout = location.liveBroadcastingTimeout {
|
||||
liveBroadcastingTimeout = timeout
|
||||
|
@ -385,8 +385,8 @@ public func themeAutoNightSettingsController(context: AccountContext) -> ViewCon
|
||||
|
||||
let forceUpdateLocation: () -> Void = {
|
||||
let locationCoordinates = Signal<(Double, Double), NoError> { subscriber in
|
||||
return context.sharedContext.locationManager!.push(mode: DeviceLocationMode.precise, updated: { coordinate, _, _ in
|
||||
subscriber.putNext((coordinate.latitude, coordinate.longitude))
|
||||
return context.sharedContext.locationManager!.push(mode: DeviceLocationMode.precise, updated: { location, _ in
|
||||
subscriber.putNext((location.coordinate.latitude, location.coordinate.longitude))
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
}
|
||||
|
@ -135,16 +135,15 @@ private enum StatsEntry: ItemListNodeEntry {
|
||||
})
|
||||
}, sectionId: self.section, style: .blocks)
|
||||
case let .publicForward(_, _, _, _, message):
|
||||
var views: Int = 0
|
||||
var views: Int32 = 0
|
||||
for attribute in message.attributes {
|
||||
if let viewsAttribute = attribute as? ViewCountMessageAttribute {
|
||||
views = viewsAttribute.count
|
||||
views = Int32(viewsAttribute.count)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var text: String = ""
|
||||
text += "\(views) views"
|
||||
let text: String = presentationData.strings.Stats_MessageViews(views)
|
||||
return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(timeFormat: .military, dateFormat: .dayFirst, dateSeparator: ".", decimalSeparator: ",", groupingSeparator: ""), nameDisplayOrder: .firstLast, context: arguments.context, peer: message.peers[message.id.peerId]!, height: .generic, aliasHandling: .standard, nameColor: .primary, nameStyle: .plain, presence: nil, text: .text(text), label: .none, editing: ItemListPeerItemEditing(editable: false, editing: false, revealed: nil), revealOptions: nil, switchValue: nil, enabled: true, highlighted: false, selectable: true, sectionId: self.section, action: {
|
||||
arguments.openMessage(message.id)
|
||||
}, setPeerIdWithRevealedOptions: { _, _ in }, removePeer: { _ in }, toggleUpdated: nil, contextAction: nil)
|
||||
@ -161,7 +160,17 @@ private func messageStatsControllerEntries(data: MessageStats?, messages: Search
|
||||
|
||||
if !data.interactionsGraph.isEmpty {
|
||||
entries.append(.interactionsTitle(presentationData.theme, presentationData.strings.Stats_MessageInteractionsTitle.uppercased()))
|
||||
entries.append(.interactionsGraph(presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, data.interactionsGraph, .twoAxisStep))
|
||||
|
||||
var chartType: ChartType
|
||||
if data.interactionsGraphDelta == 3600 {
|
||||
chartType = .twoAxisHourlyStep
|
||||
} else if data.interactionsGraphDelta == 300 {
|
||||
chartType = .twoAxis5MinStep
|
||||
} else {
|
||||
chartType = .twoAxisStep
|
||||
}
|
||||
|
||||
entries.append(.interactionsGraph(presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, data.interactionsGraph, chartType))
|
||||
}
|
||||
|
||||
if let messages = messages, !messages.messages.isEmpty {
|
||||
|
@ -9,13 +9,13 @@ public struct MessageStats: Equatable {
|
||||
public let views: Int
|
||||
public let forwards: Int
|
||||
public let interactionsGraph: StatsGraph
|
||||
public let detailedInteractionsGraph: StatsGraph?
|
||||
public let interactionsGraphDelta: Int64
|
||||
|
||||
init(views: Int, forwards: Int, interactionsGraph: StatsGraph, detailedInteractionsGraph: StatsGraph?) {
|
||||
init(views: Int, forwards: Int, interactionsGraph: StatsGraph, interactionsGraphDelta: Int64) {
|
||||
self.views = views
|
||||
self.forwards = forwards
|
||||
self.interactionsGraph = interactionsGraph
|
||||
self.detailedInteractionsGraph = detailedInteractionsGraph
|
||||
self.interactionsGraphDelta = interactionsGraphDelta
|
||||
}
|
||||
|
||||
public static func == (lhs: MessageStats, rhs: MessageStats) -> Bool {
|
||||
@ -28,14 +28,14 @@ public struct MessageStats: Equatable {
|
||||
if lhs.interactionsGraph != rhs.interactionsGraph {
|
||||
return false
|
||||
}
|
||||
if lhs.detailedInteractionsGraph != rhs.detailedInteractionsGraph {
|
||||
if lhs.interactionsGraphDelta != rhs.interactionsGraphDelta {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public func withUpdatedInteractionsGraph(_ interactionsGraph: StatsGraph) -> MessageStats {
|
||||
return MessageStats(views: self.views, forwards: self.forwards, interactionsGraph: interactionsGraph, detailedInteractionsGraph: self.detailedInteractionsGraph)
|
||||
return MessageStats(views: self.views, forwards: self.forwards, interactionsGraph: interactionsGraph, interactionsGraphDelta: self.interactionsGraphDelta)
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,16 +86,24 @@ private func requestMessageStats(postbox: Postbox, network: Network, datacenterI
|
||||
|> mapToSignal { result -> Signal<MessageStats?, MTRpcError> in
|
||||
if case let .messageStats(apiViewsGraph) = result {
|
||||
let interactionsGraph = StatsGraph(apiStatsGraph: apiViewsGraph)
|
||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||
if case let .Loaded(tokenValue, _) = interactionsGraph, let token = tokenValue, Int64(message.timestamp + 60 * 60 * 24 * 2) > Int64(timestamp) {
|
||||
return requestGraph(network: network, datacenterId: datacenterId, token: token, x: 1601596800000)
|
||||
|> castError(MTRpcError.self)
|
||||
|> map { detailedGraph -> MessageStats? in
|
||||
return MessageStats(views: views, forwards: forwards, interactionsGraph: interactionsGraph, detailedInteractionsGraph: detailedGraph)
|
||||
var interactionsGraphDelta: Int64 = 86400
|
||||
if case let .Loaded(_, data) = interactionsGraph {
|
||||
if let start = data.range(of: "[\"x\",") {
|
||||
let substring = data.suffix(from: start.upperBound)
|
||||
if let end = substring.range(of: "],") {
|
||||
let valuesString = substring.prefix(through: substring.index(before: end.lowerBound))
|
||||
let values = valuesString.components(separatedBy: ",").compactMap { Int64($0) }
|
||||
if values.count > 1 {
|
||||
let first = values[0]
|
||||
let second = values[1]
|
||||
let delta = abs(second - first) / 1000
|
||||
interactionsGraphDelta = delta
|
||||
}
|
||||
} else {
|
||||
return .single(MessageStats(views: views, forwards: forwards, interactionsGraph: interactionsGraph, detailedInteractionsGraph: nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return .single(MessageStats(views: views, forwards: forwards, interactionsGraph: interactionsGraph, interactionsGraphDelta: interactionsGraphDelta))
|
||||
} else {
|
||||
return .single(nil)
|
||||
}
|
||||
|
@ -445,9 +445,9 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
|
||||
case let .geoProximityReached(fromId, toId, distance):
|
||||
let distanceString = stringForDistance(strings: strings, distance: Double(distance))
|
||||
if toId == accountPeerId {
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_ProximityReachedYou(message.peers[fromId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? "", distanceString), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]))
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_ProximityReachedYou(message.peers[fromId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? "", distanceString), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, fromId)]))
|
||||
} else {
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_ProximityReached(message.peers[fromId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? "", distanceString, message.peers[toId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? ""), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id), (2, toId)]))
|
||||
attributedString = addAttributesToStringWithRanges(strings.Notification_ProximityReached(message.peers[fromId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? "", distanceString, message.peers[toId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? ""), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, fromId), (2, toId)]))
|
||||
}
|
||||
case .unknown:
|
||||
attributedString = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user