fix: user session doesn't close because of mibew polling - close chat popup after 10 minute idle

This commit is contained in:
Silron88 2015-08-19 03:12:56 +03:00
parent e650dc64cc
commit 95427ae340
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/*!
* This file is a part of Mibew Messenger.
*
* Copyright 2005-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function (Mibew, _) {
Mibew.Models.AutoChatCloser = Backbone.Model.extend({
defaults: {
timeout: 60 * 10,
last_activity_time: new Date().getTime() / 1000,
activity_timer: null
},
initialize: function () {
this.updateLastActivityTime();
Mibew.Objects.Collections.messages.on('multiple:add', this.updateLastActivityTime, this);
},
updateLastActivityTime: function () {
this.set({last_activity_time: new Date().getTime() / 1000});
var timer = this.get('activity_timer');
if (timer != null) {
clearTimeout(timer);
}
this.setIdleTimer(this.get('timeout'));
},
close_chat_window: function () {
var idleSeconds = (new Date().getTime() / 1000) - this.get('last_activity_time');
if (idleSeconds >= this.get('timeout')) {
Mibew.Utils.closeChatPopup()
} else {
this.setIdleTimer(this.get('timeout') - idleSeconds);
}
},
setIdleTimer: function (timeoutInSec) {
var timer = setTimeout(_.bind(this.close_chat_window, this), timeoutInSec * 1000);
this.set({activity_timer: timer});
}
});
})(Mibew, _);

View File

@ -189,6 +189,10 @@
models.soundManager = new Mibew.Models.ChatSoundManager();
if (!models.user.get('isAgent')){
models.autoCloser = new Mibew.Models.AutoChatCloser();
}
// If the chat is ran inside an iframe we need to tell the parent page
// that the chat is started. This is needed to reopen chat when the user
// navigates to another page.