diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php index ab48cd13..e6d4d037 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php @@ -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 diff --git a/src/mibew/styles/chats/default/js/source/resize.js b/src/mibew/styles/chats/default/js/source/resize.js index 3afe676e..cf91ec14 100644 --- a/src/mibew/styles/chats/default/js/source/resize.js +++ b/src/mibew/styles/chats/default/js/source/resize.js @@ -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); \ No newline at end of file