Skip to content

Commit 9bb9ae0

Browse files
authored
Merge pull request #422 from zapcannon87/master
feat: fetching member info support limit and offset
2 parents 7a7512f + 2d0193e commit 9bb9ae0

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

Sources/RTM/IMConversation.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,19 @@ public class IMConversation {
441441
try self._update(attribution: data, completion: completion)
442442
}
443443

444-
/// Fetching the table of member infomation in the conversation.
445-
/// The result will be cached by the property `memberInfoTable`.
444+
/// Fetching the table of member infomation in this conversation.
445+
/// The result will be cached in the property `memberInfoTable`.
446446
///
447-
/// - Parameter completion: Result of callback.
448-
public func fetchMemberInfoTable(completion: @escaping (LCBooleanResult) -> Void) {
449-
self._fetchMemberInfoTable { (client, result) in
447+
/// - Parameters:
448+
/// - limit: The max number of results, default is `500`.
449+
/// - offset: The number of objects to skip.
450+
/// - completion: Result of callback.
451+
public func fetchMemberInfoTable(
452+
limit: Int = 500,
453+
offset: Int? = nil,
454+
completion: @escaping (LCBooleanResult) -> Void)
455+
{
456+
self._fetchMemberInfoTable(limit: limit, offset: offset) { (client, result) in
450457
client.eventQueue.async {
451458
completion(result)
452459
}
@@ -1929,7 +1936,11 @@ extension IMConversation {
19291936
}
19301937
}
19311938

1932-
private func _fetchMemberInfoTable(completion: @escaping (IMClient, LCBooleanResult) -> Void) {
1939+
private func _fetchMemberInfoTable(
1940+
limit: Int = 500,
1941+
offset: Int? = nil,
1942+
completion: @escaping (IMClient, LCBooleanResult) -> Void)
1943+
{
19331944
self.client?.serialQueue.async {
19341945
self.client?.getSessionToken(completion: { (client, result) in
19351946
assert(client.specificAssertion)
@@ -1943,10 +1954,14 @@ extension IMConversation {
19431954
let header: [String: String] = [
19441955
"X-LC-IM-Session-Token": token,
19451956
]
1946-
let parameters: [String: Any] = [
1957+
var parameters: [String: Any] = [
19471958
"client_id": client.ID,
19481959
"where": whereString,
1960+
"limit": limit,
19491961
]
1962+
if let offset = offset {
1963+
parameters["skip"] = offset
1964+
}
19501965
_ = client.application.httpClient.request(
19511966
.get, "classes/_ConversationMemberInfo",
19521967
parameters: parameters,
@@ -2991,7 +3006,7 @@ public class IMServiceConversation: IMConversation {
29913006
}
29923007

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

@@ -3132,7 +3147,7 @@ public class IMTemporaryConversation: IMConversation {
31323147
}
31333148

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

0 commit comments

Comments
 (0)