Remove presence from collaboration package.

This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-07-09 15:08:53 -07:00
committed by Kevin Sawicki
parent be078b2b41
commit 40d500949b
7 changed files with 50 additions and 198 deletions

View File

@@ -1,56 +0,0 @@
url = require 'url'
{$$} = require 'space-pen'
ScrollView = require 'scroll-view'
BuddyView = require './buddy-view'
module.exports =
class BuddyList extends ScrollView
@content: ->
@div class: 'buddy-list', tabindex: -1, =>
@button outlet: 'shareButton', type: 'button', class: 'btn btn-default'
@div outlet: 'buddies'
presence: null
sharingSession: null
initialize: (@presence, @sharingSession) ->
super
if @sharingSession.isSharing()
@shareButton.text('Stop')
else
@shareButton.text('Start')
@presence.on 'person-added', => @updateBuddies()
@presence.on 'person-removed', => @updateBuddies()
@presence.on 'person-status-changed', => @updateBuddies()
@shareButton.on 'click', =>
@shareButton.disable()
if @sharingSession.isSharing()
@shareButton.text('Stopping...')
@sharingSession.stop()
else
@shareButton.text('Starting...')
@sharingSession.start()
@sharingSession.on 'started', =>
@shareButton.text('Stop').enable()
@sharingSession.on 'stopped', =>
@shareButton.text('Start').enable()
toggle: ->
if @hasParent()
@detach()
else
@attach()
attach: ->
rootView.horizontal.append(this)
@focus()
@updateBuddies()
updateBuddies: ->
@buddies.empty()
@buddies.append(new BuddyView(buddy)) for buddy in @presence.getPeople()

View File

@@ -1,27 +0,0 @@
url = require 'url'
{View} = require 'space-pen'
module.exports =
class BuddyView extends View
@content: ({user, windows}) ->
@div =>
@div class: 'buddy-name', =>
@img class: 'avatar', outlet: 'avatar'
@span user.login
for id, windowState of windows
{repository} = windowState
continue unless repository?
[owner, name] = url.parse(repository.url).path.split('/')[-2..]
name = name.replace(/\.git$/, '')
@div class: 'repo-name', =>
@span name
if repository.branch
@div class: 'branch-name', =>
@span repository.branch
initialize: (@buddy) ->
if @buddy.user.avatarUrl
@avatar.attr('src', @buddy.user.avatarUrl)
else
@avatar.hide()

View File

@@ -0,0 +1,38 @@
url = require 'url'
{$$, View} = require 'space-pen'
module.exports =
class CollaborationView extends View
@content: ->
@div class: 'collaboration', tabindex: -1, =>
@div outlet: 'share', type: 'button', class: 'share'
@div outlet: 'participants'
sharingSession: null
initialize: (@sharingSession) ->
if @sharingSession.isSharing()
@share.addClass('running')
@share.on 'click', =>
@share.disable()
if @sharingSession.isSharing()
@sharingSession.stop()
else
@sharingSession.start()
@sharingSession.on 'started stopped', =>
@share.toggleClass('running').enable()
@attach()
toggle: ->
if @hasParent()
@detach()
else
@attach()
attach: ->
rootView.horizontal.append(this)
@focus()

View File

@@ -1,23 +1,17 @@
Presence = require './presence'
CollaborationView = require './collaboration-view'
SharingSession = require './sharing-session'
BuddyList = require './buddy-list'
JoinPromptView = require './join-prompt-view'
module.exports =
activate: ->
presence = new Presence()
sharingSession = new SharingSession()
buddyList = null
rootView.command 'collaboration:toggle-buddy-list', ->
buddyList ?= new BuddyList(presence, sharingSession)
buddyList.toggle()
rootView.command 'collaboration:copy-session-id', ->
sessionId = sharingSession.getId()
pasteboard.write(sessionId) if sessionId
rootView.command 'collaboration:start-session', ->
new CollaborationView(sharingSession)
if sessionId = sharingSession.start()
pasteboard.write(sessionId)
@@ -28,5 +22,3 @@ module.exports =
resourcePath: window.resourcePath
sessionId: id
atom.openWindow(windowSettings)
rootView.trigger 'collaboration:toggle-buddy-list' # TEMP

View File

@@ -1,76 +0,0 @@
guid = require 'guid'
$ = require 'jquery'
keytar = require 'keytar'
_ = require 'underscore'
Pusher = require '../vendor/pusher.js'
module.exports =
class Presence
_.extend @prototype, require('event-emitter')
people: null
personId: null
windowId: null
constructor: ->
@people = {}
@windowId = guid.create().toString()
@connect()
connect: ->
token = keytar.getPassword('github.com', 'github')
return unless token
pusher = new Pusher '490be67c75616316d386',
encrypted: true
authEndpoint: 'https://fierce-caverns-8387.herokuapp.com/pusher/auth'
auth:
params:
oauth_token: token
channel = pusher.subscribe('presence-atom')
channel.bind 'pusher:subscription_succeeded', (members) =>
console.log 'subscribed to presence channel'
@personId = members.me.id
event = id: @personId
event.window = id: @windowId
if git?
event.window.repository =
branch: git.getShortHead()
url: git.getConfigValue('remote.origin.url')
channel.trigger('client-window-opened', event)
# List self as available for debugging UI when no one else is around
self =
id: @personId
user: members.me.info
windows: {}
self.windows[@windowId] = event.window
@people[self.id] = self
@trigger 'person-status-changed', self
channel.bind 'pusher:member_added', (member) =>
console.log 'member added', member
@people[member.id] = {user: member.info, windows: {}}
@trigger 'person-added', @people[member.id]
channel.bind 'pusher:member_removed', (member) =>
console.log 'member removed', member
@people.delete(member.id)
@trigger 'person-removed'
channel.bind 'client-window-opened', (event) =>
console.log 'window opened', event
if person = @people[event.id]
person.windows[event.window.id] = event.window
@trigger 'person-status-changed', person
channel.bind 'client-window-closed', (event) =>
console.log 'window closed', event
if person = @people[event.id]
delete person.windows[event.windowId]
@trigger 'person-status-changed', person
$(window).on 'beforeunload', =>
channel.trigger 'client-window-closed', {id: @personId, @windowId}
getPeople: -> _.values(@people)

View File

@@ -1,42 +1,23 @@
@import "bootstrap/less/variables.less";
@import "octicon-mixins.less";
@runningColor: #99CC99;
.buddy-list {
.collaboration {
@item-line-height: @line-height-base * 1.25;
padding: 10px;
-webkit-user-select: none;
cursor: pointer;
.buddy-name {
line-height: 30px;
margin-bottom: 5px;
.avatar {
border-radius: 3px;
height: 30px;
width: 30px;
float: left;
margin-right: 5px;
}
.share {
.mini-icon(notifications);
}
.repo-name {
margin-left: 5px;
line-height: @item-line-height;
.mini-icon(public-repo);
.running {
color: @runningColor;
span {
padding-left: 5px;
}
}
.branch-name {
margin-left: 5px;
line-height: @item-line-height;
.mini-icon(branch);
span {
padding-left: 5px;
&:hover {
color: lighten(@runningColor, 15%);
}
}
}

View File

@@ -1,4 +1,4 @@
.buddy-list {
.collaboration {
background: #1b1c1e;
box-shadow:
1px 0 0 #131516,