<commit_before>//
//  NotificationsViewController.swift
//  Justaway
//
//  Created by <NAME> on 1/25/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation
import KeyClip
import Async

class NotificationsViewController: StatusTableViewController {

    override func saveCache() {
        if self.adapter.rows.count > 0 {
            guard let account = AccountSettingsStore.get()?.account() else {
                return
            }
            let key = "notifications:\(account.userID)"
            let statuses = self.adapter.statuses
            let dictionary = ["statuses": ( statuses.count > 100 ? Array(statuses[0 ..< 100]) : statuses ).map({ $0.dictionaryValue })]
            KeyClip.save(key, dictionary: dictionary)
            NSLog("notifications saveCache.")
        }
    }

    override func loadCache(success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        adapter.activityMode = true
        Async.background {
            guard let account = AccountSettingsStore.get()?.account() else {
                return
            }
            let key = "notifications:\(account.userID)"
            if let cache = KeyClip.load(key) as NSDictionary? {
                if let statuses = cache["statuses"] as? [[String: AnyObject]] {
                    success(statuses: statuses.map({ TwitterStatus($0) }))
                    return
                }
            }
            success(statuses: [TwitterStatus]())

            Async.background(after: 0.4, block: { () -> Void in
                self.loadData(nil)
            })
        }
    }

    override func loadData(maxID: String?, success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        // Twitter.getMentionTimeline(maxID: maxID, success: success, failure: failure)
        Twitter.getActivity(maxID: maxID, success: success, failure: failure)
    }

    override func loadData(sinceID sinceID: String?, maxID: String?, success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        // Twitter.getMentionTimeline(sinceID: sinceID, maxID: maxID, success: success, failure: failure)
        Twitter.getActivity(sinceID: sinceID, maxID: maxID, success: success, failure: failure)
    }

    override func accept(status: TwitterStatus) -> Bool {

        if let event = status.event {
            if let accountSettings = AccountSettingsStore.get() {
                if let actionedBy = status.actionedBy {
                    if accountSettings.isMe(actionedBy.userID) {
                        return false
                    }<commit_msg>Alternative API for Notification tab<commit_after>//
//  NotificationsViewController.swift
//  Justaway
//
//  Created by <NAME> on 1/25/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation
import KeyClip
import Async

class NotificationsViewController: StatusTableViewController {

    override func saveCache() {
        if self.adapter.rows.count > 0 {
            guard let account = AccountSettingsStore.get()?.account() else {
                return
            }
            let key = "notifications:\(account.userID)"
            let statuses = self.adapter.statuses
            let dictionary = ["statuses": ( statuses.count > 100 ? Array(statuses[0 ..< 100]) : statuses ).map({ $0.dictionaryValue })]
            KeyClip.save(key, dictionary: dictionary)
            NSLog("notifications saveCache.")
        }
    }

    override func loadCache(success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        adapter.activityMode = true
        Async.background {
            guard let account = AccountSettingsStore.get()?.account() else {
                return
            }
            let key = "notifications:\(account.userID)"
            if let cache = KeyClip.load(key) as NSDictionary? {
                if let statuses = cache["statuses"] as? [[String: AnyObject]] {
                    success(statuses: statuses.map({ TwitterStatus($0) }))
                    return
                }
            }
            success(statuses: [TwitterStatus]())

            Async.background(after: 0.4, block: { () -> Void in
                self.loadData(nil)
            })
        }
    }

    override func loadData(maxID: String?, success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        guard let account = AccountSettingsStore.get()?.account() else {
            return
        }
        if account.exToken.isEmpty {
            Twitter.getMentionTimeline(maxID: maxID, success: success, failure: failure)
        } else {
            Twitter.getActivity(maxID: maxID, success: success, failure: failure)
        }
    }

    override func loadData(sinceID sinceID: String?, maxID: String?, success: ((statuses: [TwitterStatus]) -> Void), failure: ((error: NSError) -> Void)) {
        guard let account = AccountSettingsStore.get()?.account() else {
            return
        }
        if account.exToken.isEmpty {
            Twitter.getMentionTimeline(sinceID: sinceID, maxID: maxID, success: success, failure: failure)
        } else {
            Twitter.getActivity(sinceID: sinceID, maxID: maxID, success: success, failure: failure)
        }
    }

    override func accept(status: TwitterStatus) -> Bool {

        if let event = status.event {
            if let accountSettings = AccountSettingsStore.get() {
                if let actionedBy = status.actionedBy {
                    if accountSettings.isMe(actionedBy.userID) {
                        return false
                    }
{'fraction_non_alphanumeric': 0.1166283795723626, 'fraction_numerical': 0.0074218059727867115, 'mean_word_length': 2.097974822112753, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 27, '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': '120785', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1462, 'n_words': 382}