Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Only mark new features as fetched after call goes through #2713

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Only mark new features as fetched after call goes through
  • Loading branch information
BasThomas committed Apr 1, 2019
commit b5469386e76fa89797ba07430af350b04b5bc082
28 changes: 18 additions & 10 deletions Classes/Notifications/NewFeaturesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,25 @@ final class NewFeaturesController {
guard let url = fetchURL,
(testing == true || hasFetchedLatest == false)
else { return }
hasFetchedLatest = true

let task = session.dataTask(with: url) { (data, response, _) in
if let response = response as? HTTPURLResponse,
response.statusCode == 200,
let data = data,
let string = String(data: data, encoding: .utf8) {
DispatchQueue.main.async { [weak self] in
self?.latestMarkdown = string
success()
}
let task = session.dataTask(with: url) { data, response, error in
guard
let httpResponse = response as? HTTPURLResponse,
[200, 404].contains(httpResponse.statusCode),
Copy link
Collaborator

@jdisho jdisho Jun 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need to take into consideration 404. If the status is 404 and rest of the guard passes, means that hasFetchedLatest will be true. Which, in IMO, shouldn't be. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to care only about this range 200..<300.

let data = data else {
let message = """
"Expected a successfull or failing status code, but errored
with \(error?.localizedDescription ?? "no error") for
\(response?.description ?? "no response")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean httpResponse (instead of response)?

"""
return assertionFailure(message)
}
let string = String(decoding: data, as: UTF8.self)
DispatchQueue.main.async { [weak self] in
guard let strongSelf = self else { return }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think there is no need to write strongSelf. self would work.

strongSelf.hasFetchedLatest = true
strongSelf.latestMarkdown = string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not?

strongSelf.latestMarkdown = String(decoding: data, as: UTF8.self)

success()
}
}
task.resume()
Expand Down