From daac7f424fce8f35a402cb2eafcc59a8d4a1df36 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 18 Feb 2013 12:49:53 -0500 Subject: [PATCH] temp fix for withId query motif not being defined (just fetch parties, don't subscribe to them). Note this isn't fully functional, it's a hotfix to patch the major errors --- src/app/index.coffee | 18 ++++-------------- src/app/party.coffee | 44 +++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 9b634896c2..40aceb6550 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -32,22 +32,12 @@ get '/', (page, model, next) -> #if req.headers['x-forwarded-proto']!='https' and process.env.NODE_ENV=='production' # return page.redirect 'https://' + req.headers.host + req.url - # This used to be in party.server(model, cb), but was getting `TypeError: Object # has no method 'server'` - # on the second load for some reason - selfQ = model.query('users').withId(model.get('_userId') or model.session.userId) - model.subscribe selfQ, (err, users) -> - throw err if err - - user = users.at(0) - model.ref '_user', user - model.set '_view', _view - + party.partySubscribe model, -> character.updateUser(model) items.server(model) - - party.partySubscribe model, -> - browser.restoreRefs model - page.render() + model.set '_view', _view + browser.restoreRefs model + page.render() # ========== CONTROLLER FUNCTIONS ========== diff --git a/src/app/party.coffee b/src/app/party.coffee index a36ad7b16a..a9d3e49bdc 100644 --- a/src/app/party.coffee +++ b/src/app/party.coffee @@ -14,23 +14,30 @@ partyUnsubscribe = (model, cb) -> module.exports.partySubscribe = partySubscribe = (model, cb) -> # unsubscribe from everything - we're starting over - partyUnsubscribe model + #partyUnsubscribe model # Restart subscription to the main user selfQ = model.query('users').withId(model.get('_userId') or model.session.userId) - selfQ.subscribe (err, res) -> + selfQ.fetch (err, res) -> throw err if err u = res.at(0) uObj = u.get() - # If user not in a party, just send over that subscription - unless uObj.party?.current - model.ref '_user', u - return cb() + finished = (reset, cb) -> + # Here's a hack we need to get fixed - later model.queries override previous model.queries' + # returned fields. Aka, we need this here otherwise we only get the "public" fields for the current user, which + # are defined in model.query('users').party() + selfQ.subscribe (err, res) -> + model.ref '_user', res.at(0) + browser.resetDom(model) if window? and reset + cb() if cb? + + ## (1) User is solo, just return that subscription + return finished(false, cb) unless uObj.party?.current # User in a party partiesQ = model.query('parties').withId(uObj.party.current) - partiesQ.subscribe (err, res) -> + partiesQ.fetch (err, res) -> throw err if err p = res.at(0) model.ref '_party', p @@ -42,28 +49,19 @@ module.exports.partySubscribe = partySubscribe = (model, cb) -> # debugger # membersSubscribe model, ids - finished = (cb) -> - # Here's a hack we need to get fixed (hopefully Lever will) - later model.queries override previous model.queries' - # returned fields. Aka, we need this here otherwise we only get the "public" fields for the current user, which - # are defined in model.query('users')party() - model.subscribe selfQ, (err, users) -> - model.ref '_user', users.at(0) - browser.resetDom(model) if window? - cb() if cb? - - ids = p.get('members') - # Party has no members, just subscribe to the party itself - if _.isEmpty(ids) - finished(cb) - # Party has members, subscribe to those users too + ## (2) Party has no members, just subscribe to the party itself + if _.isEmpty(ids) + return finished(true, cb) + + ## (3) Party has members, subscribe to those users too else membersQ = model.query('users').party(ids) - membersQ.subscribe (err, m) -> + membersQ.fetch (err, m) -> throw err if err model.ref '_partyMembers', m - finished(cb) + finished(true, cb) module.exports.app = (appExports, model) ->