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

add: conversations endpoint #186

Merged
merged 1 commit into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions SKWebAPI/Sources/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 52 additions & 0 deletions SKWebAPI/Sources/WebAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down