mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
35 lines
1.2 KiB
Swift
35 lines
1.2 KiB
Swift
import Foundation
|
|
import TelegramCore
|
|
import Postbox
|
|
|
|
public extension Message {
|
|
func isRestricted(platform: String, contentSettings: ContentSettings) -> Bool {
|
|
return self.restrictionReason(platform: platform, contentSettings: contentSettings) != nil
|
|
}
|
|
|
|
func restrictionReason(platform: String, contentSettings: ContentSettings) -> String? {
|
|
if let attribute = self.restrictedContentAttribute {
|
|
if let value = attribute.platformText(platform: platform, contentSettings: contentSettings) {
|
|
return value
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
public extension RestrictedContentMessageAttribute {
|
|
func platformText(platform: String, contentSettings: ContentSettings) -> String? {
|
|
for rule in self.rules {
|
|
if rule.isSensitive {
|
|
continue
|
|
}
|
|
if rule.platform == "all" || rule.platform == "ios" || contentSettings.addContentRestrictionReasons.contains(rule.platform) {
|
|
if !contentSettings.ignoreContentRestrictionReasons.contains(rule.reason) {
|
|
return rule.text
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|