mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-11-25 18:52:20 -05:00
Make chat state updates less chatty
This commit is contained in:
parent
28914dad11
commit
89d7a39b2f
@ -61,7 +61,6 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
|
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
|
|
||||||
this.typingTimer = null;
|
|
||||||
this.$chatInput = this.$('.chatBox textarea');
|
this.$chatInput = this.$('.chatBox textarea');
|
||||||
this.$chatBox = this.$('.chatBox');
|
this.$chatBox = this.$('.chatBox');
|
||||||
this.$messageList = this.$('.messages');
|
this.$messageList = this.$('.messages');
|
||||||
@ -110,8 +109,6 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
this.resizeInput();
|
this.resizeInput();
|
||||||
},
|
},
|
||||||
handleKeyDown: function (e) {
|
handleKeyDown: function (e) {
|
||||||
clearTimeout(this.typingTimer);
|
|
||||||
|
|
||||||
if (e.which === 13 && !e.shiftKey) {
|
if (e.which === 13 && !e.shiftKey) {
|
||||||
this.sendChat();
|
this.sendChat();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -128,8 +125,9 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
} else if (!e.ctrlKey && !e.metaKey) {
|
} else if (!e.ctrlKey && !e.metaKey) {
|
||||||
if (!this.typing) {
|
if (!this.typing || this.paused) {
|
||||||
this.typing = true;
|
this.typing = true;
|
||||||
|
this.paused = false;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
to: this.model.lockedResource || this.model.jid,
|
to: this.model.lockedResource || this.model.jid,
|
||||||
chatState: 'composing'
|
chatState: 'composing'
|
||||||
@ -139,25 +137,25 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
},
|
},
|
||||||
handleKeyUp: function (e) {
|
handleKeyUp: function (e) {
|
||||||
this.resizeInput();
|
this.resizeInput();
|
||||||
clearTimeout(this.typingTimer);
|
|
||||||
this.typingTimer = setTimeout(this.pausedTyping.bind(this), 5000);
|
|
||||||
if (this.typing && this.$chatInput.val().length === 0) {
|
if (this.typing && this.$chatInput.val().length === 0) {
|
||||||
this.typing = false;
|
this.typing = false;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
to: this.model.lockedResource || this.model.jid,
|
to: this.model.lockedResource || this.model.jid,
|
||||||
chatState: 'active'
|
chatState: 'active'
|
||||||
});
|
});
|
||||||
|
} else if (this.typing) {
|
||||||
|
this.pausedTyping();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pausedTyping: function () {
|
pausedTyping: _.debounce(function () {
|
||||||
if (this.typing) {
|
if (this.typing && !this.paused) {
|
||||||
this.typing = false;
|
this.paused = true;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
to: this.model.lockedResource || this.model.jid,
|
to: this.model.lockedResource || this.model.jid,
|
||||||
chatState: 'paused'
|
chatState: 'paused'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}, 5000),
|
||||||
sendChat: function () {
|
sendChat: function () {
|
||||||
var message;
|
var message;
|
||||||
var val = this.$chatInput.val();
|
var val = this.$chatInput.val();
|
||||||
@ -189,6 +187,7 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
}
|
}
|
||||||
this.editMode = false;
|
this.editMode = false;
|
||||||
this.typing = false;
|
this.typing = false;
|
||||||
|
this.paused = false;
|
||||||
this.$chatInput.removeClass('editing');
|
this.$chatInput.removeClass('editing');
|
||||||
this.$chatInput.val('');
|
this.$chatInput.val('');
|
||||||
},
|
},
|
||||||
|
@ -54,7 +54,6 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
this.rendered = true;
|
this.rendered = true;
|
||||||
|
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
this.typingTimer = null;
|
|
||||||
this.$chatInput = this.$('.chatBox textarea');
|
this.$chatInput = this.$('.chatBox textarea');
|
||||||
this.$chatBox = this.$('.chatBox');
|
this.$chatBox = this.$('.chatBox');
|
||||||
this.$messageList = this.$('.messages');
|
this.$messageList = this.$('.messages');
|
||||||
@ -96,7 +95,6 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
this.resizeInput();
|
this.resizeInput();
|
||||||
},
|
},
|
||||||
handleKeyDown: function (e) {
|
handleKeyDown: function (e) {
|
||||||
clearTimeout(this.typingTimer);
|
|
||||||
if (e.which === 13 && !e.shiftKey) {
|
if (e.which === 13 && !e.shiftKey) {
|
||||||
this.sendChat();
|
this.sendChat();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -113,8 +111,9 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
} else if (!e.ctrlKey && !e.metaKey) {
|
} else if (!e.ctrlKey && !e.metaKey) {
|
||||||
if (!this.typing) {
|
if (!this.typing || this.paused) {
|
||||||
this.typing = true;
|
this.typing = true;
|
||||||
|
this.paused = false;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
type: 'groupchat',
|
type: 'groupchat',
|
||||||
to: this.model.jid,
|
to: this.model.jid,
|
||||||
@ -125,14 +124,16 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
},
|
},
|
||||||
handleKeyUp: function (e) {
|
handleKeyUp: function (e) {
|
||||||
this.resizeInput();
|
this.resizeInput();
|
||||||
this.typingTimer = setTimeout(this.pausedTyping.bind(this), 3000);
|
|
||||||
if (this.typing && this.$chatInput.val().length === 0) {
|
if (this.typing && this.$chatInput.val().length === 0) {
|
||||||
this.typing = false;
|
this.typing = false;
|
||||||
|
this.paused = false;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
type: 'groupchat',
|
type: 'groupchat',
|
||||||
to: this.model.jid,
|
to: this.model.jid,
|
||||||
chatState: 'active'
|
chatState: 'active'
|
||||||
});
|
});
|
||||||
|
} else if (this.typing) {
|
||||||
|
this.pausedTyping();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resizeInput: function () {
|
resizeInput: function () {
|
||||||
@ -158,16 +159,16 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pausedTyping: function () {
|
pausedTyping: _.debounce(function () {
|
||||||
if (this.typing) {
|
if (this.typing && !this.paused) {
|
||||||
this.typing = false;
|
this.paused = true;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
type: 'groupchat',
|
type: 'groupchat',
|
||||||
to: this.model.jid,
|
to: this.model.jid,
|
||||||
chatState: 'paused'
|
chatState: 'paused'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}, 5000),
|
||||||
sendChat: function () {
|
sendChat: function () {
|
||||||
var message;
|
var message;
|
||||||
var val = this.$chatInput.val();
|
var val = this.$chatInput.val();
|
||||||
@ -197,6 +198,7 @@ module.exports = BasePage.extend(chatHelpers).extend({
|
|||||||
}
|
}
|
||||||
this.editMode = false;
|
this.editMode = false;
|
||||||
this.typing = false;
|
this.typing = false;
|
||||||
|
this.paused = false;
|
||||||
this.$chatInput.removeClass('editing');
|
this.$chatInput.removeClass('editing');
|
||||||
this.$chatInput.val('');
|
this.$chatInput.val('');
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
# 0.0.1 1387399967854
|
# 0.0.1 1387404089194
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
/app.js
|
/app.js
|
||||||
|
Loading…
Reference in New Issue
Block a user