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) ->
|
sendChat = (path, input) ->
|
||||||
chat = model.at path
|
chat = model.at path
|
||||||
|
text = model.get input
|
||||||
|
# Check for non-whitespace characters
|
||||||
|
return unless /\S/.test text
|
||||||
chat.unshift
|
chat.unshift
|
||||||
id: model.id()
|
id: model.id()
|
||||||
text: model.get(input)
|
text: text
|
||||||
user: helpers.username(model.get('_user.auth'), model.get('_user.profile.name'))
|
user: helpers.username(model.get('_user.auth'), model.get('_user.profile.name'))
|
||||||
timestamp: +new Date
|
timestamp: +new Date
|
||||||
model.set(input, '')
|
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
|
model.setNull '_tavern.chat', {messages:[]} #we can remove this later, first time run only
|
||||||
sendChat('_tavern.chat.messages', '_tavernMessage')
|
sendChat('_tavern.chat.messages', '_tavernMessage')
|
||||||
|
|
||||||
|
appExports.tavernMessageKeyup = (e, el, next) ->
|
||||||
|
return next() unless e.keyCode is 13
|
||||||
|
appExports.tavernSendChat()
|
||||||
|
|
||||||
app.on 'render', (ctx) ->
|
app.on 'render', (ctx) ->
|
||||||
$('#party-tab-link').on 'shown', (e) ->
|
$('#party-tab-link').on 'shown', (e) ->
|
||||||
messages = model.get('_party.chat')
|
messages = model.get('_party.chat')
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,10 @@
|
||||||
<div class='span6'>
|
<div class='span6'>
|
||||||
<h3>Tavern Talk & LFG</h3>
|
<h3>Tavern Talk & LFG</h3>
|
||||||
<form x-bind='submit:tavernSendChat'>
|
<form x-bind='submit:tavernSendChat'>
|
||||||
<textarea>{_tavernMessage}</textarea><br/>
|
<textarea x-bind='keyup:tavernMessageKeyup'>{_tavernMessage}</textarea><br/>
|
||||||
<input class=btn type=submit value=Submit />
|
<input class=btn type=submit value=Submit />
|
||||||
</form>
|
</form>
|
||||||
<ul class='unstyled'>
|
<ul class='unstyled tavern-chat'>
|
||||||
{#each _tavern.chat.messages as :message}
|
{#each _tavern.chat.messages as :message}
|
||||||
<li>
|
<li>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue