From f8e546ae2af42ddf1d65c23b7fafbbc470100ccb Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 3 Jun 2013 14:08:54 -0400 Subject: [PATCH] groups: bug fixes: {#if _party} dynamic binding, subscription allowed for either party or guild with out requiring the other --- src/app/index.coffee | 23 +++++++++++++---------- src/server/store.coffee | 33 +++++++++++++++------------------ views/app/groups.html | 8 ++++---- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 2da29431fd..bde4b038d7 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -31,17 +31,15 @@ setupSubscriptions = (page, model, params, next, cb) -> uuid = model.get('_userId') or model.session.userId # see http://goo.gl/TPYIt selfQ = model.query('users').withId(uuid) #keep this for later - # Fetch public groups as _publicGroups # Note: due to https://github.com/codeparty/racer/issues/57, this has to come at the very beginning. The more limited # the returned fields in motifs, the sooner they must come in fetch / subscribes. publicGroupsQuery = model.query('groups').publicGroups() myGroupsQuery = model.query('groups').withMember(uuid) model.fetch publicGroupsQuery, myGroupsQuery, (err, publicGroups, groups) -> return next(err) if err - model.set '_publicGroups', _.sortBy(publicGroups.get(), (g) -> -_.size(g.members)) finished = (descriptors, paths) -> # Add public "Tavern" guild in - descriptors.push('groups.habitrpg'); paths.push('_habitRPG') + descriptors.unshift('groups.habitrpg'); paths.unshift('_habitRPG') # Subscribe to each descriptor model.subscribe.apply model, descriptors.concat -> @@ -51,9 +49,11 @@ setupSubscriptions = (page, model, params, next, cb) -> unless model.get('_user') console.error "User not found - this shouldn't be happening!" return page.redirect('/logout') #delete model.session.userId - return cb() + # Get public groups first, order most-to-least # subscribers + model.set '_publicGroups', _.sortBy(publicGroups.get(), (g) -> -_.size(g.members)) + groupsObj = groups.get() # (1) Solo player @@ -76,12 +76,15 @@ setupSubscriptions = (page, model, params, next, cb) -> model.set "_membersArray", mObj # Note - selfQ *must* come after membersQ in subscribe, otherwise _user will only get the fields restricted by party-members in store.coffee. Strang bug, but easy to get around - partyQ = model.query('groups').withIds(groupsInfo.partyId) - if _.isEmpty(groupsInfo.guildIds) - finished [partyQ, selfQ], ['_party', '_user'] - else - guildsQ = model.query('groups').withIds(groupsInfo.guildIds) - finished [partyQ, guildsQ, selfQ], ['_party', '_guilds', '_user'] + descriptors = [selfQ]; paths = ['_user'] + if groupsInfo.partyId + descriptors.unshift model.query('groups').withIds(groupsInfo.partyId) + paths.unshift '_party' + unless _.isEmpty(groupsInfo.guildIds) + descriptors.unshift model.query('groups').withIds(groupsInfo.guildIds) + paths.unshift '_guilds' + finished descriptors, paths + # ========== ROUTES ========== diff --git a/src/server/store.coffee b/src/server/store.coffee index df8d3e1b61..4c81c2775c 100644 --- a/src/server/store.coffee +++ b/src/server/store.coffee @@ -109,23 +109,19 @@ groupSystem = (store) -> 'auth.facebook.displayName') store.queryAccess "users", "publicInfo", publicAccess - ### - Fetch group info (ie, they just got invited) - ### - store.query.expose "groups", "withIds", (ids) -> - return unless ids #FIXME this is sometimes null when ids is array (guilds) - if typeof ids is 'string' - @where("id").equals(ids).findOne() # find a single group - else - @where("id").within(ids) # find multiple groups - store.queryAccess "groups", "withIds", publicAccess - ### Read / Write groups, so they can create new groups ### store.readPathAccess "groups.*", publicAccess store.writeAccess "*", "groups.*", publicAccess + ### + Public HabitRPG Guild + ### + store.readPathAccess 'groups.habitrpg', publicAccess + store.writeAccess "*", "groups.habitrpg.chat.*", publicAccess + store.writeAccess "*", "groups.habitrpg.challenges.*", publicAccess + ### Find group which has member by id ### @@ -144,11 +140,12 @@ groupSystem = (store) -> store.queryAccess "groups", "publicGroups", publicAccess ### - Public HabitRPG Guild + Fetch group info (ie, they just got invited) ### - - store.readPathAccess 'groups.habitrpg', publicAccess - store.writeAccess "*", "groups.habitrpg.chat.*", publicAccess - store.writeAccess "*", "groups.habitrpg.challenges.*", publicAccess - - + store.query.expose "groups", "withIds", (ids) -> + return unless ids #FIXME this is sometimes null when ids is array (guilds) + if typeof ids is 'string' + @where("id").equals(ids).findOne() # find a single group + else + @where("id").within(ids) # find multiple groups + store.queryAccess "groups", "withIds", publicAccess \ No newline at end of file diff --git a/views/app/groups.html b/views/app/groups.html index 197c8d08b8..7e5ae23f2e 100644 --- a/views/app/groups.html +++ b/views/app/groups.html @@ -6,22 +6,22 @@
- {{#if _party.id}} + {#if _party.id} - {{else if _user.invitations.party}} + {else if _user.invitations.party}

You're Invited To {_user.invitations.party.name}

{#with _user.invitations.party} Accept Reject {/} - {{else}} + {else}

Create A Party

You are not in a party. You can either create one and invite friends, or if you want to join an existing party, have them enter:

{_user.id}
- {{/}} + {/}