mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Fix debug call log submissions when voluntarily ending calls [skip ci]
This commit is contained in:
parent
6b75d42cd3
commit
14b59eba63
@ -419,14 +419,14 @@ public final class PresentationCallImpl: PresentationCall {
|
||||
Logger.shared.log("PresentationCall", "reportIncomingCall device in DND mode")
|
||||
Queue.mainQueue().async {
|
||||
if let strongSelf = self {
|
||||
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .busy)
|
||||
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .busy, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Logger.shared.log("PresentationCall", "reportIncomingCall error \(error)")
|
||||
Queue.mainQueue().async {
|
||||
if let strongSelf = self {
|
||||
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .hangUp)
|
||||
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .hangUp, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -451,7 +451,7 @@ public final class PresentationCallImpl: PresentationCall {
|
||||
presentationState = .connecting(keyVisualHash)
|
||||
case .failed:
|
||||
presentationState = nil
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .disconnect)
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
case .connected:
|
||||
let timestamp: Double
|
||||
if let activeTimestamp = self.activeTimestamp {
|
||||
@ -484,12 +484,14 @@ public final class PresentationCallImpl: PresentationCall {
|
||||
case let .terminated(id, _, options):
|
||||
self.audioSessionShouldBeActive.set(true)
|
||||
if wasActive {
|
||||
self.ongoingContext.stop(callId: id, sendDebugLogs: options.contains(.sendDebugLogs))
|
||||
let debugLogValue = Promise<String?>()
|
||||
self.ongoingContext.stop(callId: id, sendDebugLogs: options.contains(.sendDebugLogs), debugLogValue: debugLogValue)
|
||||
}
|
||||
default:
|
||||
self.audioSessionShouldBeActive.set(false)
|
||||
if wasActive {
|
||||
self.ongoingContext.stop()
|
||||
let debugLogValue = Promise<String?>()
|
||||
self.ongoingContext.stop(debugLogValue: debugLogValue)
|
||||
}
|
||||
}
|
||||
if case .terminated = sessionState.state, !wasTerminated {
|
||||
@ -602,15 +604,17 @@ public final class PresentationCallImpl: PresentationCall {
|
||||
}
|
||||
|
||||
public func hangUp() -> Signal<Bool, NoError> {
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .hangUp)
|
||||
self.ongoingContext.stop()
|
||||
let debugLogValue = Promise<String?>()
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .hangUp, debugLog: debugLogValue.get())
|
||||
self.ongoingContext.stop(debugLogValue: debugLogValue)
|
||||
|
||||
return self.hungUpPromise.get()
|
||||
}
|
||||
|
||||
public func rejectBusy() {
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .busy)
|
||||
self.ongoingContext.stop()
|
||||
self.callSessionManager.drop(internalId: self.internalId, reason: .busy, debugLog: .single(nil))
|
||||
let debugLog = Promise<String?>()
|
||||
self.ongoingContext.stop(debugLogValue: debugLog)
|
||||
}
|
||||
|
||||
public func toggleIsMuted() {
|
||||
|
@ -309,7 +309,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
|
||||
} else {
|
||||
for (account, _, state, _, _) in ringingStates {
|
||||
if state.id != self.currentCall?.internalId {
|
||||
account.callSessionManager.drop(internalId: state.id, reason: .missed)
|
||||
account.callSessionManager.drop(internalId: state.id, reason: .missed, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ private final class CallSessionManagerContext {
|
||||
}
|
||||
}
|
||||
|
||||
func drop(internalId: CallSessionInternalId, reason: DropCallReason) {
|
||||
func drop(internalId: CallSessionInternalId, reason: DropCallReason, debugLog: Signal<String?, NoError>) {
|
||||
if let context = self.contexts[internalId] {
|
||||
var dropData: (CallSessionStableId, Int64, DropCallSessionReason)?
|
||||
var wasRinging = false
|
||||
@ -421,10 +421,21 @@ private final class CallSessionManagerContext {
|
||||
|
||||
if let (id, accessHash, reason) = dropData {
|
||||
self.contextIdByStableId.removeValue(forKey: id)
|
||||
context.state = .dropping((dropCallSession(network: self.network, addUpdates: self.addUpdates, stableId: id, accessHash: accessHash, reason: reason) |> deliverOn(self.queue)).start(next: { [weak self] reportRating, sendDebugLogs in
|
||||
context.state = .dropping((dropCallSession(network: self.network, addUpdates: self.addUpdates, stableId: id, accessHash: accessHash, reason: reason)
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] reportRating, sendDebugLogs in
|
||||
if let strongSelf = self {
|
||||
if let context = strongSelf.contexts[internalId] {
|
||||
context.state = .terminated(id: id, accessHash: accessHash, reason: .ended(.hungUp), reportRating: reportRating, sendDebugLogs: sendDebugLogs)
|
||||
if sendDebugLogs {
|
||||
let network = strongSelf.network
|
||||
let _ = (debugLog
|
||||
|> timeout(5.0, queue: strongSelf.queue, alternate: .single(nil))
|
||||
|> deliverOnMainQueue).start(next: { debugLog in
|
||||
if let debugLog = debugLog {
|
||||
let _ = saveCallDebugLog(network: network, callId: CallId(id: id, accessHash: accessHash), log: debugLog).start()
|
||||
}
|
||||
})
|
||||
}
|
||||
strongSelf.contextUpdated(internalId: internalId)
|
||||
if context.isEmpty {
|
||||
strongSelf.contexts.removeValue(forKey: internalId)
|
||||
@ -443,14 +454,14 @@ private final class CallSessionManagerContext {
|
||||
func drop(stableId: CallSessionStableId, reason: DropCallReason) {
|
||||
if let internalId = self.contextIdByStableId[stableId] {
|
||||
self.contextIdByStableId.removeValue(forKey: stableId)
|
||||
self.drop(internalId: internalId, reason: reason)
|
||||
self.drop(internalId: internalId, reason: reason, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func dropAll() {
|
||||
let contexts = self.contexts
|
||||
for (internalId, _) in contexts {
|
||||
self.drop(internalId: internalId, reason: .hangUp)
|
||||
self.drop(internalId: internalId, reason: .hangUp, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,7 +474,7 @@ private final class CallSessionManagerContext {
|
||||
if case .accepting = context.state {
|
||||
switch result {
|
||||
case .failed:
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect)
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
case let .success(call):
|
||||
switch call {
|
||||
case let .waiting(config):
|
||||
@ -474,7 +485,7 @@ private final class CallSessionManagerContext {
|
||||
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections, maxLayer: maxLayer, allowsP2P: allowsP2P)
|
||||
strongSelf.contextUpdated(internalId: internalId)
|
||||
} else {
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect)
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,7 +513,7 @@ private final class CallSessionManagerContext {
|
||||
case let .requested(_, accessHash, a, gA, config, _):
|
||||
let p = config.p.makeData()
|
||||
if !MTCheckIsSafeGAOrB(self.network.encryptionProvider, gA, p) {
|
||||
self.drop(internalId: internalId, reason: .disconnect)
|
||||
self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
var key = MTExp(self.network.encryptionProvider, gB.makeData(), a, p)!
|
||||
|
||||
@ -528,13 +539,13 @@ private final class CallSessionManagerContext {
|
||||
if let updatedCall = updatedCall {
|
||||
strongSelf.updateSession(updatedCall, completion: { _ in })
|
||||
} else {
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect)
|
||||
strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
}
|
||||
}))
|
||||
self.contextUpdated(internalId: internalId)
|
||||
default:
|
||||
self.drop(internalId: internalId, reason: .disconnect)
|
||||
self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
} else {
|
||||
assertionFailure()
|
||||
@ -610,10 +621,10 @@ private final class CallSessionManagerContext {
|
||||
self.contextUpdated(internalId: internalId)
|
||||
}
|
||||
} else {
|
||||
self.drop(internalId: internalId, reason: .disconnect)
|
||||
self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
} else {
|
||||
self.drop(internalId: internalId, reason: .disconnect)
|
||||
self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
|
||||
}
|
||||
case let .confirming(id, accessHash, key, keyId, keyVisualHash, _):
|
||||
switch callProtocol {
|
||||
@ -761,9 +772,9 @@ public final class CallSessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public func drop(internalId: CallSessionInternalId, reason: DropCallReason) {
|
||||
public func drop(internalId: CallSessionInternalId, reason: DropCallReason, debugLog: Signal<String?, NoError>) {
|
||||
self.withContext { context in
|
||||
context.drop(internalId: internalId, reason: reason)
|
||||
context.drop(internalId: internalId, reason: reason, debugLog: debugLog)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ public func rateCall(account: Account, callId: CallId, starsCount: Int32, commen
|
||||
|> map { _ in }
|
||||
}
|
||||
|
||||
public func saveCallDebugLog(account: Account, callId: CallId, log: String) -> Signal<Void, NoError> {
|
||||
return account.network.request(Api.functions.phone.saveCallDebug(peer: Api.InputPhoneCall.inputPhoneCall(id: callId.id, accessHash: callId.accessHash), debug: .dataJSON(data: log)))
|
||||
public func saveCallDebugLog(network: Network, callId: CallId, log: String) -> Signal<Void, NoError> {
|
||||
return network.request(Api.functions.phone.saveCallDebug(peer: Api.InputPhoneCall.inputPhoneCall(id: callId.id, accessHash: callId.accessHash), debug: .dataJSON(data: log)))
|
||||
|> retryRequest
|
||||
|> map { _ in }
|
||||
}
|
||||
|
@ -241,9 +241,10 @@ public final class OngoingCallContext {
|
||||
}))
|
||||
}
|
||||
|
||||
public func stop(callId: CallId? = nil, sendDebugLogs: Bool = false) {
|
||||
public func stop(callId: CallId? = nil, sendDebugLogs: Bool = false, debugLogValue: Promise<String?>) {
|
||||
self.withContext { context in
|
||||
context.stop { debugLog, bytesSentWifi, bytesReceivedWifi, bytesSentMobile, bytesReceivedMobile in
|
||||
debugLogValue.set(.single(debugLog))
|
||||
let delta = NetworkUsageStatsConnectionsEntry(
|
||||
cellular: NetworkUsageStatsDirectionsEntry(
|
||||
incoming: bytesReceivedMobile,
|
||||
@ -254,7 +255,7 @@ public final class OngoingCallContext {
|
||||
updateAccountNetworkUsageStats(account: self.account, category: .call, delta: delta)
|
||||
|
||||
if let callId = callId, let debugLog = debugLog, sendDebugLogs {
|
||||
let _ = saveCallDebugLog(account: self.account, callId: callId, log: debugLog).start()
|
||||
let _ = saveCallDebugLog(network: self.account.network, callId: callId, log: debugLog).start()
|
||||
}
|
||||
}
|
||||
let derivedState = context.getDerivedState()
|
||||
|
Loading…
x
Reference in New Issue
Block a user