Skip to content

Commit

Permalink
Merge branch 'event-about-owner'
Browse files Browse the repository at this point in the history
  • Loading branch information
tricknotes committed May 25, 2012
2 parents 0ca3647 + 9c97a52 commit 2d51d5b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -4,7 +4,7 @@ GEM
closure-compiler (1.1.6)
crxmake (2.0.7)
zip (~> 2.0.2)
haml (3.1.4)
haml (3.1.6)
zip (2.0.2)

PLATFORMS
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Expand Up @@ -13,6 +13,7 @@
"notifications"
, "http://stream.nothub.org:4000/"
, "https://api.github.com/"
, "https://github.com/"
]
, "browser_action": {
"default_icon": "images/logo.png"
Expand Down
24 changes: 23 additions & 1 deletion src/js/background_page.coffee
Expand Up @@ -50,6 +50,21 @@ restore = (dataString) ->
catch e
{}

@getUserName = getUserName = (callback)->
xhr = new XMLHttpRequest()
xhr.onreadystatechange = ->
if xhr.readyState == 4 # contents loaded
container = document.createElement('div')
container.innerHTML = xhr.responseText
userNameElement = container.querySelector('#user')
userName = if userNameElement
userNameElement.textContent.replace(/^[ \n]+|[ \n]+$/g, '')
else
null
callback(userName)
xhr.open('GET', 'https://github.com')
xhr.send()

# export for using from other scripts
@updateQuery = updateQuery = () ->
builder = new QueryBuilder
Expand All @@ -62,7 +77,14 @@ restore = (dataString) ->
for name, eventTypes of reponames
builder.addReponame(name, eventTypes)

socket.emit 'query', builder.toQuery()
aboutUser = store.items('aboutuser')
if aboutUser && (Object.keys(aboutUser).length > 0)
getUserName (userName) ->
if userName && aboutUser[userName]
builder.addAboutUser(userName)
socket.emit 'query', builder.toQuery()
else
socket.emit 'query', builder.toQuery()

# io.connect is synchronous and heavy wait
# exports is above this line
Expand Down
26 changes: 25 additions & 1 deletion src/js/browser_action.coffee
Expand Up @@ -18,7 +18,7 @@ loadGravatarIcon = (type, name, callback) ->
if info = iconCache.items('usericon')[name]
callback(info.avatar_url || info.owner.avatar_url)
[apiPath, handler] = switch type
when 'username'
when 'username', 'aboutuser'
[
"users/#{name}"
(data) -> callback(data.avatar_url)
Expand All @@ -44,6 +44,28 @@ supportedEventTypes = {
}

jQuery ($) ->
# setup about user area
$watchAreaAboutUser = $('.watchAreaAboutUser')
background.getUserName (userName) ->
$('.watchAreaContent', $watchAreaAboutUser).hide()
if userName
$('.loggedIn', $watchAreaAboutUser).show()
loadGravatarIcon 'aboutuser', userName, (icon) ->
$('img.icon', $watchAreaAboutUser).attr('src', icon)

$checkbox = $('input[type=checkbox]', $watchAreaAboutUser)
checked = !!store.items('aboutuser')[userName]
$checkbox.attr('checked', checked)

$checkbox.change ->
if $(this).attr('checked')
store.add('aboutuser', userName, true)
else
store.remove('aboutuser', userName)

else # not logged in
$('.loggedOut', $watchAreaAboutUser).show()

$watchArea = $('.watchArea')

areaFromType = (type) ->
Expand All @@ -56,6 +78,7 @@ jQuery ($) ->
toWatchedArea = _.template($('#watchedAreaTemplate').text())

setupWatchedField = (type, name) ->
return unless supportedEventTypes[type]
$place = $('.watchedNames', areaFromType(type))
$field = $(toWatchedArea({
type
Expand All @@ -80,6 +103,7 @@ jQuery ($) ->
store.on 'add', setupWatchedField

removeNameFromWatchedField = (type, name) ->
return unless supportedEventTypes[type]
$place = $('.watchedNames', areaFromType(type))
$('.watchedRow', $place).each (i, el) ->
if $(el).data('name') == name
Expand Down
36 changes: 36 additions & 0 deletions src/js/query_builder.coffee
Expand Up @@ -18,6 +18,42 @@ class QueryBuilder
{repo: {name}}
))

addAboutUser: (login) ->
@query.push(
{'$and': [
{actor: {
login: {
'$ne': login}}
}
{'$or': [
{repo: {
name: {
'$contains': "#{login}/"}}
}
# PushEvent -> someone push commit authored by login
{ payload: {
commits: {
'$contains': {
author: {
name: login} }}}}
# FollowEvent -> follow login
{payload: {
target: {login} }}
# TODO CommitCommentEvent -> commited by login
# IssueCommentEvent -> opened by login
{payload: {
issue: {
user: {login} }}
}
# PullRequestEvent -> opened by login
{payload: {
pull_request: {
user: {login} }}
}
]}
]}
)

toQuery: () ->
if @query.length == 1
@query[0]
Expand Down
15 changes: 15 additions & 0 deletions src/popup.haml
Expand Up @@ -32,6 +32,21 @@
%h1
Your following list for GitHub

.watchAreaAboutUser
%h2 The events you should receive:
.watchAreaContent.loading
%img.icon{:src => '../images/loading.gif'}
.watchAreaContent.loggedIn{'style' => 'display:none;'}
%form
%img.icon{:src => '../images/loading.gif'}
Receive notification about YOU.
%input.aboutUser{'type' => 'checkbox'}
.watchAreaContent.loggedOut{'style' => 'display:none;'}
%img.icon{:src => '../images/no-icon.png'}
Login to
%a{'href' => 'https://github.com/login', 'target' => '_blank'}github.com
to be notified about you.

.watchArea{'data-type' => 'username'}
%h2 Users:
.watchAreaContent
Expand Down

0 comments on commit 2d51d5b

Please sign in to comment.