diff --git a/SwiftyInsta/Helpers/PaginationHelper.swift b/SwiftyInsta/Helpers/PaginationHelper.swift index a160121..c3edf9e 100644 --- a/SwiftyInsta/Helpers/PaginationHelper.swift +++ b/SwiftyInsta/Helpers/PaginationHelper.swift @@ -132,6 +132,10 @@ class PaginationHelper: Handler { options: options, delay: delay, process: process) { [weak self] in + // update the pagination parameters. + nextPaginationParameters.currentMaxId = nextPaginationParameters.nextMaxId + nextPaginationParameters.nextMaxId = nil + // check for handler. guard let handler = self?.handler else { return completion(.failure(GenericError.weakObjectReleased), nextPaginationParameters) } @@ -139,6 +143,7 @@ class PaginationHelper: Handler { switch $0 { case .failure(let error): completion(.failure(error), nextPaginationParameters) case .success(let page): + nextPaginationParameters.nextMaxId = nextPage(page) nextPaginationParameters.loadedPages += 1 // splice items. let new = splice(page) @@ -153,7 +158,6 @@ class PaginationHelper: Handler { completion(.success(responses), nextPaginationParameters) } } - nextPaginationParameters.nextMaxId = nextPage(page) guard !(nextPaginationParameters.nextMaxId ?? "").isEmpty else { return handler.settings.queues.response.async { completion(.success(responses), nextPaginationParameters) diff --git a/SwiftyInsta/Helpers/PaginationParameters.swift b/SwiftyInsta/Helpers/PaginationParameters.swift index 4db5875..cf563ff 100644 --- a/SwiftyInsta/Helpers/PaginationParameters.swift +++ b/SwiftyInsta/Helpers/PaginationParameters.swift @@ -14,11 +14,13 @@ public class PaginationParameters { public var maxPagesToLoad: Int /// The number of pages already loaded. Defaults to `0`. public var loadedPages: Int = 0 + /// The current request `maxId`. Defaults to `nil`. + public var currentMaxId: String? /// The next `maxId`. Defaults to `nil`. public var nextMaxId: String? /// Whether there's something left to load. - public var canLoadMore: Bool { return loadedPages < maxPagesToLoad } + var canLoadMore: Bool { return loadedPages < maxPagesToLoad } // MARK: Init public init(startingAt maxId: String? = nil, maxPagesToLoad: Int = 1) {