no message

This commit is contained in:
overtake
2017-05-16 19:02:37 +03:00
parent bdf58e4609
commit 130d805562
4 changed files with 73 additions and 20 deletions

View File

@@ -31,6 +31,8 @@
C27982531E73077800262BFD /* SecretChatStateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982521E73077800262BFD /* SecretChatStateBridge.swift */; };
C27982541E73078400262BFD /* SecretChatStateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982521E73077800262BFD /* SecretChatStateBridge.swift */; };
C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01749581E1092BC0057C89A /* RequestStartBot.swift */; };
C2F4ED1D1EC60064005F2696 /* RateCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2F4ED1C1EC60064005F2696 /* RateCall.swift */; };
C2F4ED1E1EC60064005F2696 /* RateCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2F4ED1C1EC60064005F2696 /* RateCall.swift */; };
C2FD33E11E680E9E008D13D4 /* RequestUserPhotos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */; };
C2FD33E21E680E9E008D13D4 /* RequestUserPhotos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */; };
C2FD33E41E687BF1008D13D4 /* PeerPhotoUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E31E687BF1008D13D4 /* PeerPhotoUpdater.swift */; };
@@ -530,6 +532,7 @@
C251D7421E65E50500283EDE /* StickerSetInstallation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerSetInstallation.swift; sourceTree = "<group>"; };
C27982501E72C97800262BFD /* MacosLegacy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacosLegacy.swift; sourceTree = "<group>"; };
C27982521E73077800262BFD /* SecretChatStateBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecretChatStateBridge.swift; sourceTree = "<group>"; };
C2F4ED1C1EC60064005F2696 /* RateCall.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RateCall.swift; sourceTree = "<group>"; };
C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestUserPhotos.swift; sourceTree = "<group>"; };
C2FD33E31E687BF1008D13D4 /* PeerPhotoUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeerPhotoUpdater.swift; sourceTree = "<group>"; };
C2FD33EA1E696C78008D13D4 /* GroupsInCommon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupsInCommon.swift; sourceTree = "<group>"; };
@@ -1277,6 +1280,7 @@
children = (
D0C50E331E93A86600F62E39 /* CallSessionManager.swift */,
D0B477721EBF54A20033A0AB /* RecentCalls.swift */,
C2F4ED1C1EC60064005F2696 /* RateCall.swift */,
);
name = Calls;
sourceTree = "<group>";
@@ -1723,6 +1727,7 @@
D0B8438C1DA7CF50005F29E1 /* BotInfo.swift in Sources */,
D033FEB31E61F3C000644997 /* ReportPeer.swift in Sources */,
D0575AF41E9FFDDE006F2541 /* ManagedSynchronizeSavedGifsOperations.swift in Sources */,
C2F4ED1D1EC60064005F2696 /* RateCall.swift in Sources */,
D021E0E21DB5401A00C6B04F /* StickerManagement.swift in Sources */,
D0BC38701E40853E0044D6FE /* UpdatePeers.swift in Sources */,
D0F3A8A81E82CD7D00B4C64C /* UpdatePeerChatInterfaceState.swift in Sources */,
@@ -1896,6 +1901,7 @@
D0B8442E1DAB91E0005F29E1 /* NBMetadataCoreTestMapper.m in Sources */,
D03C53731DAD5CA9004C17B3 /* CachedGroupData.swift in Sources */,
D019B1CD1E2E3B6A00F80DB3 /* SecretChatRekeySession.swift in Sources */,
C2F4ED1E1EC60064005F2696 /* RateCall.swift in Sources */,
D0F7AB2D1DCE889D009AD9A1 /* EditedMessageAttribute.swift in Sources */,
D0B844121DAB91CD005F29E1 /* Log.swift in Sources */,
D03C53721DAD5CA9004C17B3 /* CachedUserData.swift in Sources */,

View File

