mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Locally hide notification text when locked
This commit is contained in:
parent
9e5db9c4dc
commit
1e437ee1a8
@ -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,13 +316,30 @@ static void reportMemory() {
|
||||
title = [title stringByAppendingString:@" 🔕"];
|
||||
}
|
||||
_bestAttemptContent.title = title;
|
||||
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 = @"";
|
||||
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"];
|
||||
if ([threadIdString isKindOfClass:[NSString class]]) {
|
||||
|
||||
11
submodules/NotificationsPresentationData/BUCK
Normal file
11
submodules/NotificationsPresentationData/BUCK
Normal file
@ -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",
|
||||
],
|
||||
)
|
||||
@ -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"
|
||||
}
|
||||
@ -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<Account?, NoError>) {
|
||||
init(basePath: String, activeAccount: Signal<Account?, NoError>, presentationData: Signal<PresentationData, NoError>) {
|
||||
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user