<commit_before>//
//  SocketHandlers.swift
//  Rocket.Chat
//
//  Created by <NAME> on 8/17/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation
import Starscream
import RealmSwift
import SwiftyJSON
import Bugsnag

extension SocketManager {

    func handleMessage(_ response: JSON, socket: WebSocket) {
        guard let result = SocketResponse(response, socket: socket) else { return }

        guard result.msg != nil else {
            return Log.debug("Msg is invalid: \(result.result)")
        }

        guard !result.isError() else {
            return handleError(result, socket: socket)
        }

        switch result.msg {
            case .some(.Connected): return handleConnectionMessage(result, socket: socket)
            case .some(.Ping): return handlePingMessage(result, socket: socket)
            case .some(.Changed), .some(.Added), .some(.Removed): return handleModelUpdates(result, socket: socket)
            case .some(.Error), .some(.Updated), .some(.Unknown): fallthrough
            default: break
        }

        // Call completion block
        guard let identifier = result.id,
              let completion = queue[identifier] else { return }
        let messageCompletion = completion as MessageCompletion<commit_msg>Clean up switch statement<commit_after>//
//  SocketHandlers.swift
//  Rocket.Chat
//
//  Created by <NAME> on 8/17/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation
import Starscream
import RealmSwift
import SwiftyJSON
import Bugsnag

extension SocketManager {

    func handleMessage(_ response: JSON, socket: WebSocket) {
        guard let result = SocketResponse(response, socket: socket) else { return }

        guard !result.isError() else {
            return handleError(result, socket: socket)
        }

        guard let message = result.msg else {
            return Log.debug("Msg is invalid: \(result.result)")
        }

        switch message {
            case .Connected: return handleConnectionMessage(result, socket: socket)
            case .Ping: return handlePingMessage(result, socket: socket)
            case .Changed, .Added, .Removed: return handleModelUpdates(result, socket: socket)
            case .Error, .Updated, .Unknown: break
        }

        // Call completion block
        guard let identifier = result.id,
              let completion = queue[identifier] else { return }
        let messageCompletion = completion as MessageCompletion
{'fraction_non_alphanumeric': 0.09667067789811472, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 2.492997198879552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3311994', 'n_tokens_mistral': 675, 'n_tokens_neox': 636, 'n_words': 207}