Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Support users.conversations in WebAPI (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgto committed Mar 25, 2020
1 parent 229e4ee commit 6e63e74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions SKWebAPI/Sources/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public enum Endpoint: String {
case usersGetPresence = "users.getPresence"
case usersInfo = "users.info"
case usersList = "users.list"
case usersConversations = "users.conversations"
case usersLookupByEmail = "users.lookupByEmail"
case usersProfileSet = "users.profile.set"
case usersSetActive = "users.setActive"
Expand Down
26 changes: 26 additions & 0 deletions SKWebAPI/Sources/WebAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class WebAPI {
public typealias FailureClosure = (_ error: SlackError) -> Void
public typealias CommentClosure = (_ comment: Comment) -> Void
public typealias ChannelClosure = (_ channel: Channel) -> Void
public typealias ChannelsClosure = (_ channels: [Channel], _ nextCursor: String?) -> Void
public typealias MessageClosure = (_ message: Message) -> Void
public typealias HistoryClosure = (_ history: History) -> Void
public typealias FileClosure = (_ file: File) -> Void
Expand Down Expand Up @@ -1112,6 +1113,31 @@ extension WebAPI {

// MARK: - Users
extension WebAPI {
public func userConversations(
cursor: String? = nil,
excludeArchived: Bool? = nil,
limit: Int? = nil,
types: [ConversationType]? = nil,
userID: String? = nil,
success: ChannelsClosure?,
failure: FailureClosure?
) {
let parameters: [String: Any?] = [
"token": token,
"cursor": cursor,
"exclude_archived": excludeArchived,
"limit": limit,
"types": types?.map({ $0.rawValue }).joined(separator: ","),
"user": userID
]
networkInterface.request(.usersConversations, parameters: parameters.compactMapValues({$0}), successClosure: {(response) in
let channels: [Channel] = (response["channels"] as? [[String: Any]])?.map{Channel(channel: $0)} ?? []
success?(channels, (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String)
}) {(error) in
failure?(error)
}
}

public func userPresence(user: String, success: ((_ presence: String?) -> Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["token": token, "user": user]
networkInterface.request(.usersGetPresence, parameters: parameters, successClosure: {(response) in
Expand Down

0 comments on commit 6e63e74

Please sign in to comment.