unsubscribe to first selfQ query (we subscribe to it twice for a

reason in the comments, it's jank)
This commit is contained in:
Tyler Renelle 2013-02-18 21:53:50 -05:00
parent c3a5401a93
commit 5698db29fb

View file

@ -27,19 +27,23 @@ module.exports.partySubscribe = partySubscribe = (model, cb) ->
# Restart subscription to the main user
selfQ = model.query('users').withId(model.get('_userId') or model.session.userId)
selfQ.fetch (err, res) ->
selfQ.subscribe (err, self) ->
throw err if err
u = res.at(0)
u = self.at(0)
uObj = u.get()
finished = ->
selfQ.subscribe (err, res) ->
model.ref '_user', res.at(0)
browser.resetDom(model) if window?
cb() if cb?
model.unsubscribe selfQ, ->
selfQ.subscribe (err, self) ->
model.ref '_user', self.at(0)
browser.resetDom(model) if window?
cb() if cb?
## (1) User is solo, just return that subscription
return finished() unless uObj.party?.current
unless uObj.party?.current
model.ref '_user', u
browser.resetDom(model) if window?
return if cb then cb() else null
# User in a party