add tavern chat
This commit is contained in:
+13
-5
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user