{"size": 4240, "ext": "js", "max_stars_repo_path": "digsby/src/plugins/twitter/res/app.js", "max_stars_repo_name": "ifwe/digsby", "max_stars_repo_stars_event_min_datetime": "2015-08-15T14:32:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T16:21:26.000Z", "max_issues_repo_path": "digsby/src/plugins/twitter/res/app.js", "max_issues_repo_name": "niterain/digsby", "max_issues_repo_issues_event_min_datetime": "2015-09-12T10:42:57.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-27T04:05:51.000Z", "max_forks_repo_path": "digsby/src/plugins/twitter/res/app.js", "max_forks_repo_name": "niterain/digsby", "max_forks_repo_forks_event_min_datetime": "2015-07-10T23:58:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T22:16:33.000Z"}
{"max_stars_count": 35, "max_issues_count": 4, "max_forks_count": 15, "avg_line_length": 25.3892215569, "max_line_length": 114, "alphanum_fraction": 0.6603773585}

timelineWindows = [];

var defaultSettings = {
    show_real_names: false,
    frame_focus_unread: true,
    autoscroll_when_at_bottom: true,
    user_feeds: false,
};

var settings = $.extend(true, {}, defaultSettings);

verbose = false;

function openWindow(feedName) {
    window.feedToOpen = feedName;
    var windowOptions = 'status=0,toolbar=0,width=400,height=800';
    var win = window.open((window.resdir ? window.resdir : '')+ '/feed.html', 'mywindow', windowOptions);

    if (win) {
        console.log('feed window opened successfully: ' + win);
        timelineWindows.push(win);
    } else
        console.error('could not open window');
}

function update() {
    window.account.forceUpdate();
}

function getPrefs(opts) {
    opts.success({user: settings, defaults: defaultSettings});
}

var addFeed = function(opts) { window.account.addFeed(opts.feed || opts.group); }
var addGroup = addFeed;

var favorite = function(opts) {
    window.account.favorite(opts.tweet,
                            function(tweet){opts.success('win_favorite');},
                            function(error_obj){opts.error('fail_favorite');}
    );
}

var deleteTweet = function(opts) {
    window.account.deleteTweet({id: opts.tweet.id,
                                success: function(tweet){opts.success('win_delete');},
                                error: function(error_obj){opts.error('fail_delete');}
    });
}

function editFeed(opts) {
    window.account.editFeed(opts.feed);
}

function setFeeds(opts) {
    window.account.setFeeds(opts.feeds);
}

function markAsRead(opts) {
    var tweet = window.account.tweets[opts.tweet_id];
    if (tweet) window.account.markAsRead(tweet);
}

function inviteFollowers() {
    window.account.inviteFollowers();
}

function markFeedAsRead(opts) {
    window.account.markFeedAsRead(opts.feedName);
}

function toggleAddsToCount(opts) {
    window.account.toggleAddsToCount(opts.feedName);
}

// globals that get forwarded to the global account
$.each(['markAllAsRead', 'deleteFeed', 'getUsers', 'setAccountOptions', 'follow'], function (i, name) {
    window[name] = function(opts) {
        return window.account[name](opts);
    };
});

function tweet(opts) {
    var success = opts.success,
        error = opts.error,
        status = opts.status,
        replyTo = opts.replyTo;

    window.account.tweet(status, replyTo, success, error);
}

function showReply(opts) {
    window.account.popupInReplyTo(opts.tweetId);
}

function onTweet(tweetjson) {
    window.account.onRealTimeTweet(tweetjson);
}

function signalCorruptedDatabase() {
    console.log('calling on_corrupted_database...');
    guard(function() {
        D.notify('corrupted_database');
    });
    console.log('called on_corrupted_database...');
}

function initializeDatabase(opts) {
    // open the global database connection used by all child windows
    
    if (window.db)
        return;

    try {
        window.db = window.openDatabase('digsbysocial_2_' + opts.username, "1.0", "Digsby Social Feed", 1024 * 5);
    } catch (err) {
        try { printException(err); } catch (_e) {}
        return signalCorruptedDatabase();
    }

    if (!window.db) {
        console.error('failed to open database.')
        return signalCorruptedDatabase();
    }

    return true;
}

function initialize(opts) {
    if (!initializeDatabase(opts))
        return;

    console.log('creating twitter account ' + opts.username);
    var acct = window.account = new TwitterAccount(opts.username, opts.password, opts);
    acct.ownerWindow = window;

    acct.addClient(new TwitterHTTPClient(acct));

    guard(function() {
        acct.initialize(opts.feeds, opts.accountopts);
    });

    // preload skin images
    SmoothOperator.prototype.preload();
}

function onLoad() {
    var creds = queryParse(window.location.search);
    if (creds.username && creds.password) {
        window.login.username.value = creds.username;
        window.login.password.value = creds.password;
        initialize(creds.username, creds.password);
    }
}

function onChildWindowLoaded(childWindow) {
    twitterPageLoaded(childWindow);
}

function onChildWindowUnloaded(childWindow) {
    timelineWindows.remove(childWindow);
}

$(onLoad);

