Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d6516922f | |||
| 1b98af2b11 | |||
| 750604a801 | |||
| 47f5d040a2 | |||
| 3c34557617 | |||
| d60b8bf88a | |||
| f2f95b7a26 | |||
| c4b38dbc14 | |||
| 7fffbc8dba | |||
| ab39fda0f5 | |||
| 11e9f2e9ab | |||
| a93b4b7966 | |||
| b639fff78e | |||
| 6075577ec5 | |||
| 7a967b8f7d | |||
| 5f53f89693 | |||
| 30d701f6de | |||
| 82e200f4cc | |||
| 6cca5c3956 | |||
| 43f184a8ed | |||
| c5ce209e54 | |||
| fc336cd2ee | |||
| 7138cf3f4f |
@@ -18,6 +18,7 @@ DerivedData
|
||||
*.xcuserstate
|
||||
.build
|
||||
Packages/
|
||||
*.xcodeproj/
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DEVELOPMENT-SNAPSHOT-2016-05-09-a
|
||||
@@ -0,0 +1,8 @@
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "leaderboard",
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 0, minor: 0),
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// main.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import String
|
||||
import SlackKit
|
||||
|
||||
class Leaderboard: MessageEventsDelegate {
|
||||
|
||||
var leaderboard: [String: Int] = [String: Int]()
|
||||
let atSet = CharacterSet(characters: ["@"])
|
||||
|
||||
let client: SlackClient
|
||||
|
||||
init(token: String) {
|
||||
client = SlackClient(apiToken: token)
|
||||
client.messageEventsDelegate = self
|
||||
}
|
||||
|
||||
enum Command: String {
|
||||
case Leaderboard = "leaderboard"
|
||||
}
|
||||
|
||||
enum Trigger: String {
|
||||
case PlusPlus = "++"
|
||||
case MinusMinus = "--"
|
||||
}
|
||||
|
||||
// MARK: MessageEventsDelegate
|
||||
func messageReceived(message: Message) {
|
||||
listen(message: message)
|
||||
}
|
||||
|
||||
func messageSent(message: Message){}
|
||||
func messageChanged(message: Message){}
|
||||
func messageDeleted(message: Message?){}
|
||||
|
||||
// MARK: Leaderboard Internal Logic
|
||||
private func listen(message: Message) {
|
||||
if let id = client.authenticatedUser?.id, text = message.text {
|
||||
if text.lowercased().contains(query: Command.Leaderboard.rawValue) && text.contains(query: id) {
|
||||
handleCommand(command: .Leaderboard, channel: message.channel)
|
||||
}
|
||||
}
|
||||
if message.text?.contains(query: Trigger.PlusPlus.rawValue) == true {
|
||||
handleMessageWithTrigger(message: message, trigger: .PlusPlus)
|
||||
}
|
||||
if message.text?.contains(query: Trigger.MinusMinus.rawValue) == true {
|
||||
handleMessageWithTrigger(message: message, trigger: .MinusMinus)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleMessageWithTrigger(message: Message, trigger: Trigger) {
|
||||
if let text = message.text,
|
||||
start = text.index(of: "@"),
|
||||
end = text.index(of: trigger.rawValue) {
|
||||
let string = String(text.characters[start...end].dropLast().dropFirst())
|
||||
let users = client.users.values.filter{$0.id == self.userID(string: string)}
|
||||
if users.count > 0 {
|
||||
let idString = userID(string: string)
|
||||
initalizationForValue(dictionary: &leaderboard, value: idString)
|
||||
scoringForValue(dictionary: &leaderboard, value: idString, trigger: trigger)
|
||||
} else {
|
||||
initalizationForValue(dictionary: &leaderboard, value: string)
|
||||
scoringForValue(dictionary: &leaderboard, value: string, trigger: trigger)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleCommand(command: Command, channel:String?) {
|
||||
switch command {
|
||||
case .Leaderboard:
|
||||
if let id = channel {
|
||||
client.webAPI.sendMessage(channel:id, text: "Leaderboard", linkNames: true, attachments: [constructLeaderboardAttachment()], success: {(response) in
|
||||
|
||||
}, failure: { (error) in
|
||||
print("Leaderboard failed to post due to error:\(error)")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func initalizationForValue( dictionary: inout [String: Int], value: String) {
|
||||
if dictionary[value] == nil {
|
||||
dictionary[value] = 0
|
||||
}
|
||||
}
|
||||
|
||||
private func scoringForValue( dictionary: inout [String: Int], value: String, trigger: Trigger) {
|
||||
switch trigger {
|
||||
case .PlusPlus:
|
||||
dictionary[value]?+=1
|
||||
case .MinusMinus:
|
||||
dictionary[value]?-=1
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Leaderboard Interface
|
||||
private func constructLeaderboardAttachment() -> Attachment? {
|
||||
let 💯 = AttachmentField(title: "💯", value: swapIDsForNames(string: topItems(dictionary: &leaderboard)), short: true)
|
||||
let 💩 = AttachmentField(title: "💩", value: swapIDsForNames(string: bottomItems(dictionary: &leaderboard)), short: true)
|
||||
return Attachment(fallback: "Leaderboard", title: "Leaderboard", colorHex: AttachmentColor.Good.rawValue, text: "", fields: [💯, 💩])
|
||||
}
|
||||
|
||||
private func topItems(dictionary: inout [String: Int]) -> String {
|
||||
let sortedKeys = dictionary.keys.sorted(isOrderedBefore: ({dictionary[$0] > dictionary[$1]})).filter({dictionary[$0] > 0})
|
||||
let sortedValues = dictionary.values.sorted(isOrderedBefore: {$0 > $1}).filter({$0 > 0})
|
||||
return leaderboardString(keys: sortedKeys, values: sortedValues)
|
||||
}
|
||||
|
||||
private func bottomItems( dictionary: inout [String: Int]) -> String {
|
||||
let sortedKeys = dictionary.keys.sorted(isOrderedBefore: ({dictionary[$0] < dictionary[$1]})).filter({dictionary[$0] < 0})
|
||||
let sortedValues = dictionary.values.sorted(isOrderedBefore: {$0 < $1}).filter({$0 < 0})
|
||||
return leaderboardString(keys: sortedKeys, values: sortedValues)
|
||||
}
|
||||
|
||||
private func leaderboardString(keys: [String], values: [Int]) -> String {
|
||||
var returnValue = ""
|
||||
for i in 0..<values.count {
|
||||
returnValue += keys[i] + " (" + "\(values[i])" + ")\n"
|
||||
}
|
||||
return returnValue
|
||||
}
|
||||
|
||||
// MARK: - Utilities
|
||||
private func swapIDsForNames(string: String) -> String {
|
||||
var returnString = string
|
||||
for key in client.users.keys {
|
||||
if let name = client.users[key]?.name {
|
||||
if returnString.contains(query: key) {
|
||||
returnString.replace(string: key, with: "@"+name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnString
|
||||
}
|
||||
|
||||
private func userID(string: String) -> String {
|
||||
let alphanumericSet = CharacterSet(characters:
|
||||
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
|
||||
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
|
||||
"0","1","2","3","4","5","6","7","8","9"])
|
||||
return string.trim(alphanumericSet.inverted)
|
||||
}
|
||||
}
|
||||
|
||||
let leaderboard = Leaderboard(token: "xoxb-SLACK_API_TOKEN")
|
||||
leaderboard.client.connect()
|
||||
@@ -0,0 +1,9 @@
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "robot-or-not-bot",
|
||||
targets: [],
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 0, minor: 0),
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,139 @@
|
||||
//
|
||||
// main.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import SlackKit
|
||||
|
||||
class RobotOrNotBot: MessageEventsDelegate {
|
||||
|
||||
let verdicts: [String:Bool] = [
|
||||
"Mr. Roboto" : false,
|
||||
"Service Kiosks": false,
|
||||
"Darth Vader": false,
|
||||
"K-9": true,
|
||||
"Emotions": false,
|
||||
"Self-Driving Cars": false,
|
||||
"Telepresence Robots": false,
|
||||
"Roomba": true,
|
||||
"Assembly-Line Robot": false,
|
||||
"ASIMO": false,
|
||||
"KITT": false,
|
||||
"USS Enterprise": false,
|
||||
"Transformers": true,
|
||||
"Jaegers": false,
|
||||
"The Major": false,
|
||||
"Siri": false,
|
||||
"The Terminator": true,
|
||||
"Commander Data": false,
|
||||
"Marvin the Paranoid Android": true,
|
||||
"Pinocchio": false,
|
||||
"Droids": true,
|
||||
"Hitchbot": false,
|
||||
"Mars Rovers": false,
|
||||
"Space Probes": false,
|
||||
"Sasquatch": false,
|
||||
"Toaster": false,
|
||||
"Toaster Oven": false,
|
||||
"Cylons": false,
|
||||
"V'ger": true,
|
||||
"Ilia Robot": false,
|
||||
"The TARDIS": false,
|
||||
"Johnny 5": true,
|
||||
"Twiki": true,
|
||||
"Dr. Theopolis": false,
|
||||
"robots.txt": false,
|
||||
"Lobot": false,
|
||||
"Vicki": true,
|
||||
"GlaDOS": false,
|
||||
"Turrets": true,
|
||||
"Wheatley": true,
|
||||
"Herbie the Love Bug": false,
|
||||
"Iron Man": false,
|
||||
"Ultron": false,
|
||||
"The Vision": false,
|
||||
"Clockwork Droids": false,
|
||||
"Podcasts": false,
|
||||
"Cars": false,
|
||||
"Swimming Pool Cleaners": false,
|
||||
"Burritos": false,
|
||||
"Prince Robot IV": false,
|
||||
"Daleks": false,
|
||||
"Cybermen": false,
|
||||
"The Internet of Things": false,
|
||||
"Nanobots": true,
|
||||
"Two Intermeshed Gears": false,
|
||||
"Crow T. Robot": true,
|
||||
"Tom Servo": true,
|
||||
"Thomas and Friends": false,
|
||||
"Replicants": false,
|
||||
"Chatbots": false,
|
||||
"Agents": false,
|
||||
"Lego Simulated Worm Toy": true,
|
||||
"Ghosts": false,
|
||||
"Exos": true,
|
||||
"Rasputin": false,
|
||||
"Tamagotchi": false,
|
||||
"T-1000": true,
|
||||
"The Tin Woodman": false,
|
||||
"Mic N. The Robot": true,
|
||||
"Robot Or Not Bot": false
|
||||
]
|
||||
let client: SlackClient
|
||||
|
||||
init(token: String) {
|
||||
client = SlackClient(apiToken: token)
|
||||
client.messageEventsDelegate = self
|
||||
}
|
||||
|
||||
// MARK: MessageEventsDelegate
|
||||
func messageReceived(message: Message) {
|
||||
if let id = client.authenticatedUser?.id {
|
||||
if message.text?.contains(query: id) == true {
|
||||
handleMessage(message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageSent(message: Message){}
|
||||
func messageChanged(message: Message){}
|
||||
func messageDeleted(message: Message?){}
|
||||
|
||||
private func handleMessage(message: Message) {
|
||||
if let text = message.text?.lowercased(), channel = message.channel {
|
||||
for (robot, verdict) in verdicts {
|
||||
let lowerbot = robot.lowercased()
|
||||
if text.contains(query: lowerbot) {
|
||||
if verdict == true {
|
||||
client.webAPI.addReaction(name: "robot_face", timestamp: message.ts, channel: channel, success: nil, failure: nil)
|
||||
} else {
|
||||
client.webAPI.addReaction(name: "no_entry_sign", timestamp: message.ts, channel: channel, success: nil, failure: nil)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
client.webAPI.addReaction(name: "question", timestamp: message.ts, channel: channel, success: nil, failure: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let slackbot = RobotOrNotBot(token: "xoxb-SLACK_API_TOKEN")
|
||||
slackbot.client.connect()
|
||||
+5
-4
@@ -27,8 +27,9 @@ let package = Package(
|
||||
name: "SlackKit",
|
||||
targets: [],
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/open-swift/C7.git", majorVersion: 0, minor: 5),
|
||||
.Package(url: "https://github.com/czechboy0/Jay.git", majorVersion: 0, minor: 5),
|
||||
.Package(url: "https://github.com/Zewo/WebSocket", majorVersion: 0, minor: 5),
|
||||
]
|
||||
.Package(url: "https://github.com/Zewo/WebSocketClient", majorVersion: 0, minor: 2),
|
||||
.Package(url: "https://github.com/open-swift/C7.git", majorVersion: 0, minor: 8),
|
||||
.Package(url: "https://github.com/czechboy0/Jay.git", majorVersion: 0, minor: 6),
|
||||
],
|
||||
exclude: ["Examples"]
|
||||
)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||

|
||||
##iOS/OS X Slack Client Library
|
||||
##Alpha Linux Slack Client Library
|
||||
###Description
|
||||
This is a Slack client library for iOS and OS X written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm) as well as the [web APIs](https://api.slack.com/web) that are accessible by [bot users](https://api.slack.com/bot-users).
|
||||
This is a Slack client library for Linux written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm) as well as the [web APIs](https://api.slack.com/web) that are accessible by [bot users](https://api.slack.com/bot-users).
|
||||
|
||||
###Disclaimer: The linux version of SlackKit is a pre-release alpha. Feel free to report issues you come across.
|
||||
|
||||
###Installation
|
||||
|
||||
####Swift Package Manager
|
||||
Add SlackKit to your Package.swift
|
||||
|
||||
@@ -12,28 +15,37 @@ import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 1)
|
||||
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 0, minor: 0)
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
Run `swift-build` on your application’s main directory.
|
||||
####Development
|
||||
1. Install Homebrew: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
|
||||
2. Install `swiftenv`: `brew install kylef/formulae/swiftenv`
|
||||
3. Configure your shell: `echo 'if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi' >> ~/.bash_profile`
|
||||
4. Download and install the latest Zewo compatible snapshot:
|
||||
```
|
||||
swiftenv install DEVELOPMENT-SNAPSHOT-2016-05-03-a
|
||||
swiftenv local DEVELOPMENT-SNAPSHOT-2016-05-03-a
|
||||
```
|
||||
5. Install and Link OpenSSL: `brew install openssl`, `brew link openssl --force`
|
||||
|
||||
####CocoaPods
|
||||
Add the pod to your podfile:
|
||||
To build an application that uses SlackKit in Xcode, simply use SwiftPM. (For the 05-03 snapshot you must run `swift build` before generating an Xcode project:
|
||||
```
|
||||
pod 'SlackKit'
|
||||
```
|
||||
and run
|
||||
```
|
||||
pod install
|
||||
swift build
|
||||
swift build -Xlinker -L$(pwd)/.build/debug/ -Xswiftc -I/usr/local/include -Xlinker -L/usr/local/lib -X
|
||||
```
|
||||
|
||||
|
||||
To use the library in your project import it:
|
||||
```
|
||||
import SlackKit
|
||||
```
|
||||
|
||||
####Deployment
|
||||
Deploy your application to Heroku using [this buildpack](https://github.com/pvzig/heroku-buildpack-swift). For more detailed instructions please see [this post](https://medium.com/@pvzig/building-slack-bots-in-swift-b99e243e444c).
|
||||
|
||||
###Usage
|
||||
To use SlackKit you'll need a bearer token which identifies a single user. You can generate a [full access token or create one using OAuth 2](https://api.slack.com/web).
|
||||
|
||||
@@ -47,11 +59,6 @@ If you want to receive messages from the Slack RTM API, connect to it.
|
||||
client.connect()
|
||||
```
|
||||
|
||||
You can also set options for a ping/pong interval, timeout interval, and automatic reconnection:
|
||||
```swift
|
||||
client.connect(pingInterval: 2, timeout: 10, reconnect: false)
|
||||
```
|
||||
|
||||
Once connected, the client will begin to consume any messages sent by the Slack RTM API.
|
||||
|
||||
####Web API Methods
|
||||
@@ -216,18 +223,6 @@ func subteamSelfAdded(subteamID: String)
|
||||
func subteamSelfRemoved(subteamID: String)
|
||||
```
|
||||
|
||||
###Examples
|
||||
####Leaderboard
|
||||
Included in the OSX-Sample is an example application of a bot you might make using SlackKit. It’s a basic leaderboard scoring bot, in the spirit of [PlusPlus](https://plusplus.chat).
|
||||
|
||||
To configure it, enter your bot’s API token in `AppDelegate.swift` for the Leaderboard bot:
|
||||
|
||||
```swift
|
||||
let learderboard = Leaderboard(token: "SLACK_AUTH_TOKEN")
|
||||
```
|
||||
|
||||
It adds a point for every `@thing++`, subtracts a point for every `@thing--`, and shows a leaderboard when asked `@botname leaderboard`.
|
||||
|
||||
###Get In Touch
|
||||
[@pvzig](https://twitter.com/pvzig)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:SlackRTMKit.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -1,72 +0,0 @@
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "7C8CB4917A87F5E5383E6800524CC50437576509",
|
||||
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
|
||||
|
||||
},
|
||||
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
|
||||
"7C8CB4917A87F5E5383E6800524CC50437576509" : 0,
|
||||
"15033DFF73D1DAA84A806DC9B6994613D8A2EB4F" : 0,
|
||||
"4B8317071C2E8191C0071D14B19E229FF434BD5B" : 0,
|
||||
"8951CEB15DDB2D711276960E67900B8AA34FF427" : 0,
|
||||
"10A2CB6C4392F0E306FF8D509BE5E88232276EA4" : 0,
|
||||
"269ADF55FAAC04D68303BE30B6BD693E717155DE" : 0,
|
||||
"997F6D72B6636BD16A82A9AFFBB55CCAE1A5596D" : 0,
|
||||
"704B817219E4CBC31AA92368EF54A4E2835A8C3D" : 0
|
||||
},
|
||||
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "06B58BC9-590E-416B-85DA-67AE0673C049",
|
||||
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
|
||||
"7C8CB4917A87F5E5383E6800524CC50437576509" : "SlackKit\/",
|
||||
"15033DFF73D1DAA84A806DC9B6994613D8A2EB4F" : "SlackKit\/Packages\/IP-0.5.0\/",
|
||||
"4B8317071C2E8191C0071D14B19E229FF434BD5B" : "SlackKit\/Packages\/WebSocket-0.5.1\/",
|
||||
"8951CEB15DDB2D711276960E67900B8AA34FF427" : "SlackKit\/Packages\/MediaType-0.5.0\/",
|
||||
"10A2CB6C4392F0E306FF8D509BE5E88232276EA4" : "SlackKit\/Packages\/String-0.5.1\/",
|
||||
"269ADF55FAAC04D68303BE30B6BD693E717155DE" : "SlackKit\/Packages\/CHTTPParser-0.5.0\/",
|
||||
"997F6D72B6636BD16A82A9AFFBB55CCAE1A5596D" : "SlackKit\/Packages\/TCPSSL-0.5.1\/",
|
||||
"704B817219E4CBC31AA92368EF54A4E2835A8C3D" : "SlackKit\/Packages\/POSIX-0.5.0\/"
|
||||
},
|
||||
"DVTSourceControlWorkspaceBlueprintNameKey" : "SlackKit",
|
||||
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
|
||||
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "SlackKit.xcodeproj",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Zewo\/String.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "10A2CB6C4392F0E306FF8D509BE5E88232276EA4"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/VeniceX\/IP.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "15033DFF73D1DAA84A806DC9B6994613D8A2EB4F"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Zewo\/CHTTPParser.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "269ADF55FAAC04D68303BE30B6BD693E717155DE"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Zewo\/WebSocket",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "4B8317071C2E8191C0071D14B19E229FF434BD5B"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Zewo\/POSIX.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "704B817219E4CBC31AA92368EF54A4E2835A8C3D"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/pvzig\/SlackRTMKit.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "7C8CB4917A87F5E5383E6800524CC50437576509"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Zewo\/MediaType.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8951CEB15DDB2D711276960E67900B8AA34FF427"
|
||||
},
|
||||
{
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/VeniceX\/TCPSSL.git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
|
||||
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "997F6D72B6636BD16A82A9AFFBB55CCAE1A5596D"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,467 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "9999"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_C7"
|
||||
BuildableName = "libC7.dylib"
|
||||
BlueprintName = "C7"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_Jay"
|
||||
BuildableName = "libJay.dylib"
|
||||
BlueprintName = "Jay"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "NO"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_JayExample"
|
||||
BuildableName = "JayExample"
|
||||
BlueprintName = "JayExample"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_String"
|
||||
BuildableName = "libString.dylib"
|
||||
BlueprintName = "String"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_StructuredData"
|
||||
BuildableName = "libStructuredData.dylib"
|
||||
BlueprintName = "StructuredData"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_MediaType"
|
||||
BuildableName = "libMediaType.dylib"
|
||||
BlueprintName = "MediaType"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_CURIParser"
|
||||
BuildableName = "libCURIParser.dylib"
|
||||
BlueprintName = "CURIParser"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_URI"
|
||||
BuildableName = "libURI.dylib"
|
||||
BlueprintName = "URI"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_S4"
|
||||
BuildableName = "libS4.dylib"
|
||||
BlueprintName = "S4"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_HTTP"
|
||||
BuildableName = "libHTTP.dylib"
|
||||
BlueprintName = "HTTP"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_CLibvenice"
|
||||
BuildableName = "libCLibvenice.dylib"
|
||||
BlueprintName = "CLibvenice"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_Venice"
|
||||
BuildableName = "libVenice.dylib"
|
||||
BlueprintName = "Venice"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_POSIX"
|
||||
BuildableName = "libPOSIX.dylib"
|
||||
BlueprintName = "POSIX"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_IP"
|
||||
BuildableName = "libIP.dylib"
|
||||
BlueprintName = "IP"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_TCP"
|
||||
BuildableName = "libTCP.dylib"
|
||||
BlueprintName = "TCP"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_CHTTPParser"
|
||||
BuildableName = "libCHTTPParser.dylib"
|
||||
BlueprintName = "CHTTPParser"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_HTTPParser"
|
||||
BuildableName = "libHTTPParser.dylib"
|
||||
BlueprintName = "HTTPParser"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_HTTPSerializer"
|
||||
BuildableName = "libHTTPSerializer.dylib"
|
||||
BlueprintName = "HTTPSerializer"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_HTTPClient"
|
||||
BuildableName = "libHTTPClient.dylib"
|
||||
BlueprintName = "HTTPClient"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_File"
|
||||
BuildableName = "libFile.dylib"
|
||||
BlueprintName = "File"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_OpenSSL"
|
||||
BuildableName = "libOpenSSL.dylib"
|
||||
BlueprintName = "OpenSSL"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_TCPSSL"
|
||||
BuildableName = "libTCPSSL.dylib"
|
||||
BlueprintName = "TCPSSL"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_HTTPSClient"
|
||||
BuildableName = "libHTTPSClient.dylib"
|
||||
BlueprintName = "HTTPSClient"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_Event"
|
||||
BuildableName = "libEvent.dylib"
|
||||
BlueprintName = "Event"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_Base64"
|
||||
BuildableName = "libBase64.dylib"
|
||||
BlueprintName = "Base64"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_WebSocket"
|
||||
BuildableName = "libWebSocket.dylib"
|
||||
BlueprintName = "WebSocket"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "NO"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_Botly"
|
||||
BuildableName = "Botly"
|
||||
BlueprintName = "Botly"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_SlackKit"
|
||||
BuildableName = "libSlackKit.dylib"
|
||||
BlueprintName = "SlackKit"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_C7"
|
||||
BuildableName = "libC7.dylib"
|
||||
BlueprintName = "C7"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_C7"
|
||||
BuildableName = "libC7.dylib"
|
||||
BlueprintName = "C7"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "______Target_C7"
|
||||
BuildableName = "libC7.dylib"
|
||||
BlueprintName = "C7"
|
||||
ReferencedContainer = "container:SlackKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>SlackKit.xcscheme</key>
|
||||
<dict></dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict></dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// SlackKit.h
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for SlackKit.
|
||||
FOUNDATION_EXPORT double SlackKitVersionNumber;
|
||||
|
||||
//! Project version string for SlackKit.
|
||||
FOUNDATION_EXPORT const unsigned char SlackKitVersionString[];
|
||||
@@ -48,7 +48,7 @@ public struct Attachment {
|
||||
text = attachment?["text"] as? String
|
||||
imageURL = attachment?["image_url"] as? String
|
||||
thumbURL = attachment?["thumb_url"] as? String
|
||||
fields = (attachment?["fields"] as? [[String: Any]])?.objectArrayFromDictionaryArray(intializer: {(field) -> AttachmentField? in
|
||||
fields = (attachment?["fields"] as? [Any])?.objectArrayFromDictionaryArray(intializer: {(field) -> AttachmentField? in
|
||||
return AttachmentField(field: field)
|
||||
})
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public struct Attachment {
|
||||
return attachment
|
||||
}
|
||||
|
||||
private func fieldJSONArray(fields: [AttachmentField]?) -> [[String: Any]] {
|
||||
var returnValue = [[String: Any]]()
|
||||
private func fieldJSONArray(fields: [AttachmentField]?) -> [Any] {
|
||||
var returnValue = [Any]()
|
||||
if let f = fields {
|
||||
for field in f {
|
||||
returnValue.append(field.dictionary())
|
||||
@@ -124,3 +124,9 @@ public struct AttachmentField {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum AttachmentColor: String {
|
||||
case Good = "good"
|
||||
case Warning = "warning"
|
||||
case Danger = "danger"
|
||||
}
|
||||
|
||||
+60
-66
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// EventDispatcher.swift
|
||||
// Client+EventDispatching.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
@@ -21,143 +21,137 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
internal class EventDispatcher {
|
||||
let client: SlackClient
|
||||
let handler: EventHandler
|
||||
|
||||
required init(client: SlackClient) {
|
||||
self.client = client
|
||||
handler = EventHandler(client: client)
|
||||
}
|
||||
internal extension SlackClient {
|
||||
|
||||
func dispatch(event: [String: Any]) {
|
||||
let event = Event(event: event)
|
||||
if let type = event.type {
|
||||
switch type {
|
||||
case .Hello:
|
||||
handler.connected()
|
||||
connected = true
|
||||
slackEventsDelegate?.clientConnected()
|
||||
case .Ok:
|
||||
handler.messageSent(event: event)
|
||||
messageSent(event: event)
|
||||
case .Message:
|
||||
if (event.subtype != nil) {
|
||||
messageDispatcher(event: event)
|
||||
} else {
|
||||
handler.messageReceived(event: event)
|
||||
messageReceived(event: event)
|
||||
}
|
||||
case .UserTyping:
|
||||
handler.userTyping(event: event)
|
||||
userTyping(event: event)
|
||||
case .ChannelMarked, .IMMarked, .GroupMarked:
|
||||
handler.channelMarked(event: event)
|
||||
channelMarked(event: event)
|
||||
case .ChannelCreated, .IMCreated:
|
||||
handler.channelCreated(event: event)
|
||||
channelCreated(event: event)
|
||||
case .ChannelJoined, .GroupJoined:
|
||||
handler.channelJoined(event: event)
|
||||
channelJoined(event: event)
|
||||
case .ChannelLeft, .GroupLeft:
|
||||
handler.channelLeft(event: event)
|
||||
channelLeft(event: event)
|
||||
case .ChannelDeleted:
|
||||
handler.channelDeleted(event: event)
|
||||
channelDeleted(event: event)
|
||||
case .ChannelRenamed, .GroupRename:
|
||||
handler.channelRenamed(event: event)
|
||||
channelRenamed(event: event)
|
||||
case .ChannelArchive, .GroupArchive:
|
||||
handler.channelArchived(event: event, archived: true)
|
||||
channelArchived(event: event, archived: true)
|
||||
case .ChannelUnarchive, .GroupUnarchive:
|
||||
handler.channelArchived(event: event, archived: false)
|
||||
channelArchived(event: event, archived: false)
|
||||
case .ChannelHistoryChanged, .IMHistoryChanged, .GroupHistoryChanged:
|
||||
handler.channelHistoryChanged(event: event)
|
||||
channelHistoryChanged(event: event)
|
||||
case .DNDUpdated:
|
||||
handler.doNotDisturbUpdated(event: event)
|
||||
doNotDisturbUpdated(event: event)
|
||||
case .DNDUpatedUser:
|
||||
handler.doNotDisturbUserUpdated(event: event)
|
||||
doNotDisturbUserUpdated(event: event)
|
||||
case .IMOpen, .GroupOpen:
|
||||
handler.open(event: event, open: true)
|
||||
open(event: event, open: true)
|
||||
case .IMClose, .GroupClose:
|
||||
handler.open(event: event, open: false)
|
||||
open(event: event, open: false)
|
||||
case .FileCreated:
|
||||
handler.processFile(event: event)
|
||||
processFile(event: event)
|
||||
case .FileShared:
|
||||
handler.processFile(event: event)
|
||||
processFile(event: event)
|
||||
case .FileUnshared:
|
||||
handler.processFile(event: event)
|
||||
processFile(event: event)
|
||||
case .FilePublic:
|
||||
handler.processFile(event: event)
|
||||
processFile(event: event)
|
||||
case .FilePrivate:
|
||||
handler.filePrivate(event: event)
|
||||
filePrivate(event: event)
|
||||
case .FileChanged:
|
||||
handler.processFile(event: event)
|
||||
processFile(event: event)
|
||||
case .FileDeleted:
|
||||
handler.deleteFile(event: event)
|
||||
deleteFile(event: event)
|
||||
case .FileCommentAdded:
|
||||
handler.fileCommentAdded(event: event)
|
||||
fileCommentAdded(event: event)
|
||||
case .FileCommentEdited:
|
||||
handler.fileCommentEdited(event: event)
|
||||
fileCommentEdited(event: event)
|
||||
case .FileCommentDeleted:
|
||||
handler.fileCommentDeleted(event: event)
|
||||
fileCommentDeleted(event: event)
|
||||
case .PinAdded:
|
||||
handler.pinAdded(event: event)
|
||||
pinAdded(event: event)
|
||||
case .PinRemoved:
|
||||
handler.pinRemoved(event: event)
|
||||
pinRemoved(event: event)
|
||||
case .Pong:
|
||||
handler.pong(event: event)
|
||||
pong(event: event)
|
||||
case .PresenceChange:
|
||||
handler.presenceChange(event: event)
|
||||
presenceChange(event: event)
|
||||
case .ManualPresenceChange:
|
||||
handler.manualPresenceChange(event: event)
|
||||
manualPresenceChange(event: event)
|
||||
case .PrefChange:
|
||||
handler.changePreference(event: event)
|
||||
changePreference(event: event)
|
||||
case .UserChange:
|
||||
handler.userChange(event: event)
|
||||
userChange(event: event)
|
||||
case .TeamJoin:
|
||||
handler.teamJoin(event: event)
|
||||
teamJoin(event: event)
|
||||
case .StarAdded:
|
||||
handler.itemStarred(event: event, star: true)
|
||||
itemStarred(event: event, star: true)
|
||||
case .StarRemoved:
|
||||
handler.itemStarred(event: event, star: false)
|
||||
itemStarred(event: event, star: false)
|
||||
case .ReactionAdded:
|
||||
handler.addedReaction(event: event)
|
||||
addedReaction(event: event)
|
||||
case .ReactionRemoved:
|
||||
handler.removedReaction(event: event)
|
||||
removedReaction(event: event)
|
||||
case .EmojiChanged:
|
||||
handler.emojiChanged(event: event)
|
||||
emojiChanged(event: event)
|
||||
case .CommandsChanged:
|
||||
// This functionality is only used by our web client.
|
||||
// The other APIs required to support slash command metadata are currently unstable.
|
||||
// Until they are released other clients should ignore this event.
|
||||
break
|
||||
case .TeamPlanChange:
|
||||
handler.teamPlanChange(event: event)
|
||||
teamPlanChange(event: event)
|
||||
case .TeamPrefChange:
|
||||
handler.teamPreferenceChange(event: event)
|
||||
teamPreferenceChange(event: event)
|
||||
case .TeamRename:
|
||||
handler.teamNameChange(event: event)
|
||||
teamNameChange(event: event)
|
||||
case .TeamDomainChange:
|
||||
handler.teamDomainChange(event: event)
|
||||
teamDomainChange(event: event)
|
||||
case .EmailDomainChange:
|
||||
handler.emailDomainChange(event: event)
|
||||
emailDomainChange(event: event)
|
||||
case .TeamProfileChange:
|
||||
handler.teamProfileChange(event: event)
|
||||
teamProfileChange(event: event)
|
||||
case .TeamProfileDelete:
|
||||
handler.teamProfileDeleted(event: event)
|
||||
teamProfileDeleted(event: event)
|
||||
case .TeamProfileReorder:
|
||||
handler.teamProfileReordered(event: event)
|
||||
teamProfileReordered(event: event)
|
||||
case .BotAdded:
|
||||
handler.bot(event: event)
|
||||
bot(event: event)
|
||||
case .BotChanged:
|
||||
handler.bot(event: event)
|
||||
bot(event: event)
|
||||
case .AccountsChanged:
|
||||
// The accounts_changed event is used by our web client to maintain a list of logged-in accounts.
|
||||
// Other clients should ignore this event.
|
||||
break
|
||||
case .TeamMigrationStarted:
|
||||
client.connect(pingInterval: client.pingInterval, timeout: client.timeout, reconnect: client.reconnect)
|
||||
connect(pingInterval: pingInterval, timeout: timeout, reconnect: reconnect)
|
||||
case .ReconnectURL:
|
||||
// The reconnect_url event is currently unsupported and experimental.
|
||||
break
|
||||
case .SubteamCreated, .SubteamUpdated:
|
||||
handler.subteam(event: event)
|
||||
subteam(event: event)
|
||||
case .SubteamSelfAdded:
|
||||
handler.subteamAddedSelf(event: event)
|
||||
subteamAddedSelf(event: event)
|
||||
case.SubteamSelfRemoved:
|
||||
handler.subteamRemovedSelf(event: event)
|
||||
subteamRemovedSelf(event: event)
|
||||
case .Error:
|
||||
print("Error: \(event)")
|
||||
break
|
||||
@@ -169,11 +163,11 @@ internal class EventDispatcher {
|
||||
let subtype = MessageSubtype(rawValue: event.subtype!)!
|
||||
switch subtype {
|
||||
case .MessageChanged:
|
||||
handler.messageChanged(event: event)
|
||||
messageChanged(event: event)
|
||||
case .MessageDeleted:
|
||||
handler.messageDeleted(event: event)
|
||||
messageDeleted(event: event)
|
||||
default:
|
||||
handler.messageReceived(event: event)
|
||||
messageReceived(event: event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,547 @@
|
||||
//
|
||||
// Client+EventHandling.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Venice
|
||||
|
||||
internal extension SlackClient {
|
||||
|
||||
//MARK: - Pong
|
||||
func pong(event: Event) {
|
||||
pong = event.replyTo
|
||||
}
|
||||
|
||||
//MARK: - Messages
|
||||
func messageSent(event: Event) {
|
||||
if let reply = event.replyTo, message = sentMessages["\(reply)"], channel = message.channel, ts = message.ts {
|
||||
message.ts = event.ts
|
||||
message.text = event.text
|
||||
channels[channel]?.messages[ts] = message
|
||||
|
||||
messageEventsDelegate?.messageSent(message: message)
|
||||
}
|
||||
}
|
||||
|
||||
func messageReceived(event: Event) {
|
||||
if let channel = event.channel, message = event.message, id = channel.id, ts = message.ts {
|
||||
channels[id]?.messages[ts] = message
|
||||
|
||||
messageEventsDelegate?.messageReceived(message: message)
|
||||
}
|
||||
}
|
||||
|
||||
func messageChanged(event: Event) {
|
||||
if let id = event.channel?.id, nested = event.nestedMessage, ts = nested.ts {
|
||||
channels[id]?.messages[ts] = nested
|
||||
|
||||
messageEventsDelegate?.messageChanged(message: nested)
|
||||
}
|
||||
}
|
||||
|
||||
func messageDeleted(event: Event) {
|
||||
if let id = event.channel?.id, key = event.message?.deletedTs {
|
||||
let message = channels[id]?.messages[key]
|
||||
channels[id]?.messages.removeValue(forKey:key)
|
||||
|
||||
messageEventsDelegate?.messageDeleted(message: message)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Channels
|
||||
func userTyping(event: Event) {
|
||||
if let channelID = event.channel?.id, userID = event.user?.id {
|
||||
if let _ = channels[channelID] {
|
||||
if (!channels[channelID]!.usersTyping.contains(userID)) {
|
||||
channels[channelID]?.usersTyping.append(userID)
|
||||
|
||||
channelEventsDelegate?.userTyping(channel: event.channel, user: event.user)
|
||||
}
|
||||
}
|
||||
|
||||
co { [weak self] in
|
||||
let weakSelf = self
|
||||
nap(for: 5.0.seconds)
|
||||
if let index = weakSelf?.channels[channelID]?.usersTyping.index(of:userID) {
|
||||
weakSelf?.channels[channelID]?.usersTyping.remove(at: index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelMarked(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id]?.lastRead = event.ts
|
||||
|
||||
channelEventsDelegate?.channelMarked(channel: channel, timestamp: event.ts)
|
||||
}
|
||||
//TODO: Recalculate unreads
|
||||
}
|
||||
|
||||
func channelCreated(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id] = channel
|
||||
|
||||
channelEventsDelegate?.channelCreated(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
func channelDeleted(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels.removeValue(forKey:id)
|
||||
|
||||
channelEventsDelegate?.channelDeleted(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
func channelJoined(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id] = event.channel
|
||||
|
||||
channelEventsDelegate?.channelJoined(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
func channelLeft(event: Event) {
|
||||
if let channel = event.channel, id = channel.id, userID = authenticatedUser?.id {
|
||||
if let index = channels[id]?.members?.index(of:userID) {
|
||||
channels[id]?.members?.remove(at: index)
|
||||
|
||||
channelEventsDelegate?.channelLeft(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelRenamed(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id]?.name = channel.name
|
||||
|
||||
channelEventsDelegate?.channelRenamed(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
func channelArchived(event: Event, archived: Bool) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id]?.isArchived = archived
|
||||
|
||||
channelEventsDelegate?.channelArchived(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
func channelHistoryChanged(event: Event) {
|
||||
if let channel = event.channel {
|
||||
//TODO: Reload chat history if there are any cached messages before latest
|
||||
|
||||
channelEventsDelegate?.channelHistoryChanged(channel: channel)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Do Not Disturb
|
||||
func doNotDisturbUpdated(event: Event) {
|
||||
if let dndStatus = event.dndStatus {
|
||||
authenticatedUser?.doNotDisturbStatus = dndStatus
|
||||
|
||||
doNotDisturbEventsDelegate?.doNotDisturbUpdated(dndStatus: dndStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func doNotDisturbUserUpdated(event: Event) {
|
||||
if let dndStatus = event.dndStatus, user = event.user, id = user.id {
|
||||
users[id]?.doNotDisturbStatus = dndStatus
|
||||
|
||||
doNotDisturbEventsDelegate?.doNotDisturbUserUpdated(dndStatus: dndStatus, user: user)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - IM & Group Open/Close
|
||||
func open(event: Event, open: Bool) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
channels[id]?.isOpen = open
|
||||
|
||||
groupEventsDelegate?.groupOpened(group: channel)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Files
|
||||
func processFile(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
if let comment = file.initialComment, commentID = comment.id {
|
||||
if files[id]?.comments[commentID] == nil {
|
||||
files[id]?.comments[commentID] = comment
|
||||
}
|
||||
}
|
||||
|
||||
files[id] = file
|
||||
|
||||
fileEventsDelegate?.fileProcessed(file: file)
|
||||
}
|
||||
}
|
||||
|
||||
func filePrivate(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
files[id]?.isPublic = false
|
||||
|
||||
fileEventsDelegate?.fileMadePrivate(file: file)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteFile(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
if files[id] != nil {
|
||||
files.removeValue(forKey:id)
|
||||
}
|
||||
|
||||
fileEventsDelegate?.fileDeleted(file: file)
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentAdded(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
files[id]?.comments[commentID] = comment
|
||||
|
||||
fileEventsDelegate?.fileCommentAdded(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentEdited(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
files[id]?.comments[commentID]?.comment = comment.comment
|
||||
|
||||
fileEventsDelegate?.fileCommentEdited(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentDeleted(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
files[id]?.comments.removeValue(forKey:commentID)
|
||||
|
||||
fileEventsDelegate?.fileCommentDeleted(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Pins
|
||||
func pinAdded(event: Event) {
|
||||
if let id = event.channelID, item = event.item {
|
||||
channels[id]?.pinnedItems.append(item)
|
||||
|
||||
pinEventsDelegate?.itemPinned(item: item, channel: channels[id])
|
||||
}
|
||||
}
|
||||
|
||||
func pinRemoved(event: Event) {
|
||||
if let id = event.channelID {
|
||||
if let pins = channels[id]?.pinnedItems.filter({$0 != event.item}) {
|
||||
channels[id]?.pinnedItems = pins
|
||||
}
|
||||
|
||||
pinEventsDelegate?.itemUnpinned(item: event.item, channel: channels[id])
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Stars
|
||||
func itemStarred(event: Event, star: Bool) {
|
||||
if let item = event.item, type = item.type {
|
||||
switch type {
|
||||
case "message":
|
||||
starMessage(item: item, star: star)
|
||||
case "file":
|
||||
starFile(item: item, star: star)
|
||||
case "file_comment":
|
||||
starComment(item: item)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
starEventsDelegate?.itemStarred(item: item, star: star)
|
||||
}
|
||||
}
|
||||
|
||||
func starMessage(item: Item, star: Bool) {
|
||||
if let message = item.message, ts = message.ts, channel = item.channel {
|
||||
if let _ = channels[channel]?.messages[ts] {
|
||||
channels[channel]?.messages[ts]?.isStarred = star
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starFile(item: Item, star: Bool) {
|
||||
if let file = item.file, id = file.id {
|
||||
files[id]?.isStarred = star
|
||||
if let stars = files[id]?.stars {
|
||||
if star == true {
|
||||
files[id]?.stars = stars + 1
|
||||
} else {
|
||||
if stars > 0 {
|
||||
files[id]?.stars = stars - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starComment(item: Item) {
|
||||
if let file = item.file, id = file.id, comment = item.comment, commentID = comment.id {
|
||||
files[id]?.comments[commentID] = comment
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Reactions
|
||||
func addedReaction(event: Event) {
|
||||
if let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id {
|
||||
switch type {
|
||||
case "message":
|
||||
if let channel = item.channel, ts = item.ts {
|
||||
if let message = channels[channel]?.messages[ts] {
|
||||
if (message.reactions[key]) == nil {
|
||||
message.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
message.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
}
|
||||
case "file":
|
||||
if let id = item.file?.id, file = files[id] {
|
||||
if file.reactions[key] == nil {
|
||||
files[id]?.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
files[id]?.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
case "file_comment":
|
||||
if let id = item.file?.id, file = files[id], commentID = item.fileCommentID {
|
||||
if file.comments[commentID]?.reactions[key] == nil {
|
||||
files[id]?.comments[commentID]?.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
files[id]?.comments[commentID]?.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
reactionEventsDelegate?.reactionAdded(reaction: event.reaction, item: event.item, itemUser: event.itemUser)
|
||||
}
|
||||
}
|
||||
|
||||
func removedReaction(event: Event) {
|
||||
if let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id {
|
||||
switch type {
|
||||
case "message":
|
||||
if let channel = item.channel, ts = item.ts {
|
||||
if let message = channels[channel]?.messages[ts] {
|
||||
if (message.reactions[key]) != nil {
|
||||
message.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if (message.reactions[key]?.users.count == 0) {
|
||||
message.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "file":
|
||||
if let itemFile = item.file, id = itemFile.id, file = files[id] {
|
||||
if file.reactions[key] != nil {
|
||||
files[id]?.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if files[id]?.reactions[key]?.users.count == 0 {
|
||||
files[id]?.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
case "file_comment":
|
||||
if let id = item.file?.id, file = files[id], commentID = item.fileCommentID {
|
||||
if file.comments[commentID]?.reactions[key] != nil {
|
||||
files[id]?.comments[commentID]?.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if files[id]?.comments[commentID]?.reactions[key]?.users.count == 0 {
|
||||
files[id]?.comments[commentID]?.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
reactionEventsDelegate?.reactionRemoved(reaction: event.reaction, item: event.item, itemUser: event.itemUser)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Preferences
|
||||
func changePreference(event: Event) {
|
||||
if let name = event.name {
|
||||
authenticatedUser?.preferences?[name] = event.value
|
||||
|
||||
slackEventsDelegate?.preferenceChanged(preference: name, value: event.value)
|
||||
}
|
||||
}
|
||||
|
||||
//Mark: - User Change
|
||||
func userChange(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
let preferences = users[id]?.preferences
|
||||
users[id] = user
|
||||
users[id]?.preferences = preferences
|
||||
|
||||
slackEventsDelegate?.userChanged(user: user)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - User Presence
|
||||
func presenceChange(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
users[id]?.presence = event.presence
|
||||
|
||||
slackEventsDelegate?.presenceChanged(user: user, presence: event.presence)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Team
|
||||
func teamJoin(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
users[id] = user
|
||||
|
||||
teamEventsDelegate?.teamJoined(user: user)
|
||||
}
|
||||
}
|
||||
|
||||
func teamPlanChange(event: Event) {
|
||||
if let plan = event.plan {
|
||||
team?.plan = plan
|
||||
|
||||
teamEventsDelegate?.teamPlanChanged(plan: plan)
|
||||
}
|
||||
}
|
||||
|
||||
func teamPreferenceChange(event: Event) {
|
||||
if let name = event.name {
|
||||
team?.prefs?[name] = event.value
|
||||
|
||||
teamEventsDelegate?.teamPreferencesChanged(preference: name, value: event.value)
|
||||
}
|
||||
}
|
||||
|
||||
func teamNameChange(event: Event) {
|
||||
if let name = event.name {
|
||||
team?.name = name
|
||||
|
||||
teamEventsDelegate?.teamNameChanged(name: name)
|
||||
}
|
||||
}
|
||||
|
||||
func teamDomainChange(event: Event) {
|
||||
if let domain = event.domain {
|
||||
team?.domain = domain
|
||||
|
||||
teamEventsDelegate?.teamDomainChanged(domain: domain)
|
||||
}
|
||||
}
|
||||
|
||||
func emailDomainChange(event: Event) {
|
||||
if let domain = event.emailDomain {
|
||||
team?.emailDomain = domain
|
||||
|
||||
teamEventsDelegate?.teamEmailDomainChanged(domain: domain)
|
||||
}
|
||||
}
|
||||
|
||||
func emojiChanged(event: Event) {
|
||||
//TODO: Call emoji.list here
|
||||
|
||||
teamEventsDelegate?.teamEmojiChanged()
|
||||
}
|
||||
|
||||
//MARK: - Bots
|
||||
func bot(event: Event) {
|
||||
if let bot = event.bot, id = bot.id {
|
||||
bots[id] = bot
|
||||
|
||||
slackEventsDelegate?.botEvent(bot: bot)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Subteams
|
||||
func subteam(event: Event) {
|
||||
if let subteam = event.subteam, id = subteam.id {
|
||||
userGroups[id] = subteam
|
||||
|
||||
subteamEventsDelegate?.subteamEvent(userGroup: subteam)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func subteamAddedSelf(event: Event) {
|
||||
if let subteamID = event.subteamID, _ = authenticatedUser?.userGroups {
|
||||
authenticatedUser?.userGroups![subteamID] = subteamID
|
||||
|
||||
subteamEventsDelegate?.subteamSelfAdded(subteamID: subteamID)
|
||||
}
|
||||
}
|
||||
|
||||
func subteamRemovedSelf(event: Event) {
|
||||
if let subteamID = event.subteamID {
|
||||
authenticatedUser?.userGroups?.removeValue(forKey:subteamID)
|
||||
|
||||
subteamEventsDelegate?.subteamSelfRemoved(subteamID: subteamID)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Team Profiles
|
||||
func teamProfileChange(event: Event) {
|
||||
for user in users {
|
||||
if let fields = event.profile?.fields {
|
||||
for key in fields.keys {
|
||||
users[user.0]?.profile?.customProfile?.fields[key]?.updateProfileField(profile: fields[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileChanged(profile: event.profile)
|
||||
}
|
||||
|
||||
func teamProfileDeleted(event: Event) {
|
||||
for user in users {
|
||||
if let id = event.profile?.fields.first?.0 {
|
||||
users[user.0]?.profile?.customProfile?.fields[id] = nil
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileDeleted(profile: event.profile)
|
||||
}
|
||||
|
||||
func teamProfileReordered(event: Event) {
|
||||
for user in users {
|
||||
if let keys = event.profile?.fields.keys {
|
||||
for key in keys {
|
||||
users[user.0]?.profile?.customProfile?.fields[key]?.ordering = event.profile?.fields[key]?.ordering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
teamProfileEventsDelegate?.teamProfileReordered(profile: event.profile)
|
||||
}
|
||||
|
||||
//MARK: - Authenticated User
|
||||
func manualPresenceChange(event: Event) {
|
||||
authenticatedUser?.presence = event.presence
|
||||
|
||||
slackEventsDelegate?.manualPresenceChanged(user: authenticatedUser, presence: event.presence)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// SlackKit.h
|
||||
// Client+Utilities.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
@@ -21,10 +21,33 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for SlackKit.
|
||||
FOUNDATION_EXPORT double SlackKitVersionNumber;
|
||||
|
||||
//! Project version string for SlackKit.
|
||||
FOUNDATION_EXPORT const unsigned char SlackKitVersionString[];
|
||||
extension SlackClient {
|
||||
|
||||
//MARK: - User & Channel
|
||||
public func getChannelIDByName(name: String) -> String? {
|
||||
return channels.filter{$0.1.name == stripString(string: name)}.first?.0
|
||||
}
|
||||
|
||||
public func getUserIDByName(name: String) -> String? {
|
||||
return users.filter{$0.1.name == stripString(string: name)}.first?.0
|
||||
}
|
||||
|
||||
public func getImIDForUserWithID(id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) {
|
||||
let ims = channels.filter{$0.1.isIM == true}
|
||||
let channel = ims.filter{$0.1.user == id}.first
|
||||
if let channel = channel {
|
||||
success(imID: channel.0)
|
||||
} else {
|
||||
webAPI.openIM(userID: id, success: success, failure: failure)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Utilities
|
||||
internal func stripString(string: String) -> String? {
|
||||
var strippedString = string
|
||||
if string[string.startIndex] == "@" || string[string.startIndex] == "#" {
|
||||
strippedString.characters.remove(at: string.startIndex)
|
||||
}
|
||||
return strippedString
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
import C7
|
||||
import Jay
|
||||
import WebSocket
|
||||
import Venice
|
||||
import WebSocketClient
|
||||
|
||||
public class SlackClient {
|
||||
|
||||
@@ -40,18 +41,18 @@ public class SlackClient {
|
||||
internal(set) public var sentMessages = [String: Message]()
|
||||
|
||||
//MARK: - Delegates
|
||||
public var slackEventsDelegate: SlackEventsDelegate?
|
||||
public var messageEventsDelegate: MessageEventsDelegate?
|
||||
public var doNotDisturbEventsDelegate: DoNotDisturbEventsDelegate?
|
||||
public var channelEventsDelegate: ChannelEventsDelegate?
|
||||
public var groupEventsDelegate: GroupEventsDelegate?
|
||||
public var fileEventsDelegate: FileEventsDelegate?
|
||||
public var pinEventsDelegate: PinEventsDelegate?
|
||||
public var starEventsDelegate: StarEventsDelegate?
|
||||
public var reactionEventsDelegate: ReactionEventsDelegate?
|
||||
public var teamEventsDelegate: TeamEventsDelegate?
|
||||
public var subteamEventsDelegate: SubteamEventsDelegate?
|
||||
public var teamProfileEventsDelegate: TeamProfileEventsDelegate?
|
||||
public weak var slackEventsDelegate: SlackEventsDelegate?
|
||||
public weak var messageEventsDelegate: MessageEventsDelegate?
|
||||
public weak var doNotDisturbEventsDelegate: DoNotDisturbEventsDelegate?
|
||||
public weak var channelEventsDelegate: ChannelEventsDelegate?
|
||||
public weak var groupEventsDelegate: GroupEventsDelegate?
|
||||
public weak var fileEventsDelegate: FileEventsDelegate?
|
||||
public weak var pinEventsDelegate: PinEventsDelegate?
|
||||
public weak var starEventsDelegate: StarEventsDelegate?
|
||||
public weak var reactionEventsDelegate: ReactionEventsDelegate?
|
||||
public weak var teamEventsDelegate: TeamEventsDelegate?
|
||||
public weak var subteamEventsDelegate: SubteamEventsDelegate?
|
||||
public weak var teamProfileEventsDelegate: TeamProfileEventsDelegate?
|
||||
|
||||
internal var token = "SLACK_AUTH_TOKEN"
|
||||
|
||||
@@ -63,11 +64,10 @@ public class SlackClient {
|
||||
return SlackWebAPI(slackClient: self)
|
||||
}
|
||||
|
||||
internal var webSocket: WebSocket.Client?
|
||||
internal var webSocket: Client?
|
||||
internal var socket: WebSocket?
|
||||
internal let api = NetworkInterface()
|
||||
private var dispatcher: EventDispatcher?
|
||||
|
||||
//private let pingPongQueue = dispatch_queue_create("com.launchsoft.SlackKit", DISPATCH_QUEUE_SERIAL)
|
||||
internal var ping: Double?
|
||||
internal var pong: Double?
|
||||
|
||||
@@ -83,18 +83,17 @@ public class SlackClient {
|
||||
self.pingInterval = pingInterval
|
||||
self.timeout = timeout
|
||||
self.reconnect = reconnect
|
||||
dispatcher = EventDispatcher(client: self)
|
||||
webAPI.rtmStart(simpleLatest: simpleLatest, noUnreads: noUnreads, mpimAware: mpimAware, success: {
|
||||
(response) -> Void in
|
||||
self.initialSetup(json: response)
|
||||
if let socketURL = response["url"] as? String {
|
||||
do {
|
||||
let uri = try URI(socketURL)
|
||||
self.webSocket = try WebSocket.Client(uri: uri, onConnect: {(socket) in
|
||||
self.webSocket = try Client(uri: uri, didConnect: {(socket) in
|
||||
self.setupSocket(socket: socket)
|
||||
/*if let pingInterval = self.pingInterval {
|
||||
if let pingInterval = self.pingInterval {
|
||||
self.pingRTMServerAtInterval(interval: pingInterval)
|
||||
}*/
|
||||
}
|
||||
})
|
||||
try self.webSocket?.connect(uri.description)
|
||||
} catch _ {
|
||||
@@ -104,25 +103,25 @@ public class SlackClient {
|
||||
}, failure:nil)
|
||||
}
|
||||
|
||||
//TODO: Currently Unsupported
|
||||
/*public func disconnect() {
|
||||
//webSocket?.disconnect()
|
||||
}
|
||||
/*TO-DO: Bug in Zewo/WebSocket
|
||||
public func disconnect() {
|
||||
_ = try? socket?.close()
|
||||
}*/
|
||||
|
||||
//MARK: - RTM Message send
|
||||
public func sendMessage(message: String, channelID: String) {
|
||||
if (connected) {
|
||||
if let data = formatMessageToSlackJsonString(message: message, channel: channelID) {
|
||||
if let string = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
|
||||
//webSocket?.writeString(string)
|
||||
if let string = try? data.string() {
|
||||
_ = try? socket?.send(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private func formatMessageToSlackJsonString(message: String, channel: String) -> Data? {
|
||||
let json: [String: Any] = [
|
||||
"id": Time.slackTimestamp,
|
||||
"id": Time.slackTimestamp(),
|
||||
"type": "message",
|
||||
"channel": channel,
|
||||
"text": message.slackFormatEscaping()
|
||||
@@ -146,31 +145,28 @@ public class SlackClient {
|
||||
}
|
||||
|
||||
//MARK: - RTM Ping
|
||||
/*private func pingRTMServerAtInterval(interval: NSTimeInterval) {
|
||||
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(interval * Double(NSEC_PER_SEC)))
|
||||
dispatch_after(delay, pingPongQueue, {
|
||||
if self.connected && self.timeoutCheck() {
|
||||
self.sendRTMPing()
|
||||
self.pingRTMServerAtInterval(interval: interval)
|
||||
} else {
|
||||
//self.disconnect()
|
||||
}
|
||||
})
|
||||
private func pingRTMServerAtInterval(interval: Double) {
|
||||
co { [weak self] in
|
||||
let weakSelf = self
|
||||
repeat {
|
||||
nap(for: interval)
|
||||
weakSelf?.sendRTMPing()
|
||||
} while weakSelf?.connected == true && weakSelf?.timeoutCheck() == true
|
||||
//weakSelf?.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
private func sendRTMPing() {
|
||||
if connected {
|
||||
let json: [String: Any] = [
|
||||
"id": NSDate().slackTimestamp(),
|
||||
"id": Double.slackTimestamp(),
|
||||
"type": "ping",
|
||||
]
|
||||
do {
|
||||
let data = try NSJSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
|
||||
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
if let writePing = string as? String {
|
||||
ping = json["id"] as? Double
|
||||
//webSocket?.writeString(writePing)
|
||||
}
|
||||
let data = try Jay().dataFromJson(json)
|
||||
let string = try data.string()
|
||||
ping = json["id"] as? Double
|
||||
try socket?.send(string)
|
||||
}
|
||||
catch _ {
|
||||
|
||||
@@ -189,7 +185,7 @@ public class SlackClient {
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//MARK: - Client setup
|
||||
private func initialSetup(json: [String: Any]) {
|
||||
@@ -225,9 +221,9 @@ public class SlackClient {
|
||||
|
||||
private func enumerateSubteams(subteams: [String: Any]?) {
|
||||
if let subteams = subteams {
|
||||
if let all = subteams["all"] as? [[String: Any]] {
|
||||
if let all = subteams["all"] as? [Any] {
|
||||
for item in all {
|
||||
let u = UserGroup(userGroup: item)
|
||||
let u = UserGroup(userGroup: item as? [String: Any])
|
||||
self.userGroups[u!.id!] = u
|
||||
}
|
||||
}
|
||||
@@ -253,7 +249,7 @@ public class SlackClient {
|
||||
|
||||
|
||||
// MARK: - WebSocket
|
||||
private func setupSocket(socket: Socket) {
|
||||
private func setupSocket(socket: WebSocket) {
|
||||
socket.onText {(message) in
|
||||
self.websocketDidReceive(message: message)
|
||||
}
|
||||
@@ -262,13 +258,14 @@ public class SlackClient {
|
||||
socket.onClose{ (code: CloseCode?, reason: String?) in
|
||||
self.websocketDidDisconnect(closeCode: code, error: reason)
|
||||
}
|
||||
self.socket = socket
|
||||
}
|
||||
|
||||
private func websocketDidReceive(message: String) {
|
||||
do {
|
||||
let json = try Jay().jsonFromData(message.data.bytes)
|
||||
if let event = json as? [String: Any] {
|
||||
dispatcher?.dispatch(event:event)
|
||||
dispatch(event:event)
|
||||
}
|
||||
}
|
||||
catch _ {
|
||||
@@ -281,7 +278,7 @@ public class SlackClient {
|
||||
connected = false
|
||||
authenticated = false
|
||||
webSocket = nil
|
||||
dispatcher = nil
|
||||
socket = nil
|
||||
authenticatedUser = nil
|
||||
slackEventsDelegate?.clientDisconnected()
|
||||
if reconnect == true {
|
||||
|
||||
@@ -144,7 +144,6 @@ internal struct Event {
|
||||
let emailDomain: String?
|
||||
let reaction: String?
|
||||
let replyTo: Double?
|
||||
let reactions: [[String: Any]]?
|
||||
let edited: Edited?
|
||||
let bot: Bot?
|
||||
let channel: Channel?
|
||||
@@ -186,7 +185,6 @@ internal struct Event {
|
||||
emailDomain = event["email_domain"] as? String
|
||||
reaction = event["reaction"] as? String
|
||||
replyTo = event["reply_to"] as? Double
|
||||
reactions = event["reactions"] as? [[String: Any]]
|
||||
bot = Bot(bot: event["bot"] as? [String: Any])
|
||||
edited = Edited(edited:event["edited"] as? [String: Any])
|
||||
dndStatus = DoNotDisturbStatus(status: event["dnd_status"] as? [String: Any])
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
public protocol SlackEventsDelegate {
|
||||
public protocol SlackEventsDelegate: class {
|
||||
func clientConnected()
|
||||
func clientDisconnected()
|
||||
func preferenceChanged(preference: String, value: Any)
|
||||
@@ -31,14 +31,14 @@ public protocol SlackEventsDelegate {
|
||||
func botEvent(bot: Bot)
|
||||
}
|
||||
|
||||
public protocol MessageEventsDelegate {
|
||||
public protocol MessageEventsDelegate: class {
|
||||
func messageSent(message: Message)
|
||||
func messageReceived(message: Message)
|
||||
func messageChanged(message: Message)
|
||||
func messageDeleted(message: Message?)
|
||||
}
|
||||
|
||||
public protocol ChannelEventsDelegate {
|
||||
public protocol ChannelEventsDelegate: class {
|
||||
func userTyping(channel: Channel?, user: User?)
|
||||
func channelMarked(channel: Channel, timestamp: String?)
|
||||
func channelCreated(channel: Channel)
|
||||
@@ -50,16 +50,16 @@ public protocol ChannelEventsDelegate {
|
||||
func channelLeft(channel: Channel)
|
||||
}
|
||||
|
||||
public protocol DoNotDisturbEventsDelegate {
|
||||
public protocol DoNotDisturbEventsDelegate: class {
|
||||
func doNotDisturbUpdated(dndStatus: DoNotDisturbStatus)
|
||||
func doNotDisturbUserUpdated(dndStatus: DoNotDisturbStatus, user: User?)
|
||||
}
|
||||
|
||||
public protocol GroupEventsDelegate {
|
||||
public protocol GroupEventsDelegate: class {
|
||||
func groupOpened(group: Channel)
|
||||
}
|
||||
|
||||
public protocol FileEventsDelegate {
|
||||
public protocol FileEventsDelegate: class {
|
||||
func fileProcessed(file: File)
|
||||
func fileMadePrivate(file: File)
|
||||
func fileDeleted(file: File)
|
||||
@@ -68,21 +68,21 @@ public protocol FileEventsDelegate {
|
||||
func fileCommentDeleted(file: File, comment: Comment)
|
||||
}
|
||||
|
||||
public protocol PinEventsDelegate {
|
||||
public protocol PinEventsDelegate: class {
|
||||
func itemPinned(item: Item?, channel: Channel?)
|
||||
func itemUnpinned(item: Item?, channel: Channel?)
|
||||
}
|
||||
|
||||
public protocol StarEventsDelegate {
|
||||
public protocol StarEventsDelegate: class {
|
||||
func itemStarred(item: Item, star: Bool)
|
||||
}
|
||||
|
||||
public protocol ReactionEventsDelegate {
|
||||
public protocol ReactionEventsDelegate: class {
|
||||
func reactionAdded(reaction: String?, item: Item?, itemUser: String?)
|
||||
func reactionRemoved(reaction: String?, item: Item?, itemUser: String?)
|
||||
}
|
||||
|
||||
public protocol TeamEventsDelegate {
|
||||
public protocol TeamEventsDelegate: class {
|
||||
func teamJoined(user: User)
|
||||
func teamPlanChanged(plan: String)
|
||||
func teamPreferencesChanged(preference: String, value: Any)
|
||||
@@ -92,13 +92,13 @@ public protocol TeamEventsDelegate {
|
||||
func teamEmojiChanged()
|
||||
}
|
||||
|
||||
public protocol SubteamEventsDelegate {
|
||||
public protocol SubteamEventsDelegate: class {
|
||||
func subteamEvent(userGroup: UserGroup)
|
||||
func subteamSelfAdded(subteamID: String)
|
||||
func subteamSelfRemoved(subteamID: String)
|
||||
}
|
||||
|
||||
public protocol TeamProfileEventsDelegate {
|
||||
public protocol TeamProfileEventsDelegate: class {
|
||||
func teamProfileChanged(profile: CustomProfile?)
|
||||
func teamProfileDeleted(profile: CustomProfile?)
|
||||
func teamProfileReordered(profile: CustomProfile?)
|
||||
|
||||
@@ -1,647 +0,0 @@
|
||||
//
|
||||
// EventHandler.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
internal class EventHandler {
|
||||
let client: SlackClient
|
||||
required init(client: SlackClient) {
|
||||
self.client = client
|
||||
}
|
||||
|
||||
//MARK: - Initial connection
|
||||
func connected() {
|
||||
client.connected = true
|
||||
|
||||
if let delegate = client.slackEventsDelegate {
|
||||
delegate.clientConnected()
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Pong
|
||||
func pong(event: Event) {
|
||||
client.pong = event.replyTo
|
||||
}
|
||||
|
||||
//MARK: - Messages
|
||||
func messageSent(event: Event) {
|
||||
if let reply = event.replyTo, message = client.sentMessages["\(reply)"], channel = message.channel, ts = message.ts {
|
||||
message.ts = event.ts
|
||||
message.text = event.text
|
||||
client.channels[channel]?.messages[ts] = message
|
||||
|
||||
if let delegate = client.messageEventsDelegate {
|
||||
delegate.messageSent(message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageReceived(event: Event) {
|
||||
if let channel = event.channel, message = event.message, id = channel.id, ts = message.ts {
|
||||
client.channels[id]?.messages[ts] = message
|
||||
|
||||
if let delegate = client.messageEventsDelegate {
|
||||
delegate.messageReceived(message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageChanged(event: Event) {
|
||||
if let id = event.channel?.id, nested = event.nestedMessage, ts = nested.ts {
|
||||
client.channels[id]?.messages[ts] = nested
|
||||
|
||||
if let delegate = client.messageEventsDelegate {
|
||||
delegate.messageChanged(message: nested)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageDeleted(event: Event) {
|
||||
if let id = event.channel?.id, key = event.message?.deletedTs {
|
||||
let message = client.channels[id]?.messages[key]
|
||||
client.channels[id]?.messages.removeValue(forKey:key)
|
||||
|
||||
if let delegate = client.messageEventsDelegate {
|
||||
delegate.messageDeleted(message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Channels
|
||||
func userTyping(event: Event) {
|
||||
if let channelID = event.channel?.id, userID = event.user?.id {
|
||||
if let _ = client.channels[channelID] {
|
||||
if (!client.channels[channelID]!.usersTyping.contains(userID)) {
|
||||
client.channels[channelID]?.usersTyping.append(userID)
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.userTyping(channel: event.channel, user: event.user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*let timeout = dispatch_time(DISPATCH_TIME_NOW, Int64(5.0 * Double(NSEC_PER_SEC)))
|
||||
dispatch_after(timeout, dispatch_get_main_queue()) {
|
||||
if let index = self.client.channels[channelID]?.usersTyping.index(of:userID) {
|
||||
self.client.channels[channelID]?.usersTyping.remove(at: index)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
func channelMarked(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id]?.lastRead = event.ts
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelMarked(channel: channel, timestamp: event.ts)
|
||||
}
|
||||
}
|
||||
//TODO: Recalculate unreads
|
||||
}
|
||||
|
||||
func channelCreated(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id] = channel
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelCreated(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelDeleted(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels.removeValue(forKey:id)
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelDeleted(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelJoined(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id] = event.channel
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelJoined(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelLeft(event: Event) {
|
||||
if let channel = event.channel, id = channel.id, userID = client.authenticatedUser?.id {
|
||||
if let index = client.channels[id]?.members?.index(of:userID) {
|
||||
client.channels[id]?.members?.remove(at: index)
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelLeft(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelRenamed(event: Event) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id]?.name = channel.name
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelRenamed(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelArchived(event: Event, archived: Bool) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id]?.isArchived = archived
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelArchived(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func channelHistoryChanged(event: Event) {
|
||||
if let channel = event.channel {
|
||||
//TODO: Reload chat history if there are any cached messages before latest
|
||||
|
||||
if let delegate = client.channelEventsDelegate {
|
||||
delegate.channelHistoryChanged(channel: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Do Not Disturb
|
||||
func doNotDisturbUpdated(event: Event) {
|
||||
if let dndStatus = event.dndStatus {
|
||||
client.authenticatedUser?.doNotDisturbStatus = dndStatus
|
||||
|
||||
if let delegate = client.doNotDisturbEventsDelegate {
|
||||
delegate.doNotDisturbUpdated(dndStatus: dndStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func doNotDisturbUserUpdated(event: Event) {
|
||||
if let dndStatus = event.dndStatus, user = event.user, id = user.id {
|
||||
client.users[id]?.doNotDisturbStatus = dndStatus
|
||||
|
||||
if let delegate = client.doNotDisturbEventsDelegate {
|
||||
delegate.doNotDisturbUserUpdated(dndStatus: dndStatus, user: user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - IM & Group Open/Close
|
||||
func open(event: Event, open: Bool) {
|
||||
if let channel = event.channel, id = channel.id {
|
||||
client.channels[id]?.isOpen = open
|
||||
|
||||
if let delegate = client.groupEventsDelegate {
|
||||
delegate.groupOpened(group: channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Files
|
||||
func processFile(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
if let comment = file.initialComment, commentID = comment.id {
|
||||
if client.files[id]?.comments[commentID] == nil {
|
||||
client.files[id]?.comments[commentID] = comment
|
||||
}
|
||||
}
|
||||
|
||||
client.files[id] = file
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileProcessed(file: file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func filePrivate(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
client.files[id]?.isPublic = false
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileMadePrivate(file: file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteFile(event: Event) {
|
||||
if let file = event.file, id = file.id {
|
||||
if client.files[id] != nil {
|
||||
client.files.removeValue(forKey:id)
|
||||
}
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileDeleted(file: file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentAdded(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
client.files[id]?.comments[commentID] = comment
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileCommentAdded(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentEdited(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
client.files[id]?.comments[commentID]?.comment = comment.comment
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileCommentEdited(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fileCommentDeleted(event: Event) {
|
||||
if let file = event.file, id = file.id, comment = event.comment, commentID = comment.id {
|
||||
client.files[id]?.comments.removeValue(forKey:commentID)
|
||||
|
||||
if let delegate = client.fileEventsDelegate {
|
||||
delegate.fileCommentDeleted(file: file, comment: comment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Pins
|
||||
func pinAdded(event: Event) {
|
||||
if let id = event.channelID, item = event.item {
|
||||
client.channels[id]?.pinnedItems.append(item)
|
||||
|
||||
if let delegate = client.pinEventsDelegate {
|
||||
delegate.itemPinned(item: item, channel: client.channels[id])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pinRemoved(event: Event) {
|
||||
if let id = event.channelID {
|
||||
if let pins = client.channels[id]?.pinnedItems.filter({$0 != event.item}) {
|
||||
client.channels[id]?.pinnedItems = pins
|
||||
}
|
||||
|
||||
if let delegate = client.pinEventsDelegate {
|
||||
delegate.itemUnpinned(item: event.item, channel: client.channels[id])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Stars
|
||||
func itemStarred(event: Event, star: Bool) {
|
||||
if let item = event.item, type = item.type {
|
||||
switch type {
|
||||
case "message":
|
||||
starMessage(item: item, star: star)
|
||||
case "file":
|
||||
starFile(item: item, star: star)
|
||||
case "file_comment":
|
||||
starComment(item: item)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let delegate = client.starEventsDelegate {
|
||||
delegate.itemStarred(item: item, star: star)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starMessage(item: Item, star: Bool) {
|
||||
if let message = item.message, ts = message.ts, channel = item.channel {
|
||||
if let _ = client.channels[channel]?.messages[ts] {
|
||||
client.channels[channel]?.messages[ts]?.isStarred = star
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starFile(item: Item, star: Bool) {
|
||||
if let file = item.file, id = file.id {
|
||||
client.files[id]?.isStarred = star
|
||||
if let stars = client.files[id]?.stars {
|
||||
if star == true {
|
||||
client.files[id]?.stars = stars + 1
|
||||
} else {
|
||||
if stars > 0 {
|
||||
client.files[id]?.stars = stars - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func starComment(item: Item) {
|
||||
if let file = item.file, id = file.id, comment = item.comment, commentID = comment.id {
|
||||
client.files[id]?.comments[commentID] = comment
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Reactions
|
||||
func addedReaction(event: Event) {
|
||||
if let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id {
|
||||
switch type {
|
||||
case "message":
|
||||
if let channel = item.channel, ts = item.ts {
|
||||
if let message = client.channels[channel]?.messages[ts] {
|
||||
if (message.reactions[key]) == nil {
|
||||
message.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
message.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
}
|
||||
case "file":
|
||||
if let id = item.file?.id, file = client.files[id] {
|
||||
if file.reactions[key] == nil {
|
||||
client.files[id]?.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
client.files[id]?.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
case "file_comment":
|
||||
if let id = item.file?.id, file = client.files[id], commentID = item.fileCommentID {
|
||||
if file.comments[commentID]?.reactions[key] == nil {
|
||||
client.files[id]?.comments[commentID]?.reactions[key] = Reaction(name: event.reaction, user: userID)
|
||||
} else {
|
||||
client.files[id]?.comments[commentID]?.reactions[key]?.users[userID] = userID
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let delegate = client.reactionEventsDelegate {
|
||||
delegate.reactionAdded(reaction: event.reaction, item: event.item, itemUser: event.itemUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removedReaction(event: Event) {
|
||||
if let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id {
|
||||
switch type {
|
||||
case "message":
|
||||
if let channel = item.channel, ts = item.ts {
|
||||
if let message = client.channels[channel]?.messages[ts] {
|
||||
if (message.reactions[key]) != nil {
|
||||
message.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if (message.reactions[key]?.users.count == 0) {
|
||||
message.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "file":
|
||||
if let itemFile = item.file, id = itemFile.id, file = client.files[id] {
|
||||
if file.reactions[key] != nil {
|
||||
client.files[id]?.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if client.files[id]?.reactions[key]?.users.count == 0 {
|
||||
client.files[id]?.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
case "file_comment":
|
||||
if let id = item.file?.id, file = client.files[id], commentID = item.fileCommentID {
|
||||
if file.comments[commentID]?.reactions[key] != nil {
|
||||
client.files[id]?.comments[commentID]?.reactions[key]?.users.removeValue(forKey:userID)
|
||||
}
|
||||
if client.files[id]?.comments[commentID]?.reactions[key]?.users.count == 0 {
|
||||
client.files[id]?.comments[commentID]?.reactions.removeValue(forKey:key)
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if let delegate = client.reactionEventsDelegate {
|
||||
delegate.reactionAdded(reaction: event.reaction, item: event.item, itemUser: event.itemUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Preferences
|
||||
func changePreference(event: Event) {
|
||||
if let name = event.name {
|
||||
client.authenticatedUser?.preferences?[name] = event.value
|
||||
|
||||
if let delegate = client.slackEventsDelegate, value = event.value {
|
||||
delegate.preferenceChanged(preference: name, value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Mark: - User Change
|
||||
func userChange(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
let preferences = client.users[id]?.preferences
|
||||
client.users[id] = user
|
||||
client.users[id]?.preferences = preferences
|
||||
|
||||
if let delegate = client.slackEventsDelegate {
|
||||
delegate.userChanged(user: user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - User Presence
|
||||
func presenceChange(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
client.users[id]?.presence = event.presence
|
||||
|
||||
if let delegate = client.slackEventsDelegate {
|
||||
delegate.presenceChanged(user: user, presence: event.presence)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Team
|
||||
func teamJoin(event: Event) {
|
||||
if let user = event.user, id = user.id {
|
||||
client.users[id] = user
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamJoined(user: user)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func teamPlanChange(event: Event) {
|
||||
if let plan = event.plan {
|
||||
client.team?.plan = plan
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamPlanChanged(plan: plan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func teamPreferenceChange(event: Event) {
|
||||
if let name = event.name {
|
||||
client.team?.prefs?[name] = event.value
|
||||
|
||||
if let delegate = client.teamEventsDelegate, value = event.value {
|
||||
delegate.teamPreferencesChanged(preference: name, value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func teamNameChange(event: Event) {
|
||||
if let name = event.name {
|
||||
client.team?.name = name
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamNameChanged(name: name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func teamDomainChange(event: Event) {
|
||||
if let domain = event.domain {
|
||||
client.team?.domain = domain
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamDomainChanged(domain: domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func emailDomainChange(event: Event) {
|
||||
if let domain = event.emailDomain {
|
||||
client.team?.emailDomain = domain
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamEmailDomainChanged(domain: domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func emojiChanged(event: Event) {
|
||||
//TODO: Call emoji.list here
|
||||
|
||||
if let delegate = client.teamEventsDelegate {
|
||||
delegate.teamEmojiChanged()
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Bots
|
||||
func bot(event: Event) {
|
||||
if let bot = event.bot, id = bot.id {
|
||||
client.bots[id] = bot
|
||||
|
||||
if let delegate = client.slackEventsDelegate {
|
||||
delegate.botEvent(bot: bot)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Subteams
|
||||
func subteam(event: Event) {
|
||||
if let subteam = event.subteam, id = subteam.id {
|
||||
client.userGroups[id] = subteam
|
||||
|
||||
if let delegate = client.subteamEventsDelegate {
|
||||
delegate.subteamEvent(userGroup: subteam)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func subteamAddedSelf(event: Event) {
|
||||
if let subteamID = event.subteamID, _ = client.authenticatedUser?.userGroups {
|
||||
client.authenticatedUser?.userGroups![subteamID] = subteamID
|
||||
|
||||
if let delegate = client.subteamEventsDelegate {
|
||||
delegate.subteamSelfAdded(subteamID: subteamID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func subteamRemovedSelf(event: Event) {
|
||||
if let subteamID = event.subteamID {
|
||||
client.authenticatedUser?.userGroups?.removeValue(forKey:subteamID)
|
||||
|
||||
if let delegate = client.subteamEventsDelegate {
|
||||
delegate.subteamSelfRemoved(subteamID: subteamID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Team Profiles
|
||||
func teamProfileChange(event: Event) {
|
||||
for user in client.users {
|
||||
if let fields = event.profile?.fields {
|
||||
for key in fields.keys {
|
||||
client.users[user.0]?.profile?.customProfile?.fields[key]?.updateProfileField(profile: fields[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let delegate = client.teamProfileEventsDelegate {
|
||||
delegate.teamProfileChanged(profile: event.profile)
|
||||
}
|
||||
}
|
||||
|
||||
func teamProfileDeleted(event: Event) {
|
||||
for user in client.users {
|
||||
if let id = event.profile?.fields.first?.0 {
|
||||
client.users[user.0]?.profile?.customProfile?.fields[id] = nil
|
||||
}
|
||||
}
|
||||
|
||||
if let delegate = client.teamProfileEventsDelegate {
|
||||
delegate.teamProfileDeleted(profile: event.profile)
|
||||
}
|
||||
}
|
||||
|
||||
func teamProfileReordered(event: Event) {
|
||||
for user in client.users {
|
||||
if let keys = event.profile?.fields.keys {
|
||||
for key in keys {
|
||||
client.users[user.0]?.profile?.customProfile?.fields[key]?.ordering = event.profile?.fields[key]?.ordering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let delegate = client.teamProfileEventsDelegate {
|
||||
delegate.teamProfileReordered(profile: event.profile)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Authenticated User
|
||||
func manualPresenceChange(event: Event) {
|
||||
client.authenticatedUser?.presence = event.presence
|
||||
|
||||
if let delegate = client.slackEventsDelegate {
|
||||
delegate.manualPresenceChanged(user: client.authenticatedUser, presence: event.presence)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// ClientExtensions.swift
|
||||
// Extensions.swift
|
||||
//
|
||||
// Copyright © 2016 Peter Zignego. All rights reserved.
|
||||
//
|
||||
@@ -28,43 +28,6 @@ import C7
|
||||
import Darwin.C
|
||||
#endif
|
||||
|
||||
extension SlackClient {
|
||||
|
||||
//MARK: - User & Channel
|
||||
public func getChannelIDByName(name: String) -> String? {
|
||||
return channels.filter{$0.1.name == stripString(string: name)}.first?.0
|
||||
}
|
||||
|
||||
public func getUserIDByName(name: String) -> String? {
|
||||
return users.filter{$0.1.name == stripString(string: name)}.first?.0
|
||||
}
|
||||
|
||||
public func getImIDForUserWithID(id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) {
|
||||
let ims = channels.filter{$0.1.isIM == true}
|
||||
let channel = ims.filter{$0.1.user == id}.first
|
||||
if let channel = channel {
|
||||
success(imID: channel.0)
|
||||
} else {
|
||||
webAPI.openIM(userID: id, success: success, failure: failure)
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Utilities
|
||||
internal func stripString(string: String) -> String? {
|
||||
var strippedString = string
|
||||
if string[string.startIndex] == "@" || string[string.startIndex] == "#" {
|
||||
strippedString.characters.remove(at: string.startIndex.advanced(by:1))
|
||||
}
|
||||
return strippedString
|
||||
}
|
||||
}
|
||||
|
||||
public enum AttachmentColor: String {
|
||||
case Good = "good"
|
||||
case Warning = "warning"
|
||||
case Danger = "danger"
|
||||
}
|
||||
|
||||
public typealias Time=Double
|
||||
|
||||
public extension Double {
|
||||
@@ -99,7 +99,7 @@ public struct File {
|
||||
stars = file?["num_stars"] as? Int
|
||||
isStarred = file?["is_starred"] as? Bool
|
||||
pinnedTo = file?["pinned_to"] as? [String]
|
||||
if let reactions = file?["reactions"] as? [[String: Any]] {
|
||||
if let reactions = file?["reactions"] as? [Any] {
|
||||
self.reactions = Reaction.reactionsFromArray(array: reactions)
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ public class Message {
|
||||
pinnedTo = message?["pinned_to"] as? [String]
|
||||
comment = Comment(comment: message?["comment"] as? [String: Any])
|
||||
file = File(file: message?["file"] as? [String: Any])
|
||||
reactions = messageReactions(reactions: message?["reactions"] as? [[String: Any]])
|
||||
attachments = (message?["attachments"] as? [[String: Any]])?.objectArrayFromDictionaryArray(intializer: {(attachment) -> Attachment? in
|
||||
reactions = messageReactions(reactions: message?["reactions"] as? [Any])
|
||||
attachments = (message?["attachments"] as? [Any])?.objectArrayFromDictionaryArray(intializer: {(attachment) -> Attachment? in
|
||||
return Attachment(attachment: attachment)
|
||||
})
|
||||
}
|
||||
@@ -91,11 +91,11 @@ public class Message {
|
||||
file = nil
|
||||
}
|
||||
|
||||
private func messageReactions(reactions: [[String: Any]]?) -> [String: Reaction] {
|
||||
private func messageReactions(reactions: [Any]?) -> [String: Reaction] {
|
||||
var returnValue = [String: Reaction]()
|
||||
if let r = reactions {
|
||||
for react in r {
|
||||
if let reaction = Reaction(reaction: react), reactionName = reaction.name {
|
||||
if let reaction = Reaction(reaction: react as? [String: Any]), reactionName = reaction.name {
|
||||
returnValue[reactionName] = reaction
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
import C7
|
||||
import HTTPSClient
|
||||
import Jay
|
||||
import WebSocketClient
|
||||
|
||||
internal struct NetworkInterface {
|
||||
|
||||
@@ -72,20 +73,32 @@ internal struct NetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
internal func postRequest(endpoint: SlackAPIEndpoint, token: String, parameters: [String: Any]?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) {
|
||||
let requestString = "\(apiUrl)\(endpoint.rawValue)?token=\(token)"
|
||||
internal func uploadRequest(token: String, data: Data, parameters: [String: Any]?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) {
|
||||
var requestString = "\(apiUrl)\(SlackAPIEndpoint.FilesUpload.rawValue)?token=\(token)"
|
||||
if let params = parameters {
|
||||
requestString = requestString + requestStringFromParameters(parameters: params)
|
||||
}
|
||||
|
||||
let boundaryConstant = randomBoundary()
|
||||
let boundaryStart = "--\(boundaryConstant)\r\n"
|
||||
let boundaryEnd = "--\(boundaryConstant)--\r\n"
|
||||
let contentDispositionString = "Content-Disposition: form-data; name=\"file\"; filename=\"\(parameters!["filename"])\"\r\n"
|
||||
let contentTypeString = "Content-Type: \(parameters!["filetype"])\r\n\r\n"
|
||||
|
||||
var requestBodyData = Data()
|
||||
requestBodyData.append(contentsOf: boundaryStart.data.bytes)
|
||||
requestBodyData.append(contentsOf: contentDispositionString.data.bytes)
|
||||
requestBodyData.append(contentsOf: contentTypeString.data.bytes)
|
||||
requestBodyData.append(contentsOf: data)
|
||||
requestBodyData.append(contentsOf: "\r\n".data.bytes)
|
||||
requestBodyData.append(contentsOf: boundaryEnd.data.bytes)
|
||||
|
||||
let header: Headers = ["Content-Type":"multipart/form-data; boundary=" + boundaryConstant]
|
||||
|
||||
do {
|
||||
var response: Response?
|
||||
let headers: Headers = ["Content-Type": "application/x-www-form-urlencoded"]
|
||||
var body = ""
|
||||
if let params = parameters {
|
||||
body = requestStringFromParameters(parameters: params)
|
||||
} else {
|
||||
body = ""
|
||||
}
|
||||
|
||||
response = try client?.post(requestString, headers: headers, body: body)
|
||||
|
||||
response = try client?.post(requestString, headers: header, body: requestBodyData)
|
||||
|
||||
let data = try response?.body.becomeBuffer()
|
||||
if let data = data {
|
||||
let json = try Jay().jsonFromData(data.bytes)
|
||||
@@ -101,6 +114,7 @@ internal struct NetworkInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch let error {
|
||||
if let slackError = error as? SlackError {
|
||||
errorClosure(slackError)
|
||||
@@ -110,78 +124,28 @@ internal struct NetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Currently Unsupported
|
||||
/*internal func uploadRequest(token: String, data: NSData, parameters: [String: Any]?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) {
|
||||
var requestString = "\(apiUrl)\(SlackAPIEndpoint.FilesUpload.rawValue)?token=\(token)"
|
||||
if let params = parameters {
|
||||
requestString = requestString + requestStringFromParameters(parameters: params)
|
||||
}
|
||||
|
||||
let request = NSMutableURLRequest(url: NSURL(string: requestString)!)
|
||||
request.httpMethod = "POST"
|
||||
let boundaryConstant = randomBoundary()
|
||||
let contentType = "multipart/form-data; boundary=" + boundaryConstant
|
||||
let boundaryStart = "--\(boundaryConstant)\r\n"
|
||||
let boundaryEnd = "--\(boundaryConstant)--\r\n"
|
||||
let contentDispositionString = "Content-Disposition: form-data; name=\"file\"; filename=\"\(parameters!["filename"])\"\r\n"
|
||||
let contentTypeString = "Content-Type: \(parameters!["filetype"])\r\n\r\n"
|
||||
|
||||
let requestBodyData : NSMutableData = NSMutableData()
|
||||
requestBodyData.append(boundaryStart.data(using: NSUTF8StringEncoding)!)
|
||||
requestBodyData.append(contentDispositionString.data(using: NSUTF8StringEncoding)!)
|
||||
requestBodyData.append(contentTypeString.data(using: NSUTF8StringEncoding)!)
|
||||
requestBodyData.append(data)
|
||||
requestBodyData.append("\r\n".data(using: NSUTF8StringEncoding)!)
|
||||
requestBodyData.append(boundaryEnd.data(using: NSUTF8StringEncoding)!)
|
||||
|
||||
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
|
||||
request.httpBody = requestBodyData
|
||||
|
||||
NSURLSession.shared().dataTask(with: request) {
|
||||
(data, response, internalError) -> Void in
|
||||
guard let data = data else {
|
||||
return
|
||||
}
|
||||
do {
|
||||
let result = try NSJSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
|
||||
if (result["ok"] as! Bool == true) {
|
||||
successClosure(result)
|
||||
} else {
|
||||
if let errorString = result["error"] as? String {
|
||||
throw ErrorDispatcher.dispatch(error: errorString)
|
||||
} else {
|
||||
throw SlackError.UnknownError
|
||||
}
|
||||
}
|
||||
} catch let error {
|
||||
if let slackError = error as? SlackError {
|
||||
errorClosure(slackError)
|
||||
} else {
|
||||
errorClosure(SlackError.UnknownError)
|
||||
}
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
private func randomBoundary() -> String {
|
||||
return String(format: "slackkit.boundary.%08x%08x", arc4random(), arc4random())
|
||||
}*/
|
||||
#if os(Linux)
|
||||
return "slackkit.boundary.\(Int(random()))\(Int(random()))"
|
||||
#else
|
||||
return "slackkit.boundary.\(arc4random())\(arc4random())"
|
||||
#endif
|
||||
}
|
||||
|
||||
private func requestStringFromParameters(parameters: [String: Any]) -> String {
|
||||
var requestString = ""
|
||||
for key in parameters.keys {
|
||||
if let value = parameters[key] as? String {
|
||||
#if os(Linux)
|
||||
if let encodedValue = value.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
|
||||
requestString += "&\(key)=\(encodedValue)"
|
||||
}
|
||||
#else
|
||||
if let encodedValue = value.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed()) {
|
||||
requestString += "&\(key)=\(encodedValue)"
|
||||
}
|
||||
#endif
|
||||
do {
|
||||
let encodedValue = try value.percentEncoded(allowing: .uriQueryAllowed)
|
||||
requestString += "&\(key)=\(encodedValue)"
|
||||
} catch _ {
|
||||
print("Error encoding parameters.")
|
||||
}
|
||||
} else if let value = parameters[key] as? Int {
|
||||
requestString += "&\(key)=\(value)"
|
||||
} else if let value = parameters[key] as? Bool {
|
||||
requestString += "&\(key)=\(value)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import C7
|
||||
import Jay
|
||||
|
||||
internal enum SlackAPIEndpoint: String {
|
||||
@@ -103,16 +104,22 @@ public class SlackWebAPI {
|
||||
case IM = "im"
|
||||
}
|
||||
|
||||
private let client: SlackClient
|
||||
private let networkInterface: NetworkInterface
|
||||
private let token: String
|
||||
|
||||
required public init(slackClient: SlackClient) {
|
||||
self.client = slackClient
|
||||
init(networkInterface: NetworkInterface, token: String) {
|
||||
self.networkInterface = networkInterface
|
||||
self.token = token
|
||||
}
|
||||
|
||||
convenience public init(slackClient: SlackClient) {
|
||||
self.init(networkInterface: slackClient.api, token: slackClient.token)
|
||||
}
|
||||
|
||||
//MARK: - RTM
|
||||
public func rtmStart(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((response: [String: Any])->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["simple_latest": simpleLatest, "no_unreads": noUnreads, "mpim_aware": mpimAware]
|
||||
client.api.request(endpoint: .RTMStart, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: .RTMStart, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(response: response)
|
||||
}) {(error) -> Void in
|
||||
@@ -122,7 +129,7 @@ public class SlackWebAPI {
|
||||
|
||||
//MARK: - Auth Test
|
||||
public func authenticationTest(success: ((authenticated: Bool)->Void)?, failure: FailureClosure?) {
|
||||
client.api.request(endpoint: .AuthTest, token: client.token, parameters: nil, successClosure: {
|
||||
networkInterface.request(endpoint: .AuthTest, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(authenticated: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -188,7 +195,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Messaging
|
||||
public func deleteMessage(channel: String, ts: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel": channel, "ts": ts]
|
||||
client.api.request(endpoint: .ChatDelete, token: client.token, parameters: parameters, successClosure: { (response) -> Void in
|
||||
networkInterface.request(endpoint: .ChatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
@@ -197,7 +204,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func sendMessage(channel: String, text: String, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, linkNames: Bool? = nil, attachments: [Attachment?]? = nil, unfurlLinks: Bool? = nil, unfurlMedia: Bool? = nil, iconURL: String? = nil, iconEmoji: String? = nil, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["channel":channel, "text":text.slackFormatEscaping(), "as_user":asUser, "parse":parse?.rawValue, "link_names":linkNames, "unfurl_links":unfurlLinks, "unfurlMedia":unfurlMedia, "username":username, "attachments":encodeAttachments(attachments: attachments), "icon_url":iconURL, "icon_emoji":iconEmoji]
|
||||
client.api.postRequest(endpoint: .ChatPostMessage, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: .ChatPostMessage, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?((ts: response["ts"] as? String, response["channel"] as? String))
|
||||
}) {(error) -> Void in
|
||||
@@ -207,7 +214,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func updateMessage(channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .None, linkNames: Bool = false, success: ((updated: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["channel": channel, "ts": ts, "text": message.slackFormatEscaping(), "parse": parse.rawValue, "link_names": linkNames, "attachments":encodeAttachments(attachments: attachments)]
|
||||
client.api.postRequest(endpoint: .ChatUpdate, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: .ChatUpdate, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(updated: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -218,7 +225,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Do Not Disturb
|
||||
public func dndInfo(user: String? = nil, success: ((status: DoNotDisturbStatus?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["user": user]
|
||||
client.api.request(endpoint: .DNDInfo, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: .DNDInfo, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(status: DoNotDisturbStatus(status: response))
|
||||
}) {(error) -> Void in
|
||||
@@ -228,7 +235,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func dndTeamInfo(users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus]?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["users":users?.joined(separator: ",")]
|
||||
client.api.request(endpoint: .DNDTeamInfo, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: .DNDTeamInfo, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(statuses: self.enumerateDNDStauses(statuses: response["users"] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
@@ -238,7 +245,7 @@ public class SlackWebAPI {
|
||||
|
||||
//MARK: - Emoji
|
||||
public func emojiList(success: ((emojiList: [String: Any]?)->Void)?, failure: FailureClosure?) {
|
||||
client.api.request(endpoint: .EmojiList, token: client.token, parameters: nil, successClosure: {
|
||||
networkInterface.request(endpoint: .EmojiList, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(emojiList: response["emoji"] as? [String: Any])
|
||||
}) { (error) -> Void in
|
||||
@@ -249,7 +256,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Files
|
||||
public func deleteFile(fileID: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["file":fileID]
|
||||
client.api.request(endpoint: .FilesDelete, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .FilesDelete, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -257,21 +264,20 @@ public class SlackWebAPI {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Currently Unsupported
|
||||
/*public func uploadFile(file: NSData, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((file: File?)->Void)?, failure: FailureClosure?) {
|
||||
public func uploadFile(file: Data, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((file: File?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["file":file, "filename": filename, "filetype":filetype, "title":title, "initial_comment":initialComment, "channels":channels?.joined(separator: ",")]
|
||||
client.api.uploadRequest(token: client.token, data: file, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.uploadRequest(token: token, data: file, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(file: File(file: response["file"] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
failure?(error: error)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//MARK: - File Comments
|
||||
public func addFileComment(fileID: String, comment: String, success: ((comment: Comment?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["file":fileID, "comment":comment.slackFormatEscaping()]
|
||||
client.api.request(endpoint: .FilesCommentsAdd, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .FilesCommentsAdd, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(comment: Comment(comment: response["comment"] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
@@ -281,7 +287,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func editFileComment(fileID: String, commentID: String, comment: String, success: ((comment: Comment?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["file":fileID, "id":commentID, "comment":comment.slackFormatEscaping()]
|
||||
client.api.request(endpoint: .FilesCommentsEdit, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .FilesCommentsEdit, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(comment: Comment(comment: response["comment"] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
@@ -291,7 +297,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func deleteFileComment(fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["file":fileID, "id": commentID]
|
||||
client.api.request(endpoint: .FilesCommentsDelete, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .FilesCommentsDelete, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(deleted: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -347,7 +353,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func openGroup(channel: String, success: ((opened: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel":channel]
|
||||
client.api.request(endpoint: .GroupsOpen, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .GroupsOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(opened: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -412,7 +418,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func openIM(userID: String, success: ((imID: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["user":userID]
|
||||
client.api.request(endpoint: .IMOpen, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .IMOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
let group = response["channel"] as? [String: Any]
|
||||
success?(imID: group?["id"] as? String)
|
||||
@@ -460,7 +466,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func openMPIM(userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["users":userIDs.joined(separator: ",")]
|
||||
client.api.request(endpoint: .MPIMOpen, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .MPIMOpen, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
let group = response["group"] as? [String: Any]
|
||||
success?(mpimID: group?["id"] as? String)
|
||||
@@ -490,7 +496,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func pin(endpoint: SlackAPIEndpoint, channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["channel":channel, "file":file, "file_comment":fileComment, "timestamp":timestamp]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}){(error) -> Void in
|
||||
@@ -521,7 +527,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func react(endpoint: SlackAPIEndpoint, name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["name":name, "file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -552,7 +558,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func star(endpoint: SlackAPIEndpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any?] = ["file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: filterNilParameters(parameters: parameters), successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ok: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -563,7 +569,7 @@ public class SlackWebAPI {
|
||||
|
||||
//MARK: - Team
|
||||
public func teamInfo(success: ((info: [String: Any]?)->Void)?, failure: FailureClosure?) {
|
||||
client.api.request(endpoint: .TeamInfo, token: client.token, parameters: nil, successClosure: {
|
||||
networkInterface.request(endpoint: .TeamInfo, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(info: response["team"] as? [String: Any])
|
||||
}) {(error) -> Void in
|
||||
@@ -574,7 +580,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Users
|
||||
public func userPresence(user: String, success: ((presence: String?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["user":user]
|
||||
client.api.request(endpoint: .UsersGetPresence, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .UsersGetPresence, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(presence: response["presence"] as? String)
|
||||
}){(error) -> Void in
|
||||
@@ -584,7 +590,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func userInfo(id: String, success: ((user: User?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["user":id]
|
||||
client.api.request(endpoint: .UsersInfo, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .UsersInfo, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(user: User(user: response["user"] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
@@ -594,7 +600,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func usersList(includePresence: Bool = false, success: ((userList: [String: Any]?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["presence":includePresence]
|
||||
client.api.request(endpoint: .UsersList, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .UsersList, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(userList: response["members"] as? [String: Any])
|
||||
}){(error) -> Void in
|
||||
@@ -603,7 +609,7 @@ public class SlackWebAPI {
|
||||
}
|
||||
|
||||
public func setUserActive(success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
client.api.request(endpoint: .UsersSetActive, token: client.token, parameters: nil, successClosure: {
|
||||
networkInterface.request(endpoint: .UsersSetActive, token: token, parameters: nil, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -613,7 +619,7 @@ public class SlackWebAPI {
|
||||
|
||||
public func setUserPresence(presence: Presence, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["presence":presence.rawValue]
|
||||
client.api.request(endpoint: .UsersSetPresence, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: .UsersSetPresence, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success:true)
|
||||
}) {(error) -> Void in
|
||||
@@ -624,7 +630,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Channel Utilities
|
||||
private func close(endpoint: SlackAPIEndpoint, channelID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel":channelID]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(closed: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -634,7 +640,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func history(endpoint: SlackAPIEndpoint, id: String, latest: String = "\(Time.slackTimestamp())", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel": id, "latest": latest, "oldest": oldest, "inclusive":inclusive, "count":count, "unreads":unreads]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(history: History(history: response))
|
||||
}) {(error) -> Void in
|
||||
@@ -644,7 +650,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func info(endpoint: SlackAPIEndpoint, type: ChannelType, id: String, success: ((channel: Channel?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel": id]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(channel: Channel(channel: response[type.rawValue] as? [String: Any]))
|
||||
}) {(error) -> Void in
|
||||
@@ -654,7 +660,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func list(endpoint: SlackAPIEndpoint, type: ChannelType, excludeArchived: Bool = false, success: ((channels: [Any]?)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["exclude_archived": excludeArchived]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(channels: response[type.rawValue+"s"] as? [Any])
|
||||
}) {(error) -> Void in
|
||||
@@ -664,7 +670,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func mark(endpoint: SlackAPIEndpoint, channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel": channel, "ts": timestamp]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(ts: timestamp)
|
||||
}) {(error) -> Void in
|
||||
@@ -674,7 +680,7 @@ public class SlackWebAPI {
|
||||
|
||||
private func setInfo(endpoint: SlackAPIEndpoint, type: InfoType, channel: String, text: String, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
|
||||
let parameters: [String: Any] = ["channel": channel, type.rawValue: text]
|
||||
client.api.request(endpoint: endpoint, token: client.token, parameters: parameters, successClosure: {
|
||||
networkInterface.request(endpoint: endpoint, token: token, parameters: parameters, successClosure: {
|
||||
(response) -> Void in
|
||||
success?(success: true)
|
||||
}) {(error) -> Void in
|
||||
@@ -696,7 +702,7 @@ public class SlackWebAPI {
|
||||
//MARK: - Encode Attachments
|
||||
private func encodeAttachments(attachments: [Attachment?]?) -> String? {
|
||||
if let attachments = attachments {
|
||||
var attachmentArray: [[String: Any]] = []
|
||||
var attachmentArray: [Any] = []
|
||||
for attachment in attachments {
|
||||
if let attachment = attachment {
|
||||
attachmentArray.append(attachment.dictionary())
|
||||
|
||||
@@ -73,17 +73,19 @@ public struct Reaction {
|
||||
self.users = users
|
||||
}
|
||||
|
||||
static func reactionsFromArray(array: [[String: Any]]) -> [String: Reaction] {
|
||||
static func reactionsFromArray(array: [Any]) -> [String: Reaction] {
|
||||
var reactions = [String: Reaction]()
|
||||
var userDictionary = [String: String]()
|
||||
for reaction in array {
|
||||
if let users = reaction["users"] as? [String] {
|
||||
for user in users {
|
||||
userDictionary[user] = user
|
||||
for r in array {
|
||||
if let reaction = r as? [String: Any] {
|
||||
if let users = reaction["users"] as? [String] {
|
||||
for user in users {
|
||||
userDictionary[user] = user
|
||||
}
|
||||
}
|
||||
if let name = reaction["name"] as? String {
|
||||
reactions[name] = Reaction(name: name, users: userDictionary)
|
||||
}
|
||||
}
|
||||
if let name = reaction["name"] as? String {
|
||||
reactions[name] = Reaction(name: name, users: userDictionary)
|
||||
}
|
||||
}
|
||||
return reactions
|
||||
|
||||
Reference in New Issue
Block a user