Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
Conflicts:
	brunch/src/app/collections/channel.coffee
	brunch/src/app/collections/node.coffee
	brunch/src/app/collections/post.coffee
  • Loading branch information
dodo committed Oct 1, 2011
2 parents c01f7a1 + 59a48ae commit 591700b
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 56 deletions.
14 changes: 7 additions & 7 deletions brunch/src/app/collections/channel.coffee
Expand Up @@ -16,15 +16,14 @@ class exports.UserChannels extends exports.Channels

initialize: ->
super
@parent.bind "subscription", (subscription) =>
@parent.bind "subscription:user:#{@parent.get 'id'}", (subscription) =>
switch subscription.subscription
when 'subscribed'
# FIXME get 'pending' working when we need it
when 'subscribed', 'pending'
@get subscription.node, yes
# FIXME get this working when we need it
when 'unsubscribed'
throw new Error 'FIXME unsubscribed' #@remove id
when 'pending'
throw new Error 'FIXME pending' #@get(subscription.node).save
when 'unsubscribed', 'none'
if (channel = @get subscription.node)
@remove channel
@fetch()

sync: (method, model, options) ->
Expand All @@ -46,6 +45,7 @@ class exports.UserChannels extends exports.Channels
channel = app.channels.get id, options
@create channel


# overriding backbone internals
_add: ->
channel = super
Expand Down
17 changes: 6 additions & 11 deletions brunch/src/app/collections/node.coffee
Expand Up @@ -41,21 +41,16 @@ class exports.NodeStore extends exports.Nodes
super()

initialize: ->
@channel.bind 'subscription', (subscription) =>
@channel.bind "subscription:user:#{@channel.get 'id'}", (subscription) =>
node = @get subscription.node, create:yes
node.push_subscription subscription
@channel.bind 'post', (nodeid, post) =>
node = @get nodeid, create:yes
node.push_post post

# When creating, you must always pass a full nodeid
get: (nodeid, create) ->
id = nodeid_to_type(nodeid) or nodeid
if (node = super(id))
node
else if create
id = nodeid_to_type(nodeid)
unless id and nodeid
throw "NodeID missing"
@add { id, nodeid }
super(id)
get: (nodeid, options = {}) ->
id = nodeid_to_type(nodeid)
if options.create and not id
throw new Error "NodeID missing"
super id, options
1 change: 0 additions & 1 deletion brunch/src/app/collections/post.coffee
Expand Up @@ -10,4 +10,3 @@ class exports.Posts extends Collection
initialize: ->
@parent.bind 'post', (post) =>
@create post, update:yes

4 changes: 2 additions & 2 deletions brunch/src/app/collections/subscription.coffee
Expand Up @@ -10,6 +10,6 @@ class exports.SubscriptionStore extends Collection

get: (id, options = {}) ->
if options.all
super id
super id, options
else
super(id)?.get 'value'
super(id, options)?.get 'value'
19 changes: 5 additions & 14 deletions brunch/src/app/handlers/connector.coffee
Expand Up @@ -29,11 +29,7 @@ class exports.Connector extends Backbone.EventHandler
@connection.buddycloud.subscribeNode nodeid, (stanza) =>
app.debug "subscribe", stanza
userJid = Strophe.getBareJidFromJid(@connection.jid)
@trigger 'subscription:user',
jid: userJid
node: nodeid
subscription: 'subscribed'
@trigger 'subscription:node',
@trigger 'subscription',
jid: userJid
node: nodeid
subscription: 'subscribed'
Expand All @@ -48,14 +44,10 @@ class exports.Connector extends Backbone.EventHandler
@connection.buddycloud.unsubscribeNode nodeid, (stanza) =>
app.debug "unsubscribe", stanza
userJid = Strophe.getBareJidFromJid(@connection.jid)
@trigger 'subscription:user',
jid: userJid
node: nodeid
subscription: 'none'
@trigger 'subscription:node',
@trigger 'subscription',
jid: userJid
node: nodeid
subscription: 'none'
subscription: 'unsubscribed'
callback? stanza
done()
, =>
Expand All @@ -78,7 +70,7 @@ class exports.Connector extends Backbone.EventHandler
@trigger "post", post, nodeid
else if post.subscriptions?
for own nodeid_, subscription of post.subscriptions
@trigger 'subscription:user', subscription
@trigger 'subscription', subscription
callback? posts
done()
error = =>
Expand Down Expand Up @@ -112,8 +104,7 @@ class exports.Connector extends Backbone.EventHandler

switch notification.type
when 'subscription'
@trigger 'subscription:user', notification
@trigger 'subscription:node', notification
@trigger 'subscription', notification
when 'affiliation'
@trigger 'affiliation', notification
when 'posts'
Expand Down
3 changes: 1 addition & 2 deletions brunch/src/app/handlers/data.coffee
Expand Up @@ -8,8 +8,7 @@ class exports.DataHandler extends Backbone.EventHandler

