forked from wikimedia/wikipedia-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wikimedia#4458 from wikimedia/block-messages-final-2
Better Block Message Support
- Loading branch information
Showing
30 changed files
with
1,146 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Foundation | ||
|
||
/// An object that is passed through from fetchers to view controllers, for reference when displaying blocked errors in a BlockedPanelViewController. | ||
@objc public class MediaWikiAPIBlockedDisplayError: NSObject { | ||
|
||
// Fully resolved html to display in the blocked panel. | ||
@objc public let messageHtml: String | ||
|
||
// Base url to be referenced when user taps a relative link within the messageHtml in the blocked panel. | ||
public let linkBaseURL: URL | ||
|
||
// Error code, passed through from original MediaWikiAPIError. Currently used for logging. | ||
public let code: String | ||
|
||
public init(messageHtml: String, linkBaseURL: URL, code: String) { | ||
self.messageHtml = messageHtml | ||
self.linkBaseURL = linkBaseURL | ||
self.code = code | ||
} | ||
} | ||
|
||
|
||
/// Represents errors that come in the MediaWiki API response. | ||
/// See https://www.mediawiki.org/wiki/API:Errors_and_warnings | ||
public struct MediaWikiAPIError: Codable { | ||
|
||
public struct Data: Codable { | ||
public struct BlockInfo: Codable { | ||
let blockReason: String | ||
let blockPartial: Bool | ||
let blockedBy: String | ||
let blockID: Int64 | ||
let blockExpiry: String | ||
let blockedTimestamp: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case blockReason = "blockreason" | ||
case blockPartial = "blockpartial" | ||
case blockedBy = "blockedby" | ||
case blockID = "blockid" | ||
case blockExpiry = "blockexpiry" | ||
case blockedTimestamp = "blockedtimestamp" | ||
} | ||
|
||
init?(dict: [String: Any]) { | ||
|
||
guard let blockReason = dict["blockreason"] as? String, | ||
let blockPartial = dict["blockpartial"] as? Bool, | ||
let blockedBy = dict["blockedby"] as? String, | ||
let blockID = dict["blockid"] as? Int64, | ||
let blockExpiry = dict["blockexpiry"] as? String, | ||
let blockedTimestamp = dict["blockedtimestamp"] as? String else { | ||
return nil | ||
} | ||
|
||
self.blockReason = blockReason | ||
self.blockPartial = blockPartial | ||
self.blockedBy = blockedBy | ||
self.blockID = blockID | ||
self.blockExpiry = blockExpiry | ||
self.blockedTimestamp = blockedTimestamp | ||
} | ||
} | ||
|
||
let blockInfo: BlockInfo? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case blockInfo = "blockinfo" | ||
} | ||
|
||
init?(dict: [String: Any]) { | ||
|
||
guard let blockInfoDict = dict["blockinfo"] as? [String: Any] else { | ||
self.blockInfo = nil | ||
return | ||
} | ||
|
||
self.blockInfo = BlockInfo(dict: blockInfoDict) | ||
} | ||
} | ||
|
||
public let code: String | ||
let html: String | ||
let data: Data? | ||
|
||
init?(dict: [String: Any]) { | ||
|
||
guard let code = dict["code"] as? String, | ||
let html = dict["html"] as? String | ||
else { | ||
return nil | ||
} | ||
|
||
self.code = code | ||
self.html = html | ||
|
||
guard let dataDict = dict["data"] as? [String: Any] else { | ||
self.data = nil | ||
return | ||
} | ||
|
||
self.data = Data(dict: dataDict) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.