From 4853372bae0eb782f00ae614ff81ed7cec8f16ef Mon Sep 17 00:00:00 2001 From: Nonchalant Date: Fri, 31 Jul 2020 02:13:32 +0900 Subject: [PATCH] add: conversations endpoint --- SKWebAPI/Sources/Endpoint.swift | 2 ++ SKWebAPI/Sources/WebAPI.swift | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/SKWebAPI/Sources/Endpoint.swift b/SKWebAPI/Sources/Endpoint.swift index ad528bf..b44b29c 100755 --- a/SKWebAPI/Sources/Endpoint.swift +++ b/SKWebAPI/Sources/Endpoint.swift @@ -46,6 +46,8 @@ public enum Endpoint: String { case chatUpdate = "chat.update" case conversationsList = "conversations.list" case conversationsReplies = "conversations.replies" + case conversationsMembers = "conversations.members" + case conversationsHistory = "conversations.history" case dndInfo = "dnd.info" case dndTeamInfo = "dnd.teamInfo" case emojiList = "emoji.list" diff --git a/SKWebAPI/Sources/WebAPI.swift b/SKWebAPI/Sources/WebAPI.swift index 93663ee..2817670 100755 --- a/SKWebAPI/Sources/WebAPI.swift +++ b/SKWebAPI/Sources/WebAPI.swift @@ -1301,6 +1301,58 @@ extension WebAPI { failure?(error) } } + + public func conversationsMembers( + id: String, + cursor: String? = nil, + limit: Int? = nil, + success: ((_ members: [String]?, _ nextCursor: String?) -> Void)?, + failure: FailureClosure? + ) { + var parameters: [String: Any] = [ + "token": token, + "channel": id + ] + if let cursor = cursor { + parameters["cursor"] = cursor + } + if let limit = limit { + parameters["limit"] = limit + } + networkInterface.request(.conversationsMembers, parameters: parameters, successClosure: {(response) in + success?(response["members"] as? [String], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String) + }) {(error) in + failure?(error) + } + } + + public func conversationsHistory( + id: String, + cursor: String? = nil, + inclusive: Bool = false, + latest: String = "\(Date().timeIntervalSince1970)", + limit: Int = 10, + oldest: String = "0", + success: ((_ channels: [[String: Any]]?, _ nextCursor: String?) -> Void)?, + failure: FailureClosure? + ) { + var parameters: [String: Any] = [ + "token": token, + "channel": id, + "inclusive": inclusive, + "limit": limit, + "latest": latest, + "oldest": oldest, + ] + if let cursor = cursor { + parameters["cursor"] = cursor + } + networkInterface.request(.conversationsHistory, parameters: parameters, successClosure: {(response) in + success?(response["messages"] as? [[String: Any]], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String) + }) {(error) in + failure?(error) + } + } } // MARK: - Search