Skip to content

Commit 37285cc

Browse files
authored
add: conversations endpoint (pvzig#186)
1 parent 7555a83 commit 37285cc

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

SKWebAPI/Sources/Endpoint.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public enum Endpoint: String {
4646
case chatUpdate = "chat.update"
4747
case conversationsList = "conversations.list"
4848
case conversationsReplies = "conversations.replies"
49+
case conversationsMembers = "conversations.members"
50+
case conversationsHistory = "conversations.history"
4951
case dndInfo = "dnd.info"
5052
case dndTeamInfo = "dnd.teamInfo"
5153
case emojiList = "emoji.list"

SKWebAPI/Sources/WebAPI.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,58 @@ extension WebAPI {
13011301
failure?(error)
13021302
}
13031303
}
1304+
1305+
public func conversationsMembers(
1306+
id: String,
1307+
cursor: String? = nil,
1308+
limit: Int? = nil,
1309+
success: ((_ members: [String]?, _ nextCursor: String?) -> Void)?,
1310+
failure: FailureClosure?
1311+
) {
1312+
var parameters: [String: Any] = [
1313+
"token": token,
1314+
"channel": id
1315+
]
1316+
if let cursor = cursor {
1317+
parameters["cursor"] = cursor
1318+
}
1319+
if let limit = limit {
1320+
parameters["limit"] = limit
1321+
}
1322+
networkInterface.request(.conversationsMembers, parameters: parameters, successClosure: {(response) in
1323+
success?(response["members"] as? [String], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String)
1324+
}) {(error) in
1325+
failure?(error)
1326+
}
1327+
}
1328+
1329+
public func conversationsHistory(
1330+
id: String,
1331+
cursor: String? = nil,
1332+
inclusive: Bool = false,
1333+
latest: String = "\(Date().timeIntervalSince1970)",
1334+
limit: Int = 10,
1335+
oldest: String = "0",
1336+
success: ((_ channels: [[String: Any]]?, _ nextCursor: String?) -> Void)?,
1337+
failure: FailureClosure?
1338+
) {
1339+
var parameters: [String: Any] = [
1340+
"token": token,
1341+
"channel": id,
1342+
"inclusive": inclusive,
1343+
"limit": limit,
1344+
"latest": latest,
1345+
"oldest": oldest,
1346+
]
1347+
if let cursor = cursor {
1348+
parameters["cursor"] = cursor
1349+
}
1350+
networkInterface.request(.conversationsHistory, parameters: parameters, successClosure: {(response) in
1351+
success?(response["messages"] as? [[String: Any]], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String)
1352+
}) {(error) in
1353+
failure?(error)
1354+
}
1355+
}
13041356
}
13051357

13061358
// MARK: - Search

0 commit comments

Comments
 (0)