Skip to content

Commit

Permalink
Merge branch 'master' of github.com:buddycloud/buddycloud-webclient
Browse files Browse the repository at this point in the history
Conflicts:
	brunch/src/app/views/home/show.coffee
  • Loading branch information
dodo committed Oct 1, 2011
2 parents 59a48ae + 416d1eb commit 82da359
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 45 deletions.
3 changes: 1 addition & 2 deletions brunch/src/app/collections/node.coffee
Expand Up @@ -57,7 +57,6 @@ class exports.NodeStore extends exports.Nodes

initialize: ->
@channel.bind "subscription:user:#{@channel.get 'id'}", (subscription) =>
console.warn "NodeStore got subscription", subscription
node = @get(subscription.node, yes)
node.push_subscription subscription
@channel.bind 'post', (nodeid, post) =>
Expand All @@ -73,5 +72,5 @@ class exports.NodeStore extends exports.Nodes
id = nodeid_to_type(nodeid)
unless id and nodeid
throw "NodeID missing"
@add { nodeid }
@add { id, nodeid }
super(id)
8 changes: 6 additions & 2 deletions brunch/src/app/controllers/router.coffee
Expand Up @@ -32,7 +32,11 @@ class exports.Router extends Backbone.Router
on_connected: =>
app.views.index = new HomeView
app.users.target ?= app.users.current
@navigate app.users.target.get('jid'), true
jid = app.users.target.get('jid')
@navigate jid
# in anonymous direct browsing route, navigate above doesn't
# trigger an URL change event at all
@loadingchannel jid

# routes

Expand All @@ -55,7 +59,7 @@ class exports.Router extends Backbone.Router
@setView app.views.overview

loadingchannel: (id, domain) ->
jid = "#{id}@#{domain}"
jid = if domain then "#{id}@#{domain}" else id
app.users.target = app.users.get jid, yes

if app.handler.connection.connected
Expand Down
3 changes: 3 additions & 0 deletions brunch/src/app/handlers/data.coffee
Expand Up @@ -12,6 +12,9 @@ class exports.DataHandler extends Backbone.EventHandler
@connector.bind 'connection:start', @on_prefill_from_cache
@connector.bind 'connection:established', @on_connection_established

get_node_posts: (node, callback) ->
@connector.get_node_posts node, callback

get_node_metadata: (node, callback) ->
@connector.get_node_metadata node.get('nodeid'), callback

Expand Down
9 changes: 8 additions & 1 deletion brunch/src/app/models/channel.coffee
Expand Up @@ -6,10 +6,17 @@
# Attribute jid: Jabber-Id
class exports.Channel extends Backbone.Model
initialize: ->
@id = @get 'id'
@nodes = new NodeStore(channel: this)
@avatar = gravatar @get('id'), s:50, d:'retro'
@avatar = gravatar @id, s:50, d:'retro'
@nodes.fetch()

# Auto-create the default set of nodes for that channel, so
# that its data can be retrieved via XMPP
["posts", "status", "subscriptions",
"geo/previous", "geo/current", "geo/next"].forEach (type) =>
@nodes.get "/user/#{@id}/#{type}", yes

push_post: (nodeid, post) ->
@trigger "post", nodeid, post

Expand Down
12 changes: 6 additions & 6 deletions brunch/src/app/models/node/base.coffee
@@ -1,19 +1,18 @@
{ NodeMetadata } = require 'models/metadata/node'
{ Users } = require('collections/user')
{ Posts } = require('collections/post')
{ nodeid_to_type } = require 'util'

class exports.Node extends Backbone.Model
defaults: ->
id: nodeid_to_type(@get 'nodeid')

initialize: ->
nodeid = @get 'nodeid'
@metadata = new NodeMetadata this, nodeid
# Subscribers:
@users = new Users(parent: this)
@posts ?= new Posts(parent: this)
console.warn "Posts nouvelles", @posts

# TODO: only if !subscribed and therefore covered by MAM
do @retrieve_node

toJSON: (full) ->
result = super
Expand All @@ -29,8 +28,6 @@ class exports.Node extends Backbone.Model
update: -> # api function - every node should be updateable

push_subscription: (subscription) ->
console.warn "Node got subscription", subscription

switch subscription.subscription
when 'subscribed'
@users.get subscription.jid, yes
Expand All @@ -43,4 +40,7 @@ class exports.Node extends Backbone.Model
push_post: (post) ->
@trigger 'post', post

retrieve_node: ->
nodeid = @get 'nodeid'
app.handler.data.get_node_posts nodeid, ->

5 changes: 2 additions & 3 deletions brunch/src/app/models/user.coffee
Expand Up @@ -4,11 +4,10 @@

class exports.User extends Backbone.Model

defaults: ->
id: @get('jid')

initialize: ->
# id and jid are the same
@id = @get('jid')
@set {@id}
@avatar = gravatar @id, s:50, d:'retro'
# subscribed channels
@channels = new UserChannels parent:this
Expand Down
2 changes: 1 addition & 1 deletion brunch/src/app/views/channel/post.coffee
Expand Up @@ -20,4 +20,4 @@ class exports.PostView extends BaseView
'click .avatar': 'clickAuthor'

