<commit_before>{Timeline, Status, extend, jsonp} = Chorus = @Chorus

class BuzzTimeline extends Timeline
    constructor: (userid, options) ->
        @userid = userid
        super options

    queryUrl: "http://ajax.googleapis.com/ajax/services/feed/load"

    fetch: ->
        feed_url = escape "http://buzz.googleapis.com/feeds/#{ @userid }/public/posted"

        jsonp
            data:
                q: feed_url
                num: @options.count
                output: "json"
                v: "1.0"
            url: @queryUrl
            callback: (json) => @update json

    statusesFromData: (data) ->
        unless data.responseStatus is 200 and data.responseData
            return []

        for entry in data.responseData.feed.entries
            BuzzStatus.from entry, @userid

class BuzzStatus extends Status
    renderAvatar: ->
        link = Chorus.$fromHTML """<a href="#{ @getStreamUrl() }" class="avatar" />"""
        Chorus.$append link, buzzAvatar @username
        return link

    getStreamUrl: -> "http://www.google.com/profiles/#{@username}#buzz"

    getUrl: -> @id

    @from: (data, userid) ->
        new BuzzStatus data.link, userid || data.author, null, data.publishedDate, data.content

extend Chorus, {BuzzStatus, BuzzTimeline}

shorthands = [{
    pattern: /^BZ:(.*)$/,
    fun: (_, name) -> new BuzzTimeline name
}]

Timeline.shorthands = shorthands.concat Timeline.shorthands

cache = {}

buzzAvatar = (name) ->
    cached = cache[name]

    unless cached?
        init name
    else if cached.image?
        cached.image.clone()
    else
        placeholder name

init = (name) ->
    getGoogleAvatar name, removePlaceholders
    cache[name] = image: null, placeholders: []

    placeholder name

placeholder = (name) ->
    el = Chorus.$fromHTML '<div class="placeholder" />'
    cache[name].placeholders.push el
    return el

removePlaceholders = (name, src) ->
    item = cache[name]
    item.image = Chorus.$fromHTML """<img src="#{ src }" class="avatar" />"""
    for p in item.placeholders
        p.parentNode.replaceChild item.image.cloneNode(true), p

getGoogleAvatar = (name, callback) ->
    jsonp
        url: "http://socialgraph.apis.google.com/otherme"
        data: { q: <EMAIL>" }
        padding: "jscb"
        callback: (json) ->
            user = json["http://www.google.com/profiles/#{name}"]
            src  = user and user.attributes.photo

            callback name, src if src<commit_msg>updated the google avatar code<commit_after>{Timeline, Status, extend, jsonp} = Chorus = @Chorus

class BuzzTimeline extends Timeline
    constructor: (userid, options) ->
        @userid = userid
        super options

    queryUrl: "http://ajax.googleapis.com/ajax/services/feed/load"

    fetch: ->
        feed_url = escape "http://buzz.googleapis.com/feeds/#{ @userid }/public/posted"

        jsonp
            data:
                q: feed_url
                num: @options.count
                output: "json"
                v: "1.0"
            url: @queryUrl
            callback: (json) => @update json

    statusesFromData: (data) ->
        unless data.responseStatus is 200 and data.responseData
            return []

        for entry in data.responseData.feed.entries
            BuzzStatus.from entry, @userid

class BuzzStatus extends Status
    renderAvatar: ->
        link = Chorus.$fromHTML """<a href="#{ @getStreamUrl() }" class="avatar" />"""
        Chorus.$append link, buzzAvatar @username
        return link

    getStreamUrl: -> "http://www.google.com/profiles/#{@username}#buzz"

    getUrl: -> @id

    @from: (data, userid) ->
        new BuzzStatus data.link, userid || data.author, null, data.publishedDate, data.content

extend Chorus, {BuzzStatus, BuzzTimeline}

shorthands = [{
    pattern: /^BZ:(.*)$/,
    fun: (_, name) -> new BuzzTimeline name
}]

Timeline.shorthands = shorthands.concat Timeline.shorthands

cache = {}

buzzAvatar = (name) ->
    cached = cache[name]

    unless cached?
        init name
    else if cached.image?
        cached.image.clone()
    else
        placeholder name

init = (name) ->
    getGoogleAvatar name, removePlaceholders
    cache[name] = image: null, placeholders: []

    placeholder name

placeholder = (name) ->
    el = Chorus.$fromHTML '<div class="placeholder" />'
    cache[name].placeholders.push el
    return el

removePlaceholders = (name, src) ->
    item = cache[name]
    item.image = Chorus.$fromHTML """<img src="#{ src }" class="avatar" />"""
    for p in item.placeholders
        p.parentNode.replaceChild item.image.cloneNode(true), p

getGoogleAvatar = (name, callback) ->
    jsonp
        url: "http://socialgraph.apis.google.com/otherme"
        data: { q: <EMAIL>" }
        padding: "jscb"
        callback: (json) ->
            user = json["http://profiles.google.com/#{name}"]
            src  = user and user.attributes.photo

            callback name, src if src
{'fraction_non_alphanumeric': 0.13124368048533872, 'fraction_numerical': 0.0020222446916076846, 'mean_word_length': 2.3328840970350404, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '2681820', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1490, 'n_words': 369}