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

View File

@ -32,9 +32,12 @@
var t; 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) { if ($('#messages-region').size() == 0) {
return; return;
} }
@ -43,14 +46,14 @@
var $ava = $('#avatar-region'); var $ava = $('#avatar-region');
// Calculate delta // Calculate delta
if (delta === false) { if (delta === false || recalculateHeight) {
var max = 0; var max = 0;
$('body > *').each(function() { $('body > *').each(function() {
var $el = $(this); var $el = $(this);
var pos = $el.offset(); var pos = $el.offset();
var height = $el.height(); var height = $el.height();
if (max < (pos.top + height)) { if (max < (pos.top + height)) {
max = pos.top + height max = pos.top + height;
} }
}); });
delta = max - $msgs.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) { if (t) {
clearTimeout(t); clearTimeout(t);
} }
t = setTimeout(updateHeight, 0); t = setTimeout(function() {
updateHeight(recalculateHeight || false);
}, 0);
} }
// Stretch messages region after chat page initialize // Stretch messages region after chat page initialize
@ -125,6 +133,12 @@
$el.load(imageLoadCallback); $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); })(Mibew, jQuery);