-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add message pagination #23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
AsyncFunction("loadMessages") { (conversationTopic: String, conversationID: String?, limit: Int?, before: Double?, after: Double?) -> [String] in | ||
guard let client else { | ||
throw Error.noClient | ||
} | ||
|
||
guard let conversation = try await findConversation(topic: conversationTopic, conversationID: conversationID) else { | ||
throw Error.conversationNotFound("no conversation found for \(conversationTopic)") | ||
} | ||
let beforeDate = before != nil ? Date(timeIntervalSince1970: before!) : nil | ||
let afterDate = after != nil ? Date(timeIntervalSince1970: after!) : nil | ||
|
||
return try await conversation.messages(after: Date.init(timeIntervalSince1970: 0)).map { try DecodedMessageWrapper.encode($0) } | ||
return try await conversation.messages(limit: limit, before: beforeDate, after: afterDate).map { try DecodedMessageWrapper.encode($0) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I did this swift thing right so going to wait till @nakajima comes back to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
🎉 This PR is included in version 1.0.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #6
Adds the ability to paginate the message list.