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

Commit

Permalink
Fix crash on set_activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Azoy committed Dec 28, 2017
1 parent fa8ea90 commit b7faa9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
21 changes: 11 additions & 10 deletions Sources/SwordRPC/RPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ extension SwordRPC {
}

func handleEvent(_ data: [String: Any]) {
guard let event = Event(rawValue: data["evt"] as! String) else {
guard let evt = data["evt"] as? String,
let event = Event(rawValue: evt) else {
return
}

Expand Down Expand Up @@ -195,15 +196,15 @@ extension SwordRPC {
self.presence = nil

let json = """
{
"cmd": "SET_ACTIVITY",
"args": {
"pid": \(self.pid),
"activity": \(String(data: try! self.encoder.encode(presence), encoding: .utf8)!)
},
"nonce": "\(UUID().uuidString)"
}
"""
{
"cmd": "SET_ACTIVITY",
"args": {
"pid": \(self.pid),
"activity": \(String(data: try! self.encoder.encode(presence), encoding: .utf8)!)
},
"nonce": "\(UUID().uuidString)"
}
"""

try? self.send(json, .frame)
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwordRPC/SwordRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public class SwordRPC {

public func reply(to request: JoinRequest, with reply: JoinReply) {
let json = """
{
"cmd": "\(
reply == .yes ? "SEND_ACTIVITY_JOIN_INVITE" : "CLOSE_ACTIVITY_JOIN_REQUEST"
)",
"args": {
"user_id": "\(request.userId)"
}
}
"""
{
"cmd": "\(
reply == .yes ? "SEND_ACTIVITY_JOIN_INVITE" : "CLOSE_ACTIVITY_JOIN_REQUEST"
)",
"args": {
"user_id": "\(request.userId)"
}
}
"""

try? self.send(json, .frame)
}
Expand Down

0 comments on commit b7faa9b

Please sign in to comment.