mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 03:30:25 +00:00
Merge pull request #887 from switz/chat
@lefnire => Send chat message on enter and disallow empty messages
This commit is contained in:
commit
2a03d033d8
2 changed files with 10 additions and 3 deletions
|
|
@ -161,9 +161,12 @@ module.exports.app = (appExports, model, app) ->
|
|||
|
||||
sendChat = (path, input) ->
|
||||
chat = model.at path
|
||||
text = model.get input
|
||||
# Check for non-whitespace characters
|
||||
return unless /\S/.test text
|
||||
chat.unshift
|
||||
id: model.id()
|
||||
text: model.get(input)
|
||||
text: text
|
||||
user: helpers.username(model.get('_user.auth'), model.get('_user.profile.name'))
|
||||
timestamp: +new Date
|
||||
model.set(input, '')
|
||||
|
|
@ -177,6 +180,10 @@ module.exports.app = (appExports, model, app) ->
|
|||
model.setNull '_tavern.chat', {messages:[]} #we can remove this later, first time run only
|
||||
sendChat('_tavern.chat.messages', '_tavernMessage')
|
||||
|
||||
appExports.tavernMessageKeyup = (e, el, next) ->
|
||||
return next() unless e.keyCode is 13
|
||||
appExports.tavernSendChat()
|
||||
|
||||
app.on 'render', (ctx) ->
|
||||
$('#party-tab-link').on 'shown', (e) ->
|
||||
messages = model.get('_party.chat')
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@
|
|||
<div class='span6'>
|
||||
<h3>Tavern Talk & LFG</h3>
|
||||
<form x-bind='submit:tavernSendChat'>
|
||||
<textarea>{_tavernMessage}</textarea><br/>
|
||||
<textarea x-bind='keyup:tavernMessageKeyup'>{_tavernMessage}</textarea><br/>
|
||||
<input class=btn type=submit value=Submit />
|
||||
</form>
|
||||
<ul class='unstyled'>
|
||||
<ul class='unstyled tavern-chat'>
|
||||
{#each _tavern.chat.messages as :message}
|
||||
<li>
|
||||
<hr/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue