diff --git a/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php b/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php index 35848329..4880ce24 100644 --- a/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php +++ b/src/messenger/tests/server_side/webim/libs/classes/ThreadTest.php @@ -2,6 +2,7 @@ require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/thread.php'; require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/database.php'; +require_once dirname(__FILE__) . '/thread_processor_mock.php'; require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/settings.php'; require_once dirname(__FILE__) . '/../../../../../webim/libs/common/locale.php'; require_once dirname(__FILE__) . '/../config.php'; @@ -759,8 +760,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - // Check sent messages - $this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); + // Check sent message + $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); // Check messages text: // Thread::KIND_EVENTS message @@ -770,10 +771,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $last_msg_id ); $this->assertEquals(1, $message_count); - // Thread::KIND_AVATAR message - $message_count = $this->_helper_getMessagesCount(Thread::KIND_AVATAR, 'avatar', $last_msg_id); - $this->assertEquals(1, $message_count); - // Update last message id $last_msg_id = $this->_helper_getLastMessageId(); @@ -1141,8 +1138,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase { // Check chat started time $this->assertFalse(empty($thread->chatStarted)); $this->assertFalse(empty($thread_info['dtmchatstarted'])); - // Two messages must be sent - $this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); + // One messages must be sent + $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); // Check messages text $message_count = $this->_helper_getMessagesCount( Thread::KIND_EVENTS, @@ -1154,13 +1151,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $last_msg_id ); $this->assertEquals(1, $message_count); - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_AVATAR, - $operator['vcavatar'], - $last_msg_id - ); - $this->assertEquals(1, $message_count); - // Get last message id $last_msg_id = $this->_helper_getLastMessageId(); @@ -1178,8 +1168,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase { // Check agent id $this->assertEquals(2, $thread->agentId); $this->assertEquals(2, $thread_info['agentId']); - // Two messages must be sent - $this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); + // One message must be sent + $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); // Check messages text $message_count = $this->_helper_getMessagesCount( Thread::KIND_EVENTS, @@ -1187,13 +1177,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $last_msg_id ); $this->assertEquals(1, $message_count); - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_AVATAR, - $operator['vcavatar'], - $last_msg_id - ); - $this->assertEquals(1, $message_count); - // Get last message id $last_msg_id = $this->_helper_getLastMessageId(); @@ -1210,8 +1193,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase { // Check thread state $this->assertEquals(Thread::STATE_CHATTING, $thread->state); $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // Two messages must be sent - $this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); + // One message must be sent + $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); // Check messages text $message_count = $this->_helper_getMessagesCount( Thread::KIND_EVENTS, @@ -1223,12 +1206,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $last_msg_id ); $this->assertEquals(1, $message_count); - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_AVATAR, - $operator['vcavatar'], - $last_msg_id - ); - $this->assertEquals(1, $message_count); // Get last message id @@ -1244,8 +1221,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase { // Check thread state $this->assertEquals(Thread::STATE_CHATTING, $thread->state); $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // Two messages must be sent - $this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); + // One message must be sent + $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); // Check messages text $message_count = $this->_helper_getMessagesCount( Thread::KIND_EVENTS, @@ -1253,13 +1230,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase { $last_msg_id ); $this->assertEquals(1, $message_count); - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_AVATAR, - $operator['vcavatar'], - $last_msg_id - ); - $this->assertEquals(1, $message_count); - // Delete thread $thread->delete(); diff --git a/src/messenger/tests/server_side/webim/libs/classes/thread_processor_mock.php b/src/messenger/tests/server_side/webim/libs/classes/thread_processor_mock.php new file mode 100644 index 00000000..18e029fc --- /dev/null +++ b/src/messenger/tests/server_side/webim/libs/classes/thread_processor_mock.php @@ -0,0 +1,13 @@ + diff --git a/src/messenger/webim/js/compiled/default/models/message.js b/src/messenger/webim/js/compiled/default/models/message.js index 703ada14..0f324af7 100644 --- a/src/messenger/webim/js/compiled/default/models/message.js +++ b/src/messenger/webim/js/compiled/default/models/message.js @@ -5,4 +5,4 @@ Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew); +(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6})})(Mibew); diff --git a/src/messenger/webim/js/compiled/default_app.js b/src/messenger/webim/js/compiled/default_app.js index 61bc2314..e0ee4214 100644 --- a/src/messenger/webim/js/compiled/default_app.js +++ b/src/messenger/webim/js/compiled/default_app.js @@ -67,7 +67,7 @@ b.Server.prototype.registerFunction=function(a,b){a in this.functions||(this.fun Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ -(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6,KIND_AVATAR:7})})(Mibew); +(function(a){a.Models.Message=a.Models.Base.extend({defaults:{message:""},KIND_USER:1,KIND_AGENT:2,KIND_FOR_AGENT:3,KIND_INFO:4,KIND_CONN:5,KIND_EVENTS:6})})(Mibew); /* This file is part of Mibew Messenger project. http://mibew.org diff --git a/src/messenger/webim/js/source/default/models/message.js b/src/messenger/webim/js/source/default/models/message.js index 6f42c423..4fabf193 100644 --- a/src/messenger/webim/js/source/default/models/message.js +++ b/src/messenger/webim/js/source/default/models/message.js @@ -43,14 +43,7 @@ KIND_CONN: 5, /** System message about some events (like rename). */ - KIND_EVENTS: 6, - - /** - * Message with operators avatar - * - * This kind of message leaved only for compatibility with core - */ - KIND_AVATAR: 7 + KIND_EVENTS: 6 /** End of message kind constants */ } diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 00bcf34a..5ce9dbe2 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -17,6 +17,13 @@ require_once(dirname(__FILE__).'/track.php'); require_once(dirname(__FILE__).'/classes/thread.php'); +require_once(dirname(__FILE__).'/classes/mibew_api.php'); +require_once(dirname(__FILE__).'/classes/mibew_api_interaction.php'); +require_once(dirname(__FILE__).'/classes/mibew_api_chat_interaction.php'); +require_once(dirname(__FILE__).'/classes/mibew_api_execution_context.php'); +require_once(dirname(__FILE__).'/classes/request_processor.php'); +require_once(dirname(__FILE__).'/classes/client_side_processor.php'); +require_once(dirname(__FILE__).'/classes/thread_processor.php'); $namecookie = "WEBIM_Data"; $usercookie = "WEBIM_UserID"; @@ -28,9 +35,6 @@ function get_user_id() function message_to_text($msg) { - if ($msg['kind'] == Thread::KIND_AVATAR) { - return ""; - } $message_time = date("H:i:s ", $msg['created']); if ($msg['kind'] == Thread::KIND_USER || $msg['kind'] == Thread::KIND_AGENT) { if ($msg['name']) diff --git a/src/messenger/webim/libs/classes/thread.php b/src/messenger/webim/libs/classes/thread.php index 51175812..3e304d2e 100644 --- a/src/messenger/webim/libs/classes/thread.php +++ b/src/messenger/webim/libs/classes/thread.php @@ -71,10 +71,6 @@ Class Thread { * System message about some events (like rename). */ const KIND_EVENTS = 6; - /** - * Message with operators avatar - */ - const KIND_AVATAR = 7; /** * Messaging window connection timeout. @@ -601,7 +597,9 @@ Class Thread { // Send messages $this->postMessage(self::KIND_EVENTS, $message_to_post); - $this->postMessage(self::KIND_AVATAR, $operator['vcavatar'] ? $operator['vcavatar'] : ""); + $this->setupAvatar( + $operator['vcavatar'] ? $operator['vcavatar'] : "" + ); } } @@ -662,7 +660,6 @@ Class Thread { * @see Thread::KIND_INFO * @see Thread::KIND_CONN * @see Thread::KIND_EVENTS - * @see Thread::KIND_AVATAR * @see Thread::getMessages() */ public function postMessage($kind, $message, $from = null, $opid = null, $time = null) { @@ -783,7 +780,9 @@ Class Thread { // Send message if ($message) { $this->postMessage(self::KIND_EVENTS, $message); - $this->postMessage(self::KIND_AVATAR, $operator['vcavatar'] ? $operator['vcavatar'] : ""); + $this->setupAvatar( + $operator['vcavatar'] ? $operator['vcavatar'] : "" + ); } return true; } @@ -811,6 +810,27 @@ Class Thread { $this->postMessage(self::KIND_EVENTS, $message); } } + + /** + * Set operator avatar in the user's chat window + * @param string $link URL of the new operator avatar + */ + protected function setupAvatar($link) { + $processor = ThreadProcessor::getInstance(); + $processor->call(array( + array( + 'function' => 'setupAvatar', + 'arguments' => array( + 'threadId' => $this->id, + 'token' => $this->lastToken, + 'return' => array(), + 'references' => array(), + 'recipient' => 'user', + 'imageLink' => $link + ) + ) + )); + } } ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/classes/thread_processor.php b/src/messenger/webim/libs/classes/thread_processor.php index a1b9a1b5..d49c0be1 100644 --- a/src/messenger/webim/libs/classes/thread_processor.php +++ b/src/messenger/webim/libs/classes/thread_processor.php @@ -216,29 +216,6 @@ class ThreadProcessor extends ClientSideProcessor { protected function sendMessages(Thread $thread, $is_user, $last_message_id) { $messages = $thread->getMessages($is_user, $last_message_id); if (! empty($messages)) { - foreach($messages as $key => $msg) { - // Check if message is avatar - if ($msg['kind'] == Thread::KIND_AVATAR) { - // Update avatar - $this->responses[] = array( - 'token' => md5(time() . rand()), - 'functions' => array( - array( - 'function' => 'setupAvatar', - 'arguments' => array( - 'threadId' => $thread->id, - 'token' => $thread->lastToken, - 'return' => array(), - 'references' => array(), - 'imageLink' => $msg['message'] - ) - ) - ) - ); - unset($messages[$key]); - continue; - } - } // Send messages $this->responses[] = array( 'token' => md5(time() . rand()), diff --git a/src/messenger/webim/operator/threadprocessor.php b/src/messenger/webim/operator/threadprocessor.php index e7178261..e3fd2272 100644 --- a/src/messenger/webim/operator/threadprocessor.php +++ b/src/messenger/webim/operator/threadprocessor.php @@ -53,13 +53,7 @@ if (isset($_GET['threadid'])) { // Build messages list $lastid = -1; $messages = $thread_info['thread']->getMessages(false, $lastid); - $result = array(); - foreach ($messages as $msg) { - if ($msg['kind'] != Thread::KIND_AVATAR) { - $result[] = $msg; - } - } - $page['threadMessages'] = json_encode($result); + $page['threadMessages'] = json_encode($messages); } prepare_menu($operator, false);