Skip to content
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

feat: fetching member info support limit and offset #422

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions Sources/RTM/IMConversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,19 @@ public class IMConversation {
try self._update(attribution: data, completion: completion)
}

/// Fetching the table of member infomation in the conversation.
/// The result will be cached by the property `memberInfoTable`.
/// Fetching the table of member infomation in this conversation.
/// The result will be cached in the property `memberInfoTable`.
///
/// - Parameter completion: Result of callback.
public func fetchMemberInfoTable(completion: @escaping (LCBooleanResult) -> Void) {
self._fetchMemberInfoTable { (client, result) in
/// - Parameters:
/// - limit: The max number of results, default is `500`.
/// - offset: The number of objects to skip.
/// - completion: Result of callback.
public func fetchMemberInfoTable(
limit: Int = 500,
offset: Int? = nil,
completion: @escaping (LCBooleanResult) -> Void)
{
self._fetchMemberInfoTable(limit: limit, offset: offset) { (client, result) in
client.eventQueue.async {
completion(result)
}
Expand Down Expand Up @@ -1929,7 +1936,11 @@ extension IMConversation {
}
}

private func _fetchMemberInfoTable(completion: @escaping (IMClient, LCBooleanResult) -> Void) {
private func _fetchMemberInfoTable(
limit: Int = 500,
offset: Int? = nil,
completion: @escaping (IMClient, LCBooleanResult) -> Void)
{
self.client?.serialQueue.async {
self.client?.getSessionToken(completion: { (client, result) in
assert(client.specificAssertion)
Expand All @@ -1943,10 +1954,14 @@ extension IMConversation {
let header: [String: String] = [
"X-LC-IM-Session-Token": token,
]
let parameters: [String: Any] = [
var parameters: [String: Any] = [
"client_id": client.ID,
"where": whereString,
"limit": limit,
]
if let offset = offset {
parameters["skip"] = offset
}
_ = client.application.httpClient.request(
.get, "classes/_ConversationMemberInfo",
parameters: parameters,
Expand Down Expand Up @@ -2991,7 +3006,7 @@ public class IMServiceConversation: IMConversation {
}

@available(*, unavailable)
public override func fetchMemberInfoTable(completion: @escaping (LCBooleanResult) -> Void) {
public override func fetchMemberInfoTable(limit: Int = 500, offset: Int? = nil, completion: @escaping (LCBooleanResult) -> Void) {
completion(.failure(error: LCError.conversationNotSupport(convType: type(of: self))))
}

Expand Down Expand Up @@ -3132,7 +3147,7 @@ public class IMTemporaryConversation: IMConversation {
}

@available(*, unavailable)
public override func fetchMemberInfoTable(completion: @escaping (LCBooleanResult) -> Void) {
public override func fetchMemberInfoTable(limit: Int = 500, offset: Int? = nil, completion: @escaping (LCBooleanResult) -> Void) {
completion(.failure(error: LCError.conversationNotSupport(convType: type(of: self))))
}

Expand Down