Codes and ads improvements

This commit is contained in:
Ilya Laktyushin 2024-09-20 18:34:06 +04:00
parent 24ca7ba16e
commit 39b27018bd
7 changed files with 19 additions and 10 deletions

View File

@ -12939,3 +12939,5 @@ Sorry for the inconvenience.";
"Notification.StarsGiveaway.Subtitle" = "You won a prize in a giveaway organized by **%1$@**.\n\nYour prize is **%2$@**.";
"Notification.StarsGiveaway.Subtitle.Stars_1" = "%@ Star";
"Notification.StarsGiveaway.Subtitle.Stars_any" = "%@ Stars";
"VerificationCodes.DescriptionText" = "This chat is used to receive verification codes from third-party services.";

View File

@ -576,7 +576,7 @@ private enum RevealOptionKey: Int32 {
}
private func canArchivePeer(id: EnginePeer.Id, accountPeerId: EnginePeer.Id) -> Bool {
if id.namespace == Namespaces.Peer.CloudUser && id.id._internalGetInt64Value() == 777000 {
if id.isTelegramNotifications {
return false
}
if id == accountPeerId {
@ -913,7 +913,7 @@ private final class ChatListMediaPreviewNode: ASDisplayNode {
}
}
private let loginCodeRegex = try? NSRegularExpression(pattern: "[\\d\\-]{5,7}", options: [])
private let loginCodeRegex = try? NSRegularExpression(pattern: "\\b\\d{5,8}\\b", options: [])
public class ChatListItemNode: ItemListRevealOptionsItemNode {
final class TopicItemNode: ASDisplayNode {
@ -2371,7 +2371,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
}
}
if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 {
if message.id.peerId.isTelegramNotifications || message.id.peerId.isVerificationCodes {
if let cached = currentCustomTextEntities, cached.matches(text: message.text) {
customTextEntities = cached
} else if let matches = loginCodeRegex?.matches(in: message.text, options: [], range: NSMakeRange(0, (message.text as NSString).length)) {

View File

@ -54,7 +54,7 @@ public final class DeviceLocationManager: NSObject {
self.manager.delegate = self
self.manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
// self.manager.distanceFilter = 5.0
self.manager.distanceFilter = kCLDistanceFilterNone
self.manager.activityType = .other
self.manager.pausesLocationUpdatesAutomatically = false
self.manager.headingFilter = 2.0

View File

@ -221,6 +221,8 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
}
}
let isAd = message.adAttribute != nil
var isReplyThread = false
if case .replyThread = chatLocation {
isReplyThread = true
@ -352,7 +354,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
contentFileValue = file
}
if shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: file) {
if shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: file, isAd: isAd) {
contentMediaAutomaticDownload = .full
} else if shouldPredownloadMedia(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, media: file) {
contentMediaAutomaticDownload = .prefetch
@ -404,7 +406,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
} else {
let contentMode: InteractiveMediaNodeContentMode = contentMediaAspectFilled ? .aspectFill : .aspectFit
let automaticDownload = shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: contentMediaValue)
let automaticDownload = shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: contentMediaValue, isAd: isAd)
let (_, initialImageWidth, refineLayout) = makeContentMedia(
context,
@ -435,7 +437,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
let contentFileContinueLayout: ChatMessageInteractiveFileNode.ContinueLayout?
if let contentFileValue {
let automaticDownload = shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: contentFileValue)
let automaticDownload = shouldDownloadMediaAutomatically(settings: automaticDownloadSettings, peerType: associatedData.automaticDownloadPeerType, networkType: associatedData.automaticDownloadNetworkType, authorPeerId: message.author?.id, contactsPeerIds: associatedData.contactsPeerIds, media: contentFileValue, isAd: isAd)
let (_, refineLayout) = makeContentFile(ChatMessageInteractiveFileNode.Arguments(
context: context,

View File

@ -7784,10 +7784,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return false
}
})
} else if peerId.namespace == Namespaces.Peer.CloudUser && peerId.id._internalGetInt64Value() == 777000 {
} else if peerId.isTelegramNotifications {
self.screenCaptureManager = ScreenCaptureDetectionManager(check: { [weak self] in
if let strongSelf = self, strongSelf.traceVisibility() {
let loginCodeRegex = try? NSRegularExpression(pattern: "[\\d\\-]{5,7}", options: [])
let loginCodeRegex = try? NSRegularExpression(pattern: "\\b\\d{5,7}\\b", options: [])
var loginCodesToInvalidate: [String] = []
strongSelf.chatDisplayNode.historyNode.forEachVisibleMessageItemNode({ itemNode in
if let text = itemNode.item?.message.text, let matches = loginCodeRegex?.matches(in: text, options: [], range: NSMakeRange(0, (text as NSString).length)), let match = matches.first {

View File

@ -446,6 +446,8 @@ func chatHistoryEntriesForView(
}
if case let .peer(peerId) = location, peerId.isReplies {
entries.insert(.ChatInfoEntry("", presentationData.strings.RepliesChat_DescriptionText, nil, nil, presentationData), at: 0)
} else if case let .peer(peerId) = location, peerId.isVerificationCodes {
entries.insert(.ChatInfoEntry("", presentationData.strings.VerificationCodes_DescriptionText, nil, nil, presentationData), at: 0)
} else if let cachedPeerData = cachedPeerData as? CachedUserData, let botInfo = cachedPeerData.botInfo, !botInfo.description.isEmpty {
entries.insert(.ChatInfoEntry(presentationData.strings.Bot_DescriptionTitle, botInfo.description, botInfo.photo, botInfo.video, presentationData), at: 0)
} else {

View File

@ -564,7 +564,10 @@ public func isAutodownloadEnabledForAnyPeerType(category: MediaAutoDownloadCateg
return category.contacts || category.otherPrivate || category.groups || category.channels
}
public func shouldDownloadMediaAutomatically(settings: MediaAutoDownloadSettings, peerType: MediaAutoDownloadPeerType, networkType: MediaAutoDownloadNetworkType, authorPeerId: PeerId? = nil, contactsPeerIds: Set<PeerId> = Set(), media: Media?, isStory: Bool = false) -> Bool {
public func shouldDownloadMediaAutomatically(settings: MediaAutoDownloadSettings, peerType: MediaAutoDownloadPeerType, networkType: MediaAutoDownloadNetworkType, authorPeerId: PeerId? = nil, contactsPeerIds: Set<PeerId> = Set(), media: Media?, isStory: Bool = false, isAd: Bool = false) -> Bool {
if isAd {
return true
}
if (networkType == .cellular && !settings.cellular.enabled) || (networkType == .wifi && !settings.wifi.enabled) {
return false
}