Accommodate The Old Reader's unusual item ids when syncing article status.
This commit is contained in:
parent
071af20304
commit
1c208cd4ba
|
@ -779,7 +779,7 @@ private extension ReaderAPIAccountDelegate {
|
|||
return d
|
||||
}
|
||||
|
||||
func sendArticleStatuses(_ statuses: [SyncStatus], apiCall: ([Int], @escaping (Result<Void, Error>) -> Void) -> Void, completion: @escaping (() -> Void)) {
|
||||
func sendArticleStatuses(_ statuses: [SyncStatus], apiCall: ([String], @escaping (Result<Void, Error>) -> Void) -> Void, completion: @escaping (() -> Void)) {
|
||||
guard !statuses.isEmpty else {
|
||||
completion()
|
||||
return
|
||||
|
@ -787,7 +787,7 @@ private extension ReaderAPIAccountDelegate {
|
|||
|
||||
let group = DispatchGroup()
|
||||
|
||||
let articleIDs = statuses.compactMap { Int($0.articleID) }
|
||||
let articleIDs = statuses.compactMap { $0.articleID }
|
||||
let articleIDGroups = articleIDs.chunked(into: 1000)
|
||||
for articleIDGroup in articleIDGroups {
|
||||
|
||||
|
@ -795,11 +795,11 @@ private extension ReaderAPIAccountDelegate {
|
|||
apiCall(articleIDGroup) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.database.deleteSelectedForProcessing(articleIDGroup.map { String($0) } )
|
||||
self.database.deleteSelectedForProcessing(articleIDGroup.map { $0 } )
|
||||
group.leave()
|
||||
case .failure(let error):
|
||||
os_log(.error, log: self.log, "Article status sync call failed: %@.", error.localizedDescription)
|
||||
self.database.resetSelectedForProcessing(articleIDGroup.map { String($0) } )
|
||||
self.database.resetSelectedForProcessing(articleIDGroup.map { $0 } )
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -842,7 +842,7 @@ final class ReaderAPICaller: NSObject {
|
|||
|
||||
}
|
||||
|
||||
func updateStateToEntries(entries: [Int], state: ReaderState, add: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func updateStateToEntries(entries: [String], state: ReaderState, add: Bool, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let baseURL = APIBaseURL else {
|
||||
completion(.failure(CredentialsError.incompleteCredentials))
|
||||
return
|
||||
|
@ -858,9 +858,13 @@ final class ReaderAPICaller: NSObject {
|
|||
request.httpMethod = "POST"
|
||||
|
||||
// Get ids from above into hex representation of value
|
||||
let idsToFetch = entries.map({ (idValue) -> String in
|
||||
let idHexString = String(format: "%.16llx", idValue)
|
||||
return "i=\(idHexString)"
|
||||
let idsToFetch = entries.map({ idValue -> String in
|
||||
if self.variant == .theOldReader {
|
||||
return "i=tag:google.com,2005:reader/item/\(idValue)"
|
||||
} else {
|
||||
let idHexString = String(format: "%.16llx", idValue)
|
||||
return "i=\(idHexString)"
|
||||
}
|
||||
}).joined(separator:"&")
|
||||
|
||||
let actionIndicator = add ? "a" : "r"
|
||||
|
@ -883,21 +887,21 @@ final class ReaderAPICaller: NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
func createUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func createUnreadEntries(entries: [String], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
updateStateToEntries(entries: entries, state: .read, add: false, completion: completion)
|
||||
}
|
||||
|
||||
func deleteUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func deleteUnreadEntries(entries: [String], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
updateStateToEntries(entries: entries, state: .read, add: true, completion: completion)
|
||||
|
||||
}
|
||||
|
||||
func createStarredEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func createStarredEntries(entries: [String], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
updateStateToEntries(entries: entries, state: .starred, add: true, completion: completion)
|
||||
|
||||
}
|
||||
|
||||
func deleteStarredEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func deleteStarredEntries(entries: [String], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
updateStateToEntries(entries: entries, state: .starred, add: false, completion: completion)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue