Skip to content

Commit

Permalink
1.4.6 (187)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Nov 7, 2023
1 parent 424f446 commit def7aec
Showing 237 changed files with 50,635 additions and 630 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
"location" : "[email protected]:mobyrix/nicegram-assistant-ios.git",
"state" : {
"branch" : "develop",
"revision" : "980feb55910bdeef0e33e6107a0a927444eb04a0"
"revision" : "74a903bbc75af22ef19aa77ab20ba8df1ae0de27"
}
},
{
64 changes: 41 additions & 23 deletions Telegram/NotificationService/Sources/NotificationService.swift
Original file line number Diff line number Diff line change
@@ -675,12 +675,10 @@ private final class NotificationServiceHandler {
private let notificationKeyDisposable = MetaDisposable()
private let pollDisposable = MetaDisposable()

init?(queue: Queue, updateCurrentContent: @escaping (NotificationContent) -> Void, completed: @escaping () -> Void, payload: [AnyHashable: Any]) {
init?(queue: Queue, episode: String, updateCurrentContent: @escaping (NotificationContent) -> Void, completed: @escaping () -> Void, payload: [AnyHashable: Any]) {
//debug_linker_fail_test()
self.queue = queue

let episode = String(UInt32.random(in: 0 ..< UInt32.max), radix: 16)

guard let appBundleIdentifier = Bundle.main.bundleIdentifier, let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else {
return nil
}
@@ -1561,7 +1559,8 @@ private final class NotificationServiceHandler {
if !shouldSynchronizeState {
pollSignal = .complete()
} else {
stateManager.network.shouldKeepConnection.set(.single(true))
let shouldKeepConnection = stateManager.network.shouldKeepConnection
shouldKeepConnection.set(.single(true))
if peerId.namespace == Namespaces.Peer.CloudChannel {
Logger.shared.log("NotificationService \(episode)", "Will poll channel \(peerId)")

@@ -1572,6 +1571,9 @@ private final class NotificationServiceHandler {
peerId: peerId,
stateManager: stateManager
)
|> afterDisposed { [weak shouldKeepConnection] in
shouldKeepConnection?.set(.single(false))
}
} else {
Logger.shared.log("NotificationService \(episode)", "Will perform non-specific getDifference")
enum ControlError {
@@ -1587,6 +1589,9 @@ private final class NotificationServiceHandler {
}
}
|> restartIfError
|> afterDisposed { [weak shouldKeepConnection] in
shouldKeepConnection?.set(.single(false))
}

pollSignal = signal
}
@@ -1673,6 +1678,9 @@ private final class NotificationServiceHandler {
return
}

let shouldKeepConnection = stateManager.network.shouldKeepConnection
shouldKeepConnection.set(.single(true))

var fetchStoriesSignal: Signal<Void, NoError> = .single(Void())
fetchStoriesSignal = _internal_pollPeerStories(postbox: stateManager.postbox, network: stateManager.network, accountPeerId: stateManager.accountPeerId, peerId: peerId)
|> map { _ -> Void in
@@ -1763,6 +1771,9 @@ private final class NotificationServiceHandler {
}
}
)
|> afterDisposed { [weak shouldKeepConnection] in
shouldKeepConnection?.set(.single(false))
}

let fetchMediaSignal: Signal<Data?, NoError> = .single(nil)

@@ -1868,11 +1879,6 @@ private final class NotificationServiceHandler {
}
}

let pollSignal: Signal<Never, NoError>
pollSignal = .complete()

stateManager.network.shouldKeepConnection.set(.single(true))

let pollWithUpdatedContent: Signal<NotificationContent, NoError>
if interactionAuthorId != nil || messageId != nil {
pollWithUpdatedContent = stateManager.postbox.transaction { transaction -> NotificationContent in
@@ -1902,13 +1908,8 @@ private final class NotificationServiceHandler {

return content
}
|> then(
pollSignal
|> map { _ -> NotificationContent in }
)
} else {
pollWithUpdatedContent = pollSignal
|> map { _ -> NotificationContent in }
pollWithUpdatedContent = .complete()
}

var updatedContent = initialContent
@@ -1990,10 +1991,7 @@ private final class NotificationServiceHandler {
}

let completeRemoval: () -> Void = {
guard let strongSelf = self else {
return
}
var content = NotificationContent(isLockedMessage: nil)
let content = NotificationContent(isLockedMessage: nil)
Logger.shared.log("NotificationService \(episode)", "Updating content to \(content)")

updateCurrentContent(content)
@@ -2018,6 +2016,15 @@ private final class NotificationServiceHandler {
}
|> deliverOn(strongSelf.queue)).start(completed: {
UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { notifications in
let notificationDebugList = notifications.map { notification -> String in
if let peerIdString = notification.request.content.userInfo["peerId"] as? String, let peerIdValue = Int64(peerIdString), let messageIdString = notification.request.content.userInfo["msg_id"] as? String, let messageIdValue = Int32(messageIdString) {
return "peerId: \(peerIdValue), messageId: \(messageIdValue)"
} else {
return "unknown: \(String(describing: notification.request.content.userInfo))"
}
}.joined(separator: "\n")
Logger.shared.log("NotificationService \(episode)", "Filtering delivered notifications: \(notificationDebugList)")

var removeIdentifiers: [String] = []
for notification in notifications {
if let peerIdString = notification.request.content.userInfo["peerId"] as? String, let peerIdValue = Int64(peerIdString), let messageIdString = notification.request.content.userInfo["msg_id"] as? String, let messageIdValue = Int32(messageIdString) {
@@ -2129,12 +2136,16 @@ final class NotificationService: UNNotificationServiceExtension {
private var initialContent: UNNotificationContent?
private let content = Atomic<NotificationContent?>(value: nil)
private var contentHandler: ((UNNotificationContent) -> Void)?
private var episode: String?

override init() {
super.init()
}

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let episode = String(UInt32.random(in: 0 ..< UInt32.max), radix: 16)
self.episode = episode

self.initialContent = request.content
self.contentHandler = contentHandler

@@ -2145,6 +2156,7 @@ final class NotificationService: UNNotificationServiceExtension {
self.impl = QueueLocalObject(queue: queue, generate: { [weak self] in
return BoxedNotificationServiceHandler(value: NotificationServiceHandler(
queue: queue,
episode: episode,
updateCurrentContent: { value in
let _ = content.swap(value)
},
@@ -2155,15 +2167,17 @@ final class NotificationService: UNNotificationServiceExtension {
strongSelf.impl = nil

if let contentHandler = strongSelf.contentHandler {
Logger.shared.log("NotificationService \(episode)", "Complete handling notification")

strongSelf.contentHandler = nil

if let content = content.with({ $0 }) {
/*let request = UNNotificationRequest(identifier: UUID().uuidString, content: content.generate(), trigger: .none)
UNUserNotificationCenter.current().add(request)
contentHandler(UNMutableNotificationContent())*/

contentHandler(content.generate())
} else if let initialContent = strongSelf.initialContent {
contentHandler(initialContent)
}
} else {
Logger.shared.log("NotificationService \(episode)", "Attempted to repeatedly complete handling notification")
}
},
payload: request.content.userInfo
@@ -2173,6 +2187,10 @@ final class NotificationService: UNNotificationServiceExtension {

override func serviceExtensionTimeWillExpire() {
if let contentHandler = self.contentHandler {
self.contentHandler = nil

Logger.shared.log("NotificationService \(self.episode ?? "???")", "Completing due to serviceExtensionTimeWillExpire")

if let content = self.content.with({ $0 }) {
contentHandler(content.generate())
} else if let initialContent = self.initialContent {
2 changes: 2 additions & 0 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -10421,3 +10421,5 @@ Sorry for the inconvenience.";
"ChannelBoost.Or" = "or";

"Channel.ChannelColor" = "Channel Color";

"TextFormat.Code" = "Code";
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Intents.mobileprovision
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Share.mobileprovision
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Telegram.mobileprovision
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/WatchApp.mobileprovision
Binary file not shown.
Binary file not shown.
Binary file modified build-system/fake-codesigning/profiles/Widget.mobileprovision
Binary file not shown.
2 changes: 1 addition & 1 deletion submodules/AccountContext/Sources/AccountContext.swift
Original file line number Diff line number Diff line change
@@ -899,7 +899,7 @@ public protocol SharedAccountContext: AnyObject {
func chatAvailableMessageActions(engine: TelegramEngine, accountPeerId: EnginePeer.Id, messageIds: Set<EngineMessage.Id>, messages: [EngineMessage.Id: EngineMessage], peers: [EnginePeer.Id: EnginePeer]) -> Signal<ChatAvailableMessageActions, NoError>
func resolveUrl(context: AccountContext, peerId: PeerId?, url: String, skipUrlAuth: Bool) -> Signal<ResolvedUrl, NoError>
func resolveUrlWithProgress(context: AccountContext, peerId: PeerId?, url: String, skipUrlAuth: Bool) -> Signal<ResolveUrlResult, NoError>
func openResolvedUrl(_ resolvedUrl: ResolvedUrl, context: AccountContext, urlContext: OpenURLContext, navigationController: NavigationController?, forceExternal: Bool, openPeer: @escaping (EnginePeer, ChatControllerInteractionNavigateToPeer) -> Void, sendFile: ((FileMediaReference) -> Void)?, sendSticker: ((FileMediaReference, UIView, CGRect) -> Bool)?, requestMessageActionUrlAuth: ((MessageActionUrlSubject) -> Void)?, joinVoiceChat: ((PeerId, String?, CachedChannelData.ActiveCall) -> Void)?, present: @escaping (ViewController, Any?) -> Void, dismissInput: @escaping () -> Void, contentContext: Any?)
func openResolvedUrl(_ resolvedUrl: ResolvedUrl, context: AccountContext, urlContext: OpenURLContext, navigationController: NavigationController?, forceExternal: Bool, openPeer: @escaping (EnginePeer, ChatControllerInteractionNavigateToPeer) -> Void, sendFile: ((FileMediaReference) -> Void)?, sendSticker: ((FileMediaReference, UIView, CGRect) -> Bool)?, requestMessageActionUrlAuth: ((MessageActionUrlSubject) -> Void)?, joinVoiceChat: ((PeerId, String?, CachedChannelData.ActiveCall) -> Void)?, present: @escaping (ViewController, Any?) -> Void, dismissInput: @escaping () -> Void, contentContext: Any?, progress: Promise<Bool>?)
func openAddContact(context: AccountContext, firstName: String, lastName: String, phoneNumber: String, label: String, present: @escaping (ViewController, Any?) -> Void, pushController: @escaping (ViewController) -> Void, completed: @escaping () -> Void)
func openAddPersonContact(context: AccountContext, peerId: PeerId, pushController: @escaping (ViewController) -> Void, present: @escaping (ViewController, Any?) -> Void)
func presentContactsWarningSuppression(context: AccountContext, present: (ViewController, Any?) -> Void)
20 changes: 16 additions & 4 deletions submodules/AccountContext/Sources/ChatController.swift
Original file line number Diff line number Diff line change
@@ -322,6 +322,7 @@ public enum ChatTextInputStateTextAttributeType: Codable, Equatable {
case underline
case spoiler
case quote
case codeBlock(language: String?)

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
@@ -351,6 +352,8 @@ public enum ChatTextInputStateTextAttributeType: Codable, Equatable {
self = .spoiler
case 9:
self = .quote
case 10:
self = .codeBlock(language: try container.decodeIfPresent(String.self, forKey: "l"))
default:
assertionFailure()
self = .bold
@@ -384,6 +387,9 @@ public enum ChatTextInputStateTextAttributeType: Codable, Equatable {
try container.encode(8 as Int32, forKey: "t")
case .quote:
try container.encode(9 as Int32, forKey: "t")
case let .codeBlock(language):
try container.encode(10 as Int32, forKey: "t")
try container.encodeIfPresent(language, forKey: "l")
}
}
}
@@ -457,9 +463,13 @@ public struct ChatTextInputStateText: Codable, Equatable {
parsedAttributes.append(ChatTextInputStateTextAttribute(type: .underline, range: range.location ..< (range.location + range.length)))
} else if key == ChatTextInputAttributes.spoiler {
parsedAttributes.append(ChatTextInputStateTextAttribute(type: .spoiler, range: range.location ..< (range.location + range.length)))
} else if key == ChatTextInputAttributes.quote, let value = value as? ChatTextInputTextQuoteAttribute {
let _ = value
parsedAttributes.append(ChatTextInputStateTextAttribute(type: .quote, range: range.location ..< (range.location + range.length)))
} else if key == ChatTextInputAttributes.block, let value = value as? ChatTextInputTextQuoteAttribute {
switch value.kind {
case .quote:
parsedAttributes.append(ChatTextInputStateTextAttribute(type: .quote, range: range.location ..< (range.location + range.length)))
case let .code(language):
parsedAttributes.append(ChatTextInputStateTextAttribute(type: .codeBlock(language: language), range: range.location ..< (range.location + range.length)))
}
}
}
})
@@ -505,7 +515,9 @@ public struct ChatTextInputStateText: Codable, Equatable {
case .spoiler:
result.addAttribute(ChatTextInputAttributes.spoiler, value: true as NSNumber, range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
case .quote:
result.addAttribute(ChatTextInputAttributes.quote, value: ChatTextInputTextQuoteAttribute(), range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
result.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .quote), range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
case let .codeBlock(language):
result.addAttribute(ChatTextInputAttributes.block, value: ChatTextInputTextQuoteAttribute(kind: .code(language: language)), range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
}
}
return result
Loading

0 comments on commit def7aec

Please sign in to comment.