groups: bug fixes: {#if _party} dynamic binding, subscription allowed

for either party or guild with out requiring the other
This commit is contained in:
Tyler Renelle
2013-06-03 14:08:54 -04:00
parent fbcf21cd9d
commit f8e546ae2a
3 changed files with 32 additions and 32 deletions
+13 -10
View File
@@ -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 ==========
+15 -18
View File
@@ -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
+4 -4
View File
@@ -6,22 +6,22 @@
<div class="tab-content">
<div class="tab-pane active" id="groups-party">
{{#if _party.id}} <!-- user in a party? -->
{#if _party.id} <!-- user in a party? -->
<app:groups:group group={groups[_party.id]} />
{{else if _user.invitations.party}}
{else if _user.invitations.party}
<!-- TODO show by whom -->
<h2>You're Invited To {_user.invitations.party.name}</h2>
{#with _user.invitations.party}
<a class='btn btn-success' data-type='party' x-bind="click:acceptInvitation">Accept</a>
<a class='btn btn-danger' x-bind="click:rejectInvitation">Reject</a>
{/}
{{else}}
{else}
<h2>Create A Party</h2>
<!-- Not in a party , no invites - create a new one -->
<p>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:</p>
<pre class=prettyprint>{_user.id}</pre>
<app:groups:create-group type='party' />
{{/}}
{/}
</div>
<div class='tab-pane' id="groups-guilds">