<commit_before>//
//  MessageManager.swift
//  Rocket.Chat
//
//  Created by <NAME> on 7/14/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation
import RealmSwift

public typealias MessagesHistoryCompletion = (Date?) -> Void

struct MessageManager {
    static let historySize = 60
}

let kBlockedUsersIndentifiers = "kBlockedUsersIndentifiers"

extension MessageManager {

    static var blockedUsersList = UserDefaults.group.value(forKey: kBlockedUsersIndentifiers) as? [String] ?? []

    static func getHistory(_ subscription: UnmanagedSubscription, lastMessageDate: Date?, completion: @escaping MessagesHistoryCompletion) {
        var lastDate: Any!

        if let lastMessageDate = lastMessageDate {
            lastDate = ["$date": lastMessageDate.timeIntervalSince1970 * 1000]
        } else {
            lastDate = NSNull()
        }

        let request = [
            "msg": "method",
            "method": "loadHistory",
            "params": ["\(subscription.rid)", lastDate, historySize]
        ] as [String: Any]

        var lastMessageDate: Date?

        let currentRealm = Realm.current
        SocketManager.send(request) { response in
            guard !response.isError() else {
                return Log.debug(response.result.string)
            }<commit_msg>Request only 30 new messages to the API<commit_after>//
//  MessageManager.swift
//  Rocket.Chat
//
//  Created by <NAME> on 7/14/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation
import RealmSwift

public typealias MessagesHistoryCompletion = (Date?) -> Void

struct MessageManager {
    static let historySize = 30
}

let kBlockedUsersIndentifiers = "kBlockedUsersIndentifiers"

extension MessageManager {

    static var blockedUsersList = UserDefaults.group.value(forKey: kBlockedUsersIndentifiers) as? [String] ?? []

    static func getHistory(_ subscription: UnmanagedSubscription, lastMessageDate: Date?, completion: @escaping MessagesHistoryCompletion) {
        var lastDate: Any!

        if let lastMessageDate = lastMessageDate {
            lastDate = ["$date": lastMessageDate.timeIntervalSince1970 * 1000]
        } else {
            lastDate = NSNull()
        }

        let request = [
            "msg": "method",
            "method": "loadHistory",
            "params": ["\(subscription.rid)", lastDate, historySize]
        ] as [String: Any]

        var lastMessageDate: Date?

        let currentRealm = Realm.current
        SocketManager.send(request) { response in
            guard !response.isError() else {
                return Log.debug(response.result.string)
            }
{'fraction_non_alphanumeric': 0.1000752445447705, 'fraction_numerical': 0.015048908954100828, 'mean_word_length': 2.682825484764543, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 7, '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': '4440212', 'n_tokens_mistral': 770, 'n_tokens_neox': 710, 'n_words': 193}