clickAuthor: EventHandler ->
app.router.setCurrentChannel @author.get('jid')
app.router.navigate @author.get('jid'), true
47 changes: 29 additions & 18 deletions brunch/src/app/views/home/show.coffee
Expand Up @@ -13,26 +13,18 @@ class exports.HomeView extends Backbone.View
# sidebar entries
@views = {} # this contains the channelnode views
@channels = new Channels
new_channel_view = (channel) =>
view = @views[channel.cid]
if not view
view = new ChannelView model:channel, parent:this
@views[channel.cid] = view
do view.render
@el.append view.el
unless @current?
@current = view
else
view.el.hide()

app.users.current.channels.bind 'add', (channel) =>
@channels.update channel
app.users.current.channels.forEach (channel) =>
@channels.add channel
new_channel_view channel
@new_channel_view channel
# Attempt to come up with a default channel:
if !@current and channel.get('id') is app.users.current.get('id')
@setCurrentChannel channel

@channels.bind 'change', new_channel_view
@channels.bind 'add', new_channel_view
@channels.bind 'change', @new_channel_view
@channels.bind 'add', @new_channel_view
@channels.bind 'all', =>
app.debug "home CHEV-ALL", arguments
# if we already found a view in the cache
Expand All @@ -46,13 +38,32 @@ class exports.HomeView extends Backbone.View
@render()
@el.show()

new_channel_view: (channel) =>
unless (view = @views[channel.cid])
view = new ChannelView model:channel, parent:this
@views[channel.cid] = view
@el.append view.el
view.el.hide()
view

setCurrentChannel: (channel) =>
@current?.el.hide()
@current = @views[channel.cid]
app.router.navigate @current.model.get('id'), true if @current?
@hideCurrent?()

if (@current = @views[channel.cid])
# Present-before view
@hideCurrent = =>
@current.el.hide()
else
# Temporary view not added by @channels.bind('add')
@current = @views[channel.cid] = @new_channel_view channel
@hideCurrent = =>
@current.el.hide()
# Dispose when hiding:
delete @views[channel.cid]
app.router.navigate @current.model.get('id'), true

@sidebar.setCurrentEntry channel
@current?.el.show()
@current.el.show()

render: ->
@current?.render()
Expand Down
40 changes: 29 additions & 11 deletions brunch/src/app/views/sidebar/show.coffee
Expand Up @@ -13,24 +13,42 @@ class exports.Sidebar extends Backbone.View
# sidebar entries
@current = undefined
@views = {} # this contains the channel entry views
new_channel_entry = (channel) =>
entry = @views[channel.cid]
unless entry
entry = new ChannelEntry model:channel, parent:this
@views[channel.cid] = entry
@current ?= entry
@el.append entry.el
entry.render()
@parent.channels.forEach new_channel_entry
@parent.channels.bind 'change', new_channel_entry
@parent.channels.bind 'add', new_channel_entry
@parent.channels.forEach @new_channel_entry
@parent.channels.bind 'change', @new_channel_entry
@parent.channels.bind 'add', @new_channel_entry
@parent.channels.bind 'all', =>
app.debug "sidebar CHEV-ALL", arguments

unless app.views.overview?
app.views.overview = new ChannelOverView
@overview = app.views.overview

events:
'keypress .search input': 'on_search_keypress'

on_search_keypress: (ev) ->
if ev.keyCode == 13
ev.preventDefault()

input = @$('.search input')
search = input.val()
if /[^\/]+@[^\/]/.test(search)
app.router.navigate search, yes
input.val('')
no
else
yes

new_channel_entry: (channel) =>
entry = @views[channel.cid]
unless entry
entry = new ChannelEntry model:channel, parent:this
@views[channel.cid] = entry
@current ?= entry
@el.append entry.el
entry.render()
entry

setCurrentEntry: (channel) =>
old = @current
@current = @views[channel.cid]
Expand Down
20 changes: 19 additions & 1 deletion brunch/src/vendor/strophe.buddycloud.js
Expand Up @@ -347,7 +347,25 @@ Strophe.addConnectionPlugin('buddycloud', {
});
});
} else if (child.nodeName === 'configuration') {
/* TODO */
var config = {};
Strophe.forEachChild(child, 'x', function(x) {
Strophe.forEachChild(x, 'field', function(field) {
var k = field.getAttribute('var'),
v = undefined;
Strophe.forEachChild(field, 'value', function(value) {
if (!v)
v = Strophe.getText(value);
});
if (k && v)
config[k] = v;
});
});
if (config.FORM_TYPE === "http://jabber.org/protocol/pubsub#node_config")
listener({
type: 'config',
node: child.getAttribute('node'),
config: config
});
} else
console.warn("Unhandled buddycloud event type", child.nodeName);
});
Expand Down

0 comments on commit 82da359

Please sign in to comment.