add tavern chat

This commit is contained in:
Tyler Renelle 2013-05-02 21:09:50 +01:00
parent c3eadab4dc
commit c48d6bde13
4 changed files with 51 additions and 14 deletions

View file

@ -39,6 +39,7 @@ module.exports.partySubscribe = partySubscribe = (page, model, params, next, cb)
return page.redirect('/logout') #delete model.session.userId
finished = (descriptors, paths) ->
descriptors.push 'tavern'; paths.push '_tavern'
model.subscribe.apply model, descriptors.concat ->
[err, refs] = [arguments[0], arguments]
return next(err) if err
@ -158,17 +159,24 @@ module.exports.app = (appExports, model, app) ->
Chat Functionality
###
appExports.partySendChat = ->
chat = model.at '_party.chat'
sendChat = (path, input) ->
chat = model.at path
chat.unshift
id: model.id()
text: model.get('_chatMessage')
text: model.get(input)
user: helpers.username(model.get('_user.auth'), model.get('_user.profile.name'))
timestamp: +new Date
, -> model.set('_chatMessage', '')
model.set '_user.party.lastMessageSeen', chat.get()[0].id
model.set(input, '')
chat.remove 200 # keep a max messages cap
appExports.partySendChat = ->
sendChat('_party.chat', '_chatMessage')
model.set '_user.party.lastMessageSeen', model.get('_party.chat')[0].id
appExports.tavernSendChat = ->
model.setNull '_tavern.chat', {messages:[]} #we can remove this later, first time run only
sendChat('_tavern.chat.messages', '_tavernMessage')
app.on 'render', (ctx) ->
$('#party-tab-link').on 'shown', (e) ->
messages = model.get('_party.chat')

View file

@ -8,6 +8,7 @@ Setup read / write access
module.exports.customAccessControl = (store) ->
userAccess(store)
partySystem(store)
tavernSystem(store)
REST(store)
###
@ -115,3 +116,18 @@ partySystem = (store) ->
# return err(derbyAuth.SESSION_INVALIDATED_ERROR) if derbyAuth.bustedSession(@)
return accept(false) if derbyAuth.bustedSession(@)
accept(true)
###
LFG / tavern system
###
tavernSystem = (store) ->
store.readPathAccess 'tavern', ->
accept = arguments[arguments.length-2]
return accept(false) if derbyAuth.bustedSession(@)
accept(true)
store.writeAccess "*", "tavern.*", ->
accept = arguments[arguments.length-2]
return accept(false) if derbyAuth.bustedSession(@)
accept(true)

View file

@ -7,9 +7,7 @@
<ul class="nav nav-tabs game-tabs">
<li class="active"><a data-toggle='tab' data-target="#profileCustomize"><i class='icon-user'></i> Profile</a></li>
<li class='{#if _user.party.invitation}tab-notification{/}'>
<a data-toggle='tab' data-target="#profileParty" id='party-tab-link'><i class='icon-heart'></i> Party</a>
</li>
<li><a data-toggle='tab' data-target="#profileParty" id='party-tab-link'><i class='icon-heart'></i> Party</a></li>
{#if _user.flags.dropsEnabled}
<li><a data-toggle='tab' data-target="#profileInventory"><i class='icon-gift'></i> Inventory</a></li>
<li><a data-toggle='tab' data-target="#profileStable"><i class='icon-leaf'></i> Stable</a></li>
@ -74,15 +72,13 @@
<tavern:>
<div class='row-fluid tavern-pane'>
<div class='span6'>
<div class='span6 border-right'>
<img src='/img/npcs/daniel.png' />
<div class="popover fade right in" style="top: 0px; left: 135px; display: block;">
<div class="arrow"></div>
<h3 class="popover-title">Daniel Johansson</h3>
<div class="popover-content">Welcome to the Tavern! I'm the bar keep, <a target="_blank" href="http://www.kickstarter.com/profile/2014640723">Daniel</a>. If you would like to rest a while (going on vacation?), I can set you up at the inn for 10gp. While you're resting, your dailies won't hurt you. The minimum stay is 24h, but you can check out whenever you want. In the future, you may find other adventurers here, looking meet and mingle (LFG anyone?)</div>
</div>
</div>
<div class='span6'>
<form>
<fieldset>
<label class="checkbox">
@ -90,7 +86,22 @@
</label>
</fieldset>
</form>
</div>
<div class='span6'>
<h3>Tavern Talk & LFG</h3>
<form x-bind='submit:tavernSendChat'>
<textarea>{_tavernMessage}</textarea><br/>
<input class=btn type=submit value=Submit />
</form>
<ul class='unstyled'>
{#each _tavern.chat.messages as :message}
<li>
<hr/>
<span class='badge'>{:message.user}</span> {:message.text} - <span class='muted'>{friendlyTimestamp(:message.timestamp)}</span>
</li>
{/}
</ul>
</div>
</div>
</div>

View file

@ -27,8 +27,10 @@
</form>
<ul class='unstyled'>
{#each _party.chat as :message}
<hr/>
<li><span class='badge'>{:message.user}</span> {:message.text} - <span class='muted'>{friendlyTimestamp(:message.timestamp)}</span></li>
<li>
<hr/>
<span class='badge'>{:message.user}</span> {:message.text} - <span class='muted'>{friendlyTimestamp(:message.timestamp)}</span>
</li>
{/}
</ul>
</div>