Skip to content

Commit

Permalink
Merge development into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed Jan 9, 2021
2 parents 076cc28 + 7454e2a commit 212e141
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Examples/Followers/Followers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_ASSET_PATHS = "\"Followers/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand All @@ -363,7 +363,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_ASSET_PATHS = "\"Followers/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -417,7 +417,7 @@
repositoryURL = "[email protected]:sbertix/Swiftagram.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 4.1.0;
minimumVersion = 4.2.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E028F0072418DFAD00F9C7F8"
BuildableName = "Followers.app"
BlueprintName = "Followers"
ReferencedContainer = "container:Followers.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E028F0072418DFAD00F9C7F8"
BuildableName = "Followers.app"
BlueprintName = "Followers"
ReferencedContainer = "container:Followers.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E028F0072418DFAD00F9C7F8"
BuildableName = "Followers.app"
BlueprintName = "Followers"
ReferencedContainer = "container:Followers.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 4 additions & 4 deletions Examples/Followers/Followers/Followers/FollowersModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class FollowersModel: ObservableObject {
/// The logged in secret.
var secret: Secret? {
didSet {
guard let secret = secret, secret.id != oldValue?.id else { return }
guard let secret = secret, secret.identifier != oldValue?.identifier else { return }
fetch(secret: secret)
}
}
Expand All @@ -42,7 +42,7 @@ final class FollowersModel: ObservableObject {
if let secret = KeychainStorage<Secret>().all().first {
self.secret = secret
self.current = UserDefaults.standard
.data(forKey: secret.id)
.data(forKey: secret.identifier)
.flatMap { try? JSONDecoder().decode(User.self, from: $0) }
// Fetch the data.
self.fetch(secret: secret)
Expand All @@ -59,7 +59,7 @@ final class FollowersModel: ObservableObject {
/// Fetch values.
func fetch(secret: Secret) {
// Load info for the logged in user.
Endpoint.User.summary(for: secret.id)
Endpoint.User.summary(for: secret.identifier)
.unlocking(with: secret)
.publish()
.map(\.user)
Expand All @@ -69,7 +69,7 @@ final class FollowersModel: ObservableObject {
// Load the first 3 pages of the current user's followers.
// In a real app you might want to fetch all of them.
followers = []
Endpoint.Friendship.following(secret.id)
Endpoint.Friendship.following(secret.identifier)
.unlocking(with: secret)
.publish()
.prefix(3)
Expand Down
4 changes: 4 additions & 0 deletions Examples/Followers/Followers/Followers/FollowersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ struct FollowersView: View {
Text("Loading…")
.font(.headline)
.foregroundColor(.secondary)
.padding(.vertical)
} else if model.followers?.isEmpty == true {
Text("No followers.")
.padding(.vertical)
} else {
ForEach(model.followers ?? [], id: \.username.hashValue) { user in
/// Visit **Instagram** on tap.
Expand All @@ -37,10 +39,12 @@ struct FollowersView: View {
Spacer()
Image(systemName: "chevron.right").imageScale(.small).foregroundColor(.secondary)
}
.padding(.vertical)
}
}
}
}
.listStyle(PlainListStyle())
.onAppear {
guard self.model.secret == nil else { return }
self.shouldDisplayLogin = true
Expand Down
29 changes: 21 additions & 8 deletions Sources/Swiftagram/Endpoints/EndpointMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,38 @@ public extension Endpoint.Media {
/// Timeline.
///
/// - parameter page: An optional `String` holding reference to a valid cursor. Defaults to `nil`.
@available(*, deprecated, message: "visit https://github.com/sbertix/Swiftagram/discussions/128")
public static func timeline(startingAt page: String? = nil) -> Endpoint.Paginated<Wrapper> {
Endpoint.version1.feed.appendingDefaultHeader()
.appending(path: "timeline/")
.appending(query: ["max_id": page])
.replacing(body: ["max_id": page])
.prepare {
switch $1 {
case .none:
switch $0.query["max_id"] {
case let value? where !value.isEmpty:
return $0.appending(query: ["reason": "pagination"])
return try? $0.appending(body: ["reason": "pagination"])
default:
return (try? $0.appending(body: ["reason": "cold_start_fetch",
"is_pull_to_refresh": "0"]))
?? $0
return try? $0.appending(body: ["reason": "cold_start_fetch", "is_pull_to_refresh": "0"])
}
case let response?:
guard let nextMaxId = try? response.get().nextMaxId.string() else { return nil }
return try? $0.appending(query: ["max_id": nextMaxId]).appending(body: ["reason": "pagination"])
guard let success = try? response.get(), let nextMaxId = success.nextMaxId.string() else { return nil }
// Check if you reached the end for unwatched posts.
// If you have, load older posts.
switch nextMaxId {
case "feed_recs_head_load":
guard let actualNextMaxId = success.feedItems.array()?
.last?
.endOfFeedDemarcator
.groupSet
.groups
.array()?
.first(where: { $0.id.string() == "past_posts" })?
.nextMaxId
.string() else { return nil }
return try? $0.appending(body: ["max_id": actualNextMaxId, "reason": "pagination"])
default:
return try? $0.appending(body: ["max_id": nextMaxId, "reason": "pagination"])
}
}
}
.locking(Secret.self) {
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftagramTests/EndpointTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ final class EndpointTests: XCTestCase {

/// Test `Endpoint.Media.Posts`.
func testEndpointPosts() {
performTest(on: Endpoint.Media.Posts.timeline())
performTest(on: Endpoint.Media.Posts.liked())
performTest(on: Endpoint.Media.Posts.saved())
performTest(on: Endpoint.Media.Posts.owned(by: "183250726"))
Expand Down

0 comments on commit 212e141

Please sign in to comment.