<commit_before>//
//  ChatDataController.swift
//  Rocket.Chat
//
//  Created by <NAME> on 09/12/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation

enum ChatDataType {
    case daySeparator
    case unreadSeparator
    case message
    case loader
    case header
}

struct ChatData {
    var identifier = String.random(10)
    var type: ChatDataType = .message
    var timestamp: Date
    var indexPath: IndexPath!
    var height: CGFloat?

    // This is only used for messages
    var message: Message?

    // Initializers
    init(type: ChatDataType, timestamp: Date) {
        self.type = type
        self.timestamp = timestamp
    }
}

final class ChatDataController {
    var messagesUsernames: Set<String> = []

    var dataCellHeight: [String: CGFloat] = [:]
    var data: [ChatData] = [] {
        didSet {
            messagesUsernames.removeAll()
            messagesUsernames.formUnion(data.compactMap { $0.message?.user?.username })
        }
    }

    var loadedAllMessages = false
    lazy var lastSeen: Date = {
        return Date()
    }()
    var unreadSeparator = false
    var dismissUnreadSeparator = false

    @discardableResult
    func clear() -> [IndexPath] {
        var indexPaths: [IndexPath] = []

        for item in data {
            indexPaths.append(item.indexPath)
        }

        data = []
        return indexPaths
    }

    func cacheCellHeight(for identifier: String, value: CGFloat) {
        dataCellHeight[identifier] = value
    }<commit_msg>Fix object invalidated crash when setting ChatDataController.data property<commit_after>//
//  ChatDataController.swift
//  Rocket.Chat
//
//  Created by <NAME> on 09/12/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation

enum ChatDataType {
    case daySeparator
    case unreadSeparator
    case message
    case loader
    case header
}

struct ChatData {
    var identifier = String.random(10)
    var type: ChatDataType = .message
    var timestamp: Date
    var indexPath: IndexPath!
    var height: CGFloat?

    // This is only used for messages
    var message: Message?

    // Initializers
    init(type: ChatDataType, timestamp: Date) {
        self.type = type
        self.timestamp = timestamp
    }
}

final class ChatDataController {
    var messagesUsernames: Set<String> = []

    var dataCellHeight: [String: CGFloat] = [:]
    var data: [ChatData] = [] {
        didSet {
            messagesUsernames.removeAll()
            messagesUsernames.formUnion(data.compactMap { $0.message?.validated()?.user?.validated()?.username })
        }
    }

    var loadedAllMessages = false
    lazy var lastSeen: Date = {
        return Date()
    }()
    var unreadSeparator = false
    var dismissUnreadSeparator = false

    @discardableResult
    func clear() -> [IndexPath] {
        var indexPaths: [IndexPath] = []

        for item in data {
            indexPaths.append(item.indexPath)
        }

        data = []
        return indexPaths
    }

    func cacheCellHeight(for identifier: String, value: CGFloat) {
        dataCellHeight[identifier] = value
    }
{'fraction_non_alphanumeric': 0.0958904109589041, 'fraction_numerical': 0.00828289264096846, 'mean_word_length': 2.351120597652081, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5522079', 'n_tokens_mistral': 927, 'n_tokens_neox': 907, 'n_words': 247}