Skip to content

[Feature] Notifications content on lock screen #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Telegram-Mac/NotificationPreferencesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ private final class NotificationArguments {
let updateJoinedNotifications: (Bool) -> Void
let toggleBadge: (Bool)->Void
let toggleRequestUserAttention: ()->Void
let toggleContentsOnLockscreen: ()->Void
let toggleInAppSounds:(Bool)->Void
init(resetAllNotifications: @escaping() -> Void, toggleMessagesPreview:@escaping() -> Void, toggleNotifications:@escaping() -> Void, notificationTone:@escaping() -> Void, toggleIncludeUnreadChats:@escaping(Bool) -> Void, toggleCountUnreadMessages:@escaping(Bool) -> Void, toggleIncludeGroups:@escaping(Bool) -> Void, toggleIncludeChannels:@escaping(Bool) -> Void, allAcounts: @escaping()-> Void, snoof: @escaping()-> Void, updateJoinedNotifications: @escaping(Bool) -> Void, toggleBadge: @escaping(Bool)->Void, toggleRequestUserAttention: @escaping ()->Void, toggleInAppSounds: @escaping(Bool)->Void) {
init(resetAllNotifications: @escaping() -> Void, toggleMessagesPreview:@escaping() -> Void, toggleNotifications:@escaping() -> Void, notificationTone:@escaping() -> Void, toggleIncludeUnreadChats:@escaping(Bool) -> Void, toggleCountUnreadMessages:@escaping(Bool) -> Void, toggleIncludeGroups:@escaping(Bool) -> Void, toggleIncludeChannels:@escaping(Bool) -> Void, allAcounts: @escaping()-> Void, snoof: @escaping()-> Void, updateJoinedNotifications: @escaping(Bool) -> Void, toggleBadge: @escaping(Bool)->Void, toggleRequestUserAttention: @escaping ()->Void, toggleContentsOnLockscreen: @escaping ()->Void, toggleInAppSounds: @escaping(Bool)->Void) {
self.resetAllNotifications = resetAllNotifications
self.toggleMessagesPreview = toggleMessagesPreview
self.toggleNotifications = toggleNotifications
Expand All @@ -187,6 +188,7 @@ private final class NotificationArguments {
self.updateJoinedNotifications = updateJoinedNotifications
self.toggleBadge = toggleBadge
self.toggleRequestUserAttention = toggleRequestUserAttention
self.toggleContentsOnLockscreen = toggleContentsOnLockscreen
self.toggleInAppSounds = toggleInAppSounds
}
}
Expand All @@ -205,6 +207,7 @@ private let _id_new_contacts = InputDataIdentifier("_id_new_contacts")
private let _id_snoof = InputDataIdentifier("_id_snoof")
private let _id_tone = InputDataIdentifier("_id_tone")
private let _id_bounce = InputDataIdentifier("_id_bounce")
private let _id_lockscreen = InputDataIdentifier("_id_lockscreen")

private let _id_turnon_notifications = InputDataIdentifier("_id_turnon_notifications")
private let _id_turnon_notifications_title = InputDataIdentifier("_id_turnon_notifications_title")
Expand Down Expand Up @@ -279,6 +282,11 @@ private func notificationEntries(settings:InAppNotificationSettings, soundList:
})))
index += 1

entries.append(InputDataEntry.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_lockscreen, data: InputDataGeneralData(name: strings().notificationSettingsLockScreenContent, color: theme.colors.text, type: .switchable(settings.showContentsOnLockscreen), viewType: .innerItem, action: {
arguments.toggleContentsOnLockscreen()
})))
index += 1

entries.append(InputDataEntry.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_reset, data: InputDataGeneralData(name: strings().notificationSettingsResetNotifications, color: theme.colors.text, type: .none, viewType: .lastItem, action: {
arguments.resetAllNotifications()
})))
Expand Down Expand Up @@ -423,6 +431,10 @@ func NotificationPreferencesController(_ context: AccountContext, focusOnItemTag
_ = updateInAppNotificationSettingsInteractively(accountManager: context.sharedContext.accountManager, { value in
return value.withUpdatedRequestUserAttention(!value.requestUserAttention)
}).start()
}, toggleContentsOnLockscreen: {
_ = updateInAppNotificationSettingsInteractively(accountManager: context.sharedContext.accountManager, { value in
return value.withUpdatedShowContentsOnLockscreen(!value.showContentsOnLockscreen)
}).start()
}, toggleInAppSounds: { value in
FastSettings.toggleInAppSouds(value)
})
Expand Down
9 changes: 5 additions & 4 deletions Telegram-Mac/SharedNotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ final class SharedNotificationManager : NSObject, NSUserNotificationCenterDelega
return .complete()
}
} |> deliverOnMainQueue).start(next: { sources, images, inAppSettings, screenIsLocked, accountPeer, soundPath in
let hideContentOnLockScreen = screenIsLocked && !inAppSettings.showContentsOnLockscreen

if !primary, !inAppSettings.notifyAllAccounts {
return
Expand Down Expand Up @@ -523,7 +524,7 @@ final class SharedNotificationManager : NSObject, NSUserNotificationCenterDelega
hasReplyButton = false
}

if screenIsLocked {
if hideContentOnLockScreen {
title = appName
}

Expand Down Expand Up @@ -575,7 +576,7 @@ final class SharedNotificationManager : NSObject, NSUserNotificationCenterDelega
subText = "\(txt) → \(threadData.info.title)"
}

if !inAppSettings.displayPreviews || message.peers[message.id.peerId] is TelegramSecretChat || screenIsLocked {
if !inAppSettings.displayPreviews || message.peers[message.id.peerId] is TelegramSecretChat || hideContentOnLockScreen {
text = strings().notificationLockedPreview
subText = nil
}
Expand Down Expand Up @@ -614,14 +615,14 @@ final class SharedNotificationManager : NSObject, NSUserNotificationCenterDelega
notification.soundName = nil
}

if self.activeAccounts.accounts.count > 1 && !screenIsLocked {
if self.activeAccounts.accounts.count > 1 && !hideContentOnLockScreen {
title += " → \(accountPeer.addressName ?? accountPeer.displayTitle)"
}

notification.title = title
notification.informativeText = text as String
notification.subtitle = subText
notification.contentImage = screenIsLocked ? nil : images[message.id]
notification.contentImage = hideContentOnLockScreen ? nil : images[message.id]
notification.hasReplyButton = hasReplyButton

notification.hasActionButton = !message.wasScheduled
Expand Down
Binary file modified Telegram-Mac/en.lproj/Localizable.strings
Binary file not shown.
Loading