Forbid users to post to closed threads

Fixes #72
This commit is contained in:
Dmitriy Simushev 2014-11-06 13:13:29 +00:00
parent b4ab5d8cd1
commit 6b3b5d6fec
2 changed files with 31 additions and 10 deletions

View File

@ -361,11 +361,14 @@ class ThreadProcessor extends ClientSideProcessor implements
if ($args['user']) {
$is_typing = abs($thread->lastPingAgent - time()) < Thread::CONNECTION_TIMEOUT
&& $thread->agentTyping;
// Users can post messages only when thread is open.
$can_post = $thread->state != Thread::STATE_CLOSED;
} else {
$is_typing = abs($thread->lastPingUser - time()) < Thread::CONNECTION_TIMEOUT
&& $thread->userTyping;
// Operators can always post messages.
$can_post = true;
}
$can_post = $args['user'] || $operator['operatorid'] == $thread->agentId;
return array(
'threadState' => $thread->state,
@ -433,10 +436,14 @@ class ThreadProcessor extends ClientSideProcessor implements
// Get operator's array
if (!$args['user']) {
$operator = $this->checkOperator();
// Operators can always post messages.
$can_post = true;
} else {
// Users can post messages only when a thread is open.
$can_post = $thread->state != Thread::STATE_CLOSED;
}
// Check message can be sent
if (!$args['user'] && $operator['operatorid'] != $thread->agentId) {
if (!$can_post) {
throw new ThreadProcessorException(
"Cannot send",
ThreadProcessorException::ERROR_CANNOT_SEND

View File

@ -32,9 +32,12 @@
var t;
/**
* Stretch #messages-region to fill the window
* Stretch #messages-region to fill the window.
*
* @param {Boolean} recalculateHeight Indicates if height of elements must
* be recalculated. It can be usefull when elements set is changed.
*/
var updateHeight = function() {
var updateHeight = function(recalculateHeight) {
if ($('#messages-region').size() == 0) {
return;
}
@ -43,14 +46,14 @@
var $ava = $('#avatar-region');
// Calculate delta
if (delta === false) {
if (delta === false || recalculateHeight) {
var max = 0;
$('body > *').each(function() {
var $el = $(this);
var pos = $el.offset();
var height = $el.height();
if (max < (pos.top + height)) {
max = pos.top + height
max = pos.top + height;
}
});
delta = max - $msgs.height();
@ -73,13 +76,18 @@
}
/**
* Fix bug with window resize event
* Fix bug with window resize event.
*
* @param {Boolean} recalculateHeight Indicates if height of elements must
* be recalculated. The default value is false.
*/
var updateHeightWrapper = function() {
var updateHeightWrapper = function(recalculateHeight) {
if (t) {
clearTimeout(t);
}
t = setTimeout(updateHeight, 0);
t = setTimeout(function() {
updateHeight(recalculateHeight || false);
}, 0);
}
// Stretch messages region after chat page initialize
@ -125,6 +133,12 @@
$el.load(imageLoadCallback);
}
});
// Change of user's "canPost" field changes visibility of message input
// form. Thus we should manually update the height.
Mibew.Objects.Models.user.on('change:canPost', function() {
updateHeightWrapper(true);
});
});
})(Mibew, jQuery);