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 6, 2021
2 parents a9d1dcc + 6b1569a commit 076cc28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Sources/Swiftagram/Endpoints/EndpointDirect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ public extension Endpoint {

/// All threads.
///
/// - parameter page: An optional `String` holding reference to a valid cursor. Defaults to `nil`.
public static func inbox(startingAt page: String? = nil) -> Paginated<Conversation.Collection> {
/// - parameters:
/// - page: An optional `String` holding reference to a valid cursor. Defaults to `nil`.
/// - rank: A valid `Int` making sure users are paginated consistently. Defaults to a random `Int` between `1_000` and `10_000`.
public static func inbox(startingAt page: String? = nil, rank: Int = Int.random(in: 1_000..<10_000)) -> Paginated<Conversation.Collection> {
base.inbox
.appending(query: ["visual_message_return_type": "unseen",
"direction": page.flatMap { _ in "older" },
"thread_message_limit": "10",
"persistent_badging": "true",
"limit": "20"])
.paginating(process: Conversation.Collection.self, key: "cursor", keyPath: \.oldestCursor, value: page)
"limit": "20",
"seq_id": String(rank)])
.paginating(process: Conversation.Collection.self,
key: "cursor",
keyPath: \.inbox.oldestCursor,
value: page)
.locking(Secret.self)
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Swiftagram/Endpoints/EndpointMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ 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/")
Expand All @@ -196,7 +197,7 @@ public extension Endpoint.Media {
}
case let response?:
guard let nextMaxId = try? response.get().nextMaxId.string() else { return nil }
return $0.appending(query: ["max_id": nextMaxId, "reason": "pagination"])
return try? $0.appending(query: ["max_id": nextMaxId]).appending(body: ["reason": "pagination"])
}
}
.locking(Secret.self) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Swiftagram/Extensions/Requestable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public extension Requestable where Self: QueryComposable & QueryParsable {
self.appending(query: key, with: value)
.prepare(process: Mapped.self) { request, response in
guard let response = try? response?.get().wrapper() else { return request }
return (keyPath(response).string() ?? keyPath(response).int().flatMap(String.init))
.flatMap { request.appending(query: key, with: $0) }
guard let nextCursor = keyPath(response).string(converting: true) else { return nil }
return request.appending(query: key, with: nextCursor)
}
}
}
6 changes: 6 additions & 0 deletions Sources/Swiftagram/Models/Specialized/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public extension Conversation {
/// The logged in user.
public var viewer: User? { self["viewer"].optional().flatMap(User.init) }

/// The pagination parameters.
public var pagination: Pagination {
/// The current cursor is always `nil` for inboxes.
.init(current: nil, next: self["inbox"]["oldestCursor"].string())
}

/// Init.
/// - parameter wrapper: A valid `Wrapper`.
public init(wrapper: @escaping () -> Wrapper) {
Expand Down

0 comments on commit 076cc28

Please sign in to comment.