diff --git a/NotificationService/NotificationService.m b/NotificationService/NotificationService.m index de1777bd8d..b194d85da2 100644 --- a/NotificationService/NotificationService.m +++ b/NotificationService/NotificationService.m @@ -55,6 +55,8 @@ static void reportMemory() { NSString * _Nullable _rootPath; DeviceSpecificEncryptionParameters * _Nullable _deviceSpecificEncryptionParameters; + bool _isLockedValue; + NSString *_lockedMessageTextValue; NSString * _Nullable _baseAppBundleId; void (^_contentHandler)(UNNotificationContent *); UNMutableNotificationContent * _Nullable _bestAttemptContent; @@ -68,7 +70,7 @@ static void reportMemory() { @implementation NotificationServiceImpl -- (instancetype)initWithCountIncomingMessage:(void (^)(NSString *, int64_t, DeviceSpecificEncryptionParameters *, int64_t, int32_t))countIncomingMessage { +- (instancetype)initWithCountIncomingMessage:(void (^)(NSString *, int64_t, DeviceSpecificEncryptionParameters *, int64_t, int32_t))countIncomingMessage isLocked:(nonnull bool (^)(NSString * _Nonnull))isLocked lockedMessageText:(NSString *(^)(NSString *))lockedMessageText { self = [super init]; if (self != nil) { #if DEBUG @@ -89,6 +91,11 @@ static void reportMemory() { _rootPath = rootPath; if (rootPath != nil) { _deviceSpecificEncryptionParameters = [BuildConfig deviceSpecificEncryptionParameters:rootPath baseAppBundleId:_baseAppBundleId]; + + _isLockedValue = isLocked(rootPath); + if (_isLockedValue) { + _lockedMessageTextValue = lockedMessageText(rootPath); + } } } else { NSAssert(false, @"appGroupUrl == nil"); @@ -309,12 +316,29 @@ static void reportMemory() { title = [title stringByAppendingString:@" 🔕"]; } _bestAttemptContent.title = title; - _bestAttemptContent.subtitle = subtitle; - _bestAttemptContent.body = body; + if (_isLockedValue) { + _bestAttemptContent.subtitle = @""; + if (_lockedMessageTextValue != nil) { + _bestAttemptContent.body = _lockedMessageTextValue; + } else { + _bestAttemptContent.body = @"You have a new message"; + } + } else { + _bestAttemptContent.subtitle = subtitle; + _bestAttemptContent.body = body; + } } else if ([alert isKindOfClass:[NSString class]]) { _bestAttemptContent.title = @""; _bestAttemptContent.subtitle = @""; - _bestAttemptContent.body = alert; + if (_isLockedValue) { + if (_lockedMessageTextValue != nil) { + _bestAttemptContent.body = _lockedMessageTextValue; + } else { + _bestAttemptContent.body = @"You have a new message"; + } + } else { + _bestAttemptContent.body = alert; + } } NSString *threadIdString = aps[@"thread-id"]; diff --git a/submodules/NotificationsPresentationData/BUCK b/submodules/NotificationsPresentationData/BUCK new file mode 100644 index 0000000000..b58e009f65 --- /dev/null +++ b/submodules/NotificationsPresentationData/BUCK @@ -0,0 +1,11 @@ +load("//Config:buck_rule_macros.bzl", "static_library") + +static_library( + name = "NotificationsPresentationData", + srcs = glob([ + "Sources/**/*.swift", + ]), + frameworks = [ + "$SDKROOT/System/Library/Frameworks/Foundation.framework", + ], +) diff --git a/submodules/NotificationsPresentationData/Sources/NotificationsPresentationData.swift b/submodules/NotificationsPresentationData/Sources/NotificationsPresentationData.swift new file mode 100644 index 0000000000..cc1352f022 --- /dev/null +++ b/submodules/NotificationsPresentationData/Sources/NotificationsPresentationData.swift @@ -0,0 +1,13 @@ +import Foundation + +public struct NotificationsPresentationData: Codable, Equatable { + public var applicationLockedMessageString: String + + public init(applicationLockedMessageString: String) { + self.applicationLockedMessageString = applicationLockedMessageString + } +} + +public func notificationsPresentationDataPath(rootPath: String) -> String { + return rootPath + "/notificationsPresentationData.json" +} diff --git a/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift b/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift index 472f1f43c2..1484f199c1 100644 --- a/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift +++ b/submodules/TelegramUI/TelegramUI/WidgetDataContext.swift @@ -4,12 +4,16 @@ import Postbox import TelegramCore import SyncCore import WidgetItems +import TelegramPresentationData +import NotificationsPresentationData final class WidgetDataContext { private var currentAccount: Account? private var currentAccountDisposable: Disposable? + private var widgetPresentationDataDisposable: Disposable? + private var notificationPresentationDataDisposable: Disposable? - init(basePath: String, activeAccount: Signal) { + init(basePath: String, activeAccount: Signal, presentationData: Signal) { self.currentAccountDisposable = (activeAccount |> distinctUntilChanged(isEqual: { lhs, rhs in return lhs === rhs @@ -42,6 +46,32 @@ final class WidgetDataContext { let _ = try? FileManager.default.removeItem(atPath: path) } }) + + self.widgetPresentationDataDisposable = (presentationData + |> map { presentationData -> WidgetPresentationData in + return WidgetPresentationData(applicationLockedString: presentationData.strings.Widget_ApplicationLocked) + } + |> distinctUntilChanged).start(next: { value in + let path = widgetPresentationDataPath(rootPath: basePath) + if let data = try? JSONEncoder().encode(value) { + let _ = try? data.write(to: URL(fileURLWithPath: path), options: [.atomic]) + } else { + let _ = try? FileManager.default.removeItem(atPath: path) + } + }) + + self.notificationPresentationDataDisposable = (presentationData + |> map { presentationData -> NotificationsPresentationData in + return NotificationsPresentationData(applicationLockedMessageString: presentationData.strings.PUSH_LOCKED_MESSAGE("").0) + } + |> distinctUntilChanged).start(next: { value in + let path = notificationsPresentationDataPath(rootPath: basePath) + if let data = try? JSONEncoder().encode(value) { + let _ = try? data.write(to: URL(fileURLWithPath: path), options: [.atomic]) + } else { + let _ = try? FileManager.default.removeItem(atPath: path) + } + }) } deinit {