Skip to content

Commit

Permalink
Merge pull request #4207 from wikimedia/T307529
Browse files Browse the repository at this point in the history
Notifications - fix bugs with special character url fragments
  • Loading branch information
staykids authored May 4, 2022
2 parents 2aa732d + 3ec139d commit 8d36dde
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,20 @@ public class RemoteNotification: NSManagedObject {
}
}

public var primaryLinkHost: String? {
return messageLinks?.primary?.url?.host
public var linkHost: String? {
if let primaryLinkHost = messageLinks?.primary?.url?.host {
return primaryLinkHost
}

if let secondaryLinks = messageLinks?.secondary {
for secondaryLink in secondaryLinks {
if let secondaryHost = secondaryLink.url?.host {
return secondaryHost
}
}
}

return nil
}

public var primaryLinkFragment: String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RemoteNotificationLinks: NSObject, NSSecureCoding, Codable {
}

@objc(RemoteNotificationLink)
public class RemoteNotificationLink: NSObject, NSSecureCoding, Codable {
public final class RemoteNotificationLink: NSObject, NSSecureCoding, Codable {
public static var supportsSecureCoding: Bool = true

let type: String?
Expand All @@ -43,6 +43,20 @@ public class RemoteNotificationLink: NSObject, NSSecureCoding, Codable {
self.url = url
self.label = label as String?
}

public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
type = try? values.decode(String.self, forKey: .type)

let urlString = try? values.decode(String.self, forKey: .url)
if let urlString = urlString {
url = URL(string: urlString)
} else {
url = nil
}

label = try? values.decode(String.self, forKey: .label)
}

public required convenience init(coder decoder: NSCoder) {
let type = decoder.decodeObject(of: NSString.self, forKey: "type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension NotificationsCenterCommonViewModel {

var linkData: LinkData? {

guard let host = notification.primaryLinkHost ?? configuration.defaultSiteURL.host,
guard let host = notification.linkHost,
let wiki = notification.wiki else {
return nil
}
Expand Down

0 comments on commit 8d36dde

Please sign in to comment.