Supports blocking third-party sources

Blocked sources cannot be added by new users, or updated for existing users.
This commit is contained in:
Riley Testut
2023-05-15 16:25:25 -05:00
committed by Magesh K
parent b9dd6432a1
commit 254a9773ec
7 changed files with 151 additions and 23 deletions

View File

@@ -118,3 +118,40 @@ public extension UserDefaults
}
}
}
public extension UserDefaults
{
// Cache trustedSourceIDs just in case we need to check whether source is trusted or not.
@nonobjc var trustedSourceIDs: Set<String>? {
get {
guard let sourceIDs = _trustedSourceIDs else { return nil }
return Set(sourceIDs)
}
set {
_trustedSourceIDs = newValue?.map { $0 }
}
}
@NSManaged @objc(trustedSourceIDs) private var _trustedSourceIDs: [String]?
@nonobjc var blockedSourceIDs: Set<String>? {
get {
guard let sourceIDs = _blockedSourceIDs else { return nil }
return Set(sourceIDs)
}
set {
_blockedSourceIDs = newValue?.map { $0 }
}
}
@NSManaged @objc(blockedSourceIDs) private var _blockedSourceIDs: [String]?
@nonobjc var blockedSourceURLs: Set<URL>? {
get {
guard let sourceURLs = _blockedSourceURLs?.compactMap({ URL(string: $0) }) else { return nil }
return Set(sourceURLs)
}
set {
_blockedSourceURLs = newValue?.map { $0.absoluteString }
}
}
@NSManaged @objc(blockedSourceURLs) private var _blockedSourceURLs: [String]?
}