@@ -315,6 +315,7 @@ public final class AccountViewTracker {
context = existingContext
context.referenceData = referenceData
if context.timestamp == nil || abs(CFAbsoluteTimeGetCurrent() - context.timestamp!) > 60.0 * 5 {
context.timestamp = CFAbsoluteTimeGetCurrent()
dataUpdated = true
}
} else {

View File

@@ -28,6 +28,11 @@ public enum CallSessionTerminationReason {
case error(CallSessionError)
}
public struct ReportCallRating {
public let id:Int64
public let accessHash:Int64
}
enum CallSessionInternalState {
case ringing(id: Int64, accessHash: Int64, gAHash: Data, b: Data)
case accepting(id: Int64, accessHash: Int64, gAHash: Data, b: Data, disposable: Disposable)
@@ -37,7 +42,7 @@ enum CallSessionInternalState {
case confirming(id: Int64, accessHash: Int64, key: Data, keyId: Int64, keyVisualHash: Data, disposable: Disposable)
case active(id: Int64, accessHash: Int64, beginTimestamp: Int32, key: Data, keyId: Int64, keyVisualHash: Data, connections: CallSessionConnectionSet)
case dropping(Disposable)
case terminated(reason: CallSessionTerminationReason, reportRating: Bool)
case terminated(reason: CallSessionTerminationReason, reportRating: ReportCallRating?)
}
public typealias CallSessionInternalId = UUID
@@ -64,7 +69,7 @@ public enum CallSessionState {
case requesting(ringing: Bool)
case active(key: Data, keyVisualHash: Data, connections: CallSessionConnectionSet)
case dropping
case terminated(reason: CallSessionTerminationReason, reportRating: Bool)
case terminated(reason: CallSessionTerminationReason, reportRating: ReportCallRating?)
fileprivate init(_ context: CallSessionContext) {
switch context.state {
@@ -286,7 +291,7 @@ private final class CallSessionManagerContext {
dropData = (id, accessHash, .busy)
case let .requesting(_, disposable):
disposable.dispose()
context.state = .terminated(reason: .ended(.hungUp), reportRating: false)
context.state = .terminated(reason: .ended(.hungUp), reportRating: nil)
self.contextUpdated(internalId: internalId)
if context.isEmpty {
self.contexts.removeValue(forKey: internalId)
@@ -295,10 +300,10 @@ 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(completed: { [weak self] 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 in
if let strongSelf = self {
if let context = strongSelf.contexts[internalId] {
context.state = .terminated(reason: .ended(.hungUp), reportRating: false)
context.state = .terminated(reason: .ended(.hungUp), reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
strongSelf.contextUpdated(internalId: internalId)
if context.isEmpty {
strongSelf.contexts.removeValue(forKey: internalId)
@@ -420,27 +425,32 @@ private final class CallSessionManagerContext {
} else {
parsedReason = .ended(.hungUp)
}
switch context.state {
case let .accepting(_, _, _, _, disposable):
case let .accepting(id, accessHash, _, _, disposable):
disposable.dispose()
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
self.contextUpdated(internalId: internalId)
case .active:
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
case .active(let id, let accessHash, _, _, _, _, _):
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
self.contextUpdated(internalId: internalId)
case .awaitingConfirmation, .requested:
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
case .awaitingConfirmation(let id, let accessHash, _, _, _):
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
self.contextUpdated(internalId: internalId)
case let .confirming(_, _, _, _, _, disposable):
case .requested(let id, let accessHash, _, _, _, _):
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
self.contextUpdated(internalId: internalId)
case let .confirming(id, accessHash, _, _, _, disposable):
disposable.dispose()
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accessHash) : nil)
self.contextUpdated(internalId: internalId)
case let .requesting(_, disposable):
disposable.dispose()
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
context.state = .terminated(reason: parsedReason, reportRating: nil)
self.contextUpdated(internalId: internalId)
case .ringing:
context.state = .terminated(reason: parsedReason, reportRating: reportRating)
case .ringing(let id, let accesshash, _, _):
context.state = .terminated(reason: parsedReason, reportRating: reportRating ? ReportCallRating(id: id, accessHash: accesshash) : nil)
self.ringingStatesUpdated()
self.contextUpdated(internalId: internalId)
case .dropping, .terminated:
@@ -539,7 +549,7 @@ private final class CallSessionManagerContext {
strongSelf.contextIdByStableId[id] = internalId
strongSelf.contextUpdated(internalId: internalId)
case let .failed(error):
context.state = .terminated(reason: .error(error), reportRating: false)
context.state = .terminated(reason: .error(error), reportRating: nil)
strongSelf.contextUpdated(internalId: internalId)
if context.isEmpty {
strongSelf.contexts.removeValue(forKey: internalId)
@@ -789,7 +799,7 @@ private enum DropCallSessionReason {
case disconnect
}
private func dropCallSession(network: Network, addUpdates: @escaping (Api.Updates) -> Void, stableId: CallSessionStableId, accessHash: Int64, reason: DropCallSessionReason) -> Signal<Void, NoError> {
private func dropCallSession(network: Network, addUpdates: @escaping (Api.Updates) -> Void, stableId: CallSessionStableId, accessHash: Int64, reason: DropCallSessionReason) -> Signal<Bool, NoError> {
var mappedReason: Api.PhoneCallDiscardReason
var duration: Int32 = 0
switch reason {
@@ -808,10 +818,32 @@ private func dropCallSession(network: Network, addUpdates: @escaping (Api.Update
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
return .single(nil)
}
|> mapToSignal { updates -> Signal<Void, NoError> in
|> mapToSignal { updates -> Signal<Bool, NoError> in
var report:Bool = false
if let updates = updates {
switch updates {
case .updates(let updates, _, _, _, _):
for update in updates {
switch update {
case .updatePhoneCall(let phoneCall):
switch phoneCall {
case.phoneCallDiscarded(let values):
report = (values.flags & (1 << 2)) != 0
default:
break
}
break
default:
break
}
}
default:
break
}
addUpdates(updates)
}
return .complete()
return .single(report)
}
}

View File

@@ -0,0 +1,14 @@
import Foundation
#if os(macOS)
import PostboxMac
import MtProtoKitMac
import SwiftSignalKitMac
#else
import Postbox
import MtProtoKitDynamic
import SwiftSignalKit
#endif
public func rateCall(account:Account, report:ReportCallRating, starsCount:Int32, comment:String = "") -> Signal<Void, Void> {
return account.network.request(Api.functions.phone.setCallRating(peer: Api.InputPhoneCall.inputPhoneCall(id: report.id, accessHash: report.accessHash), rating: starsCount, comment: comment)) |> retryRequest |> map {_ in}
}