From 0ff99ac11196450863f348220b95341706ea81ce Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sun, 17 Dec 2023 12:40:09 -0500 Subject: [PATCH 1/4] fixed cursor pagination not working on 0.19 --- Mlem/API/Requests/Post/GetPosts.swift | 4 +++- Mlem/Models/Trackers/Post Tracker.swift | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Mlem/API/Requests/Post/GetPosts.swift b/Mlem/API/Requests/Post/GetPosts.swift index 52b652881..5db358c68 100644 --- a/Mlem/API/Requests/Post/GetPosts.swift +++ b/Mlem/API/Requests/Post/GetPosts.swift @@ -39,8 +39,10 @@ struct GetPostsRequest: APIGetRequest { let paginationParameter: URLQueryItem if let cursor { - paginationParameter = .init(name: "page_v2", value: cursor) + print("adding page cursor") + paginationParameter = .init(name: "page_cursor", value: cursor) } else { + print("adding raw page") paginationParameter = .init(name: "page", value: "\(page)") } diff --git a/Mlem/Models/Trackers/Post Tracker.swift b/Mlem/Models/Trackers/Post Tracker.swift index 6720ac184..b5296cce9 100644 --- a/Mlem/Models/Trackers/Post Tracker.swift +++ b/Mlem/Models/Trackers/Post Tracker.swift @@ -76,6 +76,7 @@ class PostTracker: ObservableObject { var newPosts: [PostModel] = .init() let numItems = items.count repeat { + print("[DEBUG] current cursor: \(currentCursor)") let (posts, cursor) = try await postRepository.loadPage( communityId: communityId, page: page, @@ -87,6 +88,8 @@ class PostTracker: ObservableObject { newPosts = posts + print("[DEBUG] got \(newPosts.count) new posts") + if newPosts.isEmpty { hasReachedEnd = true } else if let currentCursor, cursor == currentCursor { From a64c5bf4cd4c8033968a1bfa4d27a0a3c9d3fda0 Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sun, 17 Dec 2023 12:56:35 -0500 Subject: [PATCH 2/4] fixed multithreading issue --- Mlem/API/Requests/Post/GetPosts.swift | 2 -- Mlem/Models/Trackers/Post Tracker.swift | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Mlem/API/Requests/Post/GetPosts.swift b/Mlem/API/Requests/Post/GetPosts.swift index 5db358c68..3aa41ab7b 100644 --- a/Mlem/API/Requests/Post/GetPosts.swift +++ b/Mlem/API/Requests/Post/GetPosts.swift @@ -39,10 +39,8 @@ struct GetPostsRequest: APIGetRequest { let paginationParameter: URLQueryItem if let cursor { - print("adding page cursor") paginationParameter = .init(name: "page_cursor", value: cursor) } else { - print("adding raw page") paginationParameter = .init(name: "page", value: "\(page)") } diff --git a/Mlem/Models/Trackers/Post Tracker.swift b/Mlem/Models/Trackers/Post Tracker.swift index b5296cce9..b726c0fa0 100644 --- a/Mlem/Models/Trackers/Post Tracker.swift +++ b/Mlem/Models/Trackers/Post Tracker.swift @@ -76,7 +76,6 @@ class PostTracker: ObservableObject { var newPosts: [PostModel] = .init() let numItems = items.count repeat { - print("[DEBUG] current cursor: \(currentCursor)") let (posts, cursor) = try await postRepository.loadPage( communityId: communityId, page: page, @@ -88,11 +87,10 @@ class PostTracker: ObservableObject { newPosts = posts - print("[DEBUG] got \(newPosts.count) new posts") - if newPosts.isEmpty { hasReachedEnd = true } else if let currentCursor, cursor == currentCursor { + print("cursor has reached end") hasReachedEnd = true } else { await add(newPosts, filtering: filtering) @@ -206,7 +204,7 @@ class PostTracker: ObservableObject { let thresholdIndex = max(0, items.index(items.endIndex, offsetBy: AppConstants.infiniteLoadThresholdOffset)) if thresholdIndex >= 0, let itemIndex = items.firstIndex(where: { $0.uid == item.uid }), - itemIndex >= thresholdIndex { + itemIndex == thresholdIndex { return true } From 70a2a303ce0332ff9561c930a2703e7cd460131f Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sun, 17 Dec 2023 12:57:12 -0500 Subject: [PATCH 3/4] cleanup --- Mlem/Models/Trackers/Post Tracker.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Mlem/Models/Trackers/Post Tracker.swift b/Mlem/Models/Trackers/Post Tracker.swift index b726c0fa0..141d89253 100644 --- a/Mlem/Models/Trackers/Post Tracker.swift +++ b/Mlem/Models/Trackers/Post Tracker.swift @@ -90,7 +90,6 @@ class PostTracker: ObservableObject { if newPosts.isEmpty { hasReachedEnd = true } else if let currentCursor, cursor == currentCursor { - print("cursor has reached end") hasReachedEnd = true } else { await add(newPosts, filtering: filtering) From e57f7960d5099f4f2818072a3cbc76f4cd74a9b0 Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Sun, 17 Dec 2023 13:04:00 -0500 Subject: [PATCH 4/4] bumped version to 1.1.2 --- Mlem.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mlem.xcodeproj/project.pbxproj b/Mlem.xcodeproj/project.pbxproj index aea03ed32..1ba5cc892 100644 --- a/Mlem.xcodeproj/project.pbxproj +++ b/Mlem.xcodeproj/project.pbxproj @@ -3439,7 +3439,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.1; + MARKETING_VERSION = 1.1.2; PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; @@ -3480,7 +3480,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.1; + MARKETING_VERSION = 1.1.2; PRODUCT_BUNDLE_IDENTIFIER = com.hanners.Mlem; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";