@connector.bind 'post', @on_node_post
@connector.bind 'affiliation', @on_affiliation
@connector.bind 'subscription:user', @on_subscription
@connector.bind 'subscription:node', @on_subscription
@connector.bind 'subscription', @on_subscription
@connector.bind 'connection:start', @on_prefill_from_cache
@connector.bind 'connection:established', @on_connection_established

Expand Down
2 changes: 1 addition & 1 deletion brunch/src/app/models/channel.coffee
Expand Up @@ -16,5 +16,5 @@ class exports.Channel extends Backbone.Model
# subscription.jid is already filtered for this channel id (user)
push_subscription: (subscription) ->
# subscription.subscription is either subscribed, unsubscribed or pending
@trigger "subscription", subscription
@trigger "subscription:user:#{subscription.jid}", subscription

6 changes: 5 additions & 1 deletion brunch/src/app/models/node/base.coffee
@@ -1,8 +1,12 @@
{ 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
Expand Down Expand Up @@ -34,7 +38,7 @@ class exports.Node extends Backbone.Model
if (user = @users.get subscription.jid)
@users.remove user

@trigger 'subscription', subscription
@trigger "subscription:node:#{subscription.node}", subscription

push_post: (post) ->
@trigger 'post', post
Expand Down
11 changes: 11 additions & 0 deletions brunch/src/app/models/post.coffee
@@ -1,6 +1,17 @@

class exports.Post extends Backbone.Model

defaults: ->
author:
jid: undefined
name: undefined
uri: undefined
content:
type: undefined
value: undefined
published: new Date().toISOString()
updated: new Date().toISOString()

initialize: ->
result = super
@author = app.users.get @get('author').jid, yes
Expand Down
17 changes: 5 additions & 12 deletions brunch/src/app/models/user.coffee
Expand Up @@ -4,23 +4,16 @@

class exports.User extends Backbone.Model

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

initialize: ->
# id and jid are the same
@set id: @get('jid')
@avatar = gravatar @id, s:50, d:'retro'
# subscribed channels
@channels = new UserChannels parent:this
@metadata = new UserMetadata parent:this

push_subscription: (subscription) ->
if subscription.jid isnt @get('jid')
return

switch subscription.subscription
when 'subscribed'
@channels.get subscription.node, yes
when 'unsubscribed', 'none'
if (channel = @channels.get subscription.node)
@channels.remove user

@trigger "subscription", subscription
if subscription.jid is @get('jid')
@trigger "subscription:user:#{@get 'jid'}", subscription
12 changes: 7 additions & 5 deletions brunch/src/app/views/channel/show.coffee
Expand Up @@ -14,7 +14,8 @@ class exports.ChannelView extends BaseView
@model.bind 'change', @render
@model.bind 'change:node:metadata', @render
nodeid = @model.nodes.get('posts')?.get 'nodeid'
app.users.current.channels.bind "change:#{@model.get 'id'}", @render
app.users.current.channels.bind "add", @render
app.users.current.channels.bind "remove", @render
# create posts node view when it arrives from xmpp or instant when its already cached
init_posts = =>
@model.nodes.unbind "add", init_posts
Expand All @@ -24,6 +25,7 @@ class exports.ChannelView extends BaseView
parent: this
el: @el.find('.topics')
do @postsview.render
do @render
else
@model.nodes.bind "add", init_posts
do init_posts
Expand All @@ -45,7 +47,8 @@ class exports.ChannelView extends BaseView
node = @model.nodes.get('posts')
app.handler.data.publish node, post, =>
post.content = value:post.content
app.handler.data.add_post node, post
# TODO: make sure prematurely added post correlates to incoming notification
#app.handler.data.add_post node, post
@el.find('.newTopic, .answer').removeClass 'write'
text.val ""

Expand Down Expand Up @@ -83,10 +86,9 @@ class exports.ChannelView extends BaseView
if (geo = @model.nodes.get 'geoloc')
@geo = geo.toJSON yes
# Permissions:
subscription = app.users.current.channels.get(@model.nodes.get('posts')?.get 'nodeid') or "none"
followingThisChannel = app.users.current.channels.get(@model.nodes.get('posts')?.get 'nodeid')?
#affiliation = app.users.current.affiliations.get(@model.nodes.get('posts')?.get 'nodeid') or "none"
# TODO: pending may require special handling
@user =
followingThisChannel: subscription in ["subscribed", "pending"]
followingThisChannel: followingThisChannel
hasRightToPost: yes #affiliation in ["owner", "publisher", "moderator", "member"]
app.debug "ChannelView.update_attributes", @user

0 comments on commit 591700b

Please sign in to comment.