There is no KIND_AVATAR message kind any more

This commit is contained in:
Dmitriy Simushev 2013-02-06 14:29:37 +00:00
parent bf564e55ef
commit 0054423407
9 changed files with 62 additions and 91 deletions

View File

@ -2,6 +2,7 @@
require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/thread.php'; require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/thread.php';
require_once dirname(__FILE__) . '/../../../../../webim/libs/classes/database.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/classes/settings.php';
require_once dirname(__FILE__) . '/../../../../../webim/libs/common/locale.php'; require_once dirname(__FILE__) . '/../../../../../webim/libs/common/locale.php';
require_once dirname(__FILE__) . '/../config.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_info['istate']);
$this->assertEquals(Thread::STATE_CHATTING, $thread->state); $this->assertEquals(Thread::STATE_CHATTING, $thread->state);
// Check sent messages // Check sent message
$this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id));
// Check messages text: // Check messages text:
// Thread::KIND_EVENTS message // Thread::KIND_EVENTS message
@ -770,10 +771,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$last_msg_id $last_msg_id
); );
$this->assertEquals(1, $message_count); $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 // Update last message id
$last_msg_id = $this->_helper_getLastMessageId(); $last_msg_id = $this->_helper_getLastMessageId();
@ -1141,8 +1138,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
// Check chat started time // Check chat started time
$this->assertFalse(empty($thread->chatStarted)); $this->assertFalse(empty($thread->chatStarted));
$this->assertFalse(empty($thread_info['dtmchatstarted'])); $this->assertFalse(empty($thread_info['dtmchatstarted']));
// Two messages must be sent // One messages must be sent
$this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id));
// Check messages text // Check messages text
$message_count = $this->_helper_getMessagesCount( $message_count = $this->_helper_getMessagesCount(
Thread::KIND_EVENTS, Thread::KIND_EVENTS,
@ -1154,13 +1151,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$last_msg_id $last_msg_id
); );
$this->assertEquals(1, $message_count); $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 // Get last message id
$last_msg_id = $this->_helper_getLastMessageId(); $last_msg_id = $this->_helper_getLastMessageId();
@ -1178,8 +1168,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
// Check agent id // Check agent id
$this->assertEquals(2, $thread->agentId); $this->assertEquals(2, $thread->agentId);
$this->assertEquals(2, $thread_info['agentId']); $this->assertEquals(2, $thread_info['agentId']);
// Two messages must be sent // One message must be sent
$this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id));
// Check messages text // Check messages text
$message_count = $this->_helper_getMessagesCount( $message_count = $this->_helper_getMessagesCount(
Thread::KIND_EVENTS, Thread::KIND_EVENTS,
@ -1187,13 +1177,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$last_msg_id $last_msg_id
); );
$this->assertEquals(1, $message_count); $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 // Get last message id
$last_msg_id = $this->_helper_getLastMessageId(); $last_msg_id = $this->_helper_getLastMessageId();
@ -1210,8 +1193,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
// Check thread state // Check thread state
$this->assertEquals(Thread::STATE_CHATTING, $thread->state); $this->assertEquals(Thread::STATE_CHATTING, $thread->state);
$this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']);
// Two messages must be sent // One message must be sent
$this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id));
// Check messages text // Check messages text
$message_count = $this->_helper_getMessagesCount( $message_count = $this->_helper_getMessagesCount(
Thread::KIND_EVENTS, Thread::KIND_EVENTS,
@ -1223,12 +1206,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$last_msg_id $last_msg_id
); );
$this->assertEquals(1, $message_count); $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 // Get last message id
@ -1244,8 +1221,8 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
// Check thread state // Check thread state
$this->assertEquals(Thread::STATE_CHATTING, $thread->state); $this->assertEquals(Thread::STATE_CHATTING, $thread->state);
$this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']);
// Two messages must be sent // One message must be sent
$this->assertEquals(2, $this->_helper_getTotalMessagesCount($last_msg_id)); $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id));
// Check messages text // Check messages text
$message_count = $this->_helper_getMessagesCount( $message_count = $this->_helper_getMessagesCount(
Thread::KIND_EVENTS, Thread::KIND_EVENTS,
@ -1253,13 +1230,6 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$last_msg_id $last_msg_id
); );
$this->assertEquals(1, $message_count); $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 // Delete thread
$thread->delete(); $thread->delete();

View File

@ -0,0 +1,13 @@
<?php
class ThreadProcessor {
public static function getInstance() {
return new self();
}
public function call($functions = null, $callback = null) {
return true;
}
}
?>

View File

@ -5,4 +5,4 @@
Copyright (c) 2005-2011 Mibew Messenger Community Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php 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);

View File

@ -67,7 +67,7 @@ b.Server.prototype.registerFunction=function(a,b){a in this.functions||(this.fun
Copyright (c) 2005-2011 Mibew Messenger Community Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php 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. This file is part of Mibew Messenger project.
http://mibew.org http://mibew.org

View File

@ -43,14 +43,7 @@
KIND_CONN: 5, KIND_CONN: 5,
/** System message about some events (like rename). */ /** System message about some events (like rename). */
KIND_EVENTS: 6, KIND_EVENTS: 6
/**
* Message with operators avatar
*
* This kind of message leaved only for compatibility with core
*/
KIND_AVATAR: 7
/** End of message kind constants */ /** End of message kind constants */
} }

View File

@ -17,6 +17,13 @@
require_once(dirname(__FILE__).'/track.php'); require_once(dirname(__FILE__).'/track.php');
require_once(dirname(__FILE__).'/classes/thread.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"; $namecookie = "WEBIM_Data";
$usercookie = "WEBIM_UserID"; $usercookie = "WEBIM_UserID";
@ -28,9 +35,6 @@ function get_user_id()
function message_to_text($msg) function message_to_text($msg)
{ {
if ($msg['kind'] == Thread::KIND_AVATAR) {
return "";
}
$message_time = date("H:i:s ", $msg['created']); $message_time = date("H:i:s ", $msg['created']);
if ($msg['kind'] == Thread::KIND_USER || $msg['kind'] == Thread::KIND_AGENT) { if ($msg['kind'] == Thread::KIND_USER || $msg['kind'] == Thread::KIND_AGENT) {
if ($msg['name']) if ($msg['name'])

View File

@ -71,10 +71,6 @@ Class Thread {
* System message about some events (like rename). * System message about some events (like rename).
*/ */
const KIND_EVENTS = 6; const KIND_EVENTS = 6;
/**
* Message with operators avatar
*/
const KIND_AVATAR = 7;
/** /**
* Messaging window connection timeout. * Messaging window connection timeout.
@ -601,7 +597,9 @@ Class Thread {
// Send messages // Send messages
$this->postMessage(self::KIND_EVENTS, $message_to_post); $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_INFO
* @see Thread::KIND_CONN * @see Thread::KIND_CONN
* @see Thread::KIND_EVENTS * @see Thread::KIND_EVENTS
* @see Thread::KIND_AVATAR
* @see Thread::getMessages() * @see Thread::getMessages()
*/ */
public function postMessage($kind, $message, $from = null, $opid = null, $time = null) { public function postMessage($kind, $message, $from = null, $opid = null, $time = null) {
@ -783,7 +780,9 @@ Class Thread {
// Send message // Send message
if ($message) { if ($message) {
$this->postMessage(self::KIND_EVENTS, $message); $this->postMessage(self::KIND_EVENTS, $message);
$this->postMessage(self::KIND_AVATAR, $operator['vcavatar'] ? $operator['vcavatar'] : ""); $this->setupAvatar(
$operator['vcavatar'] ? $operator['vcavatar'] : ""
);
} }
return true; return true;
} }
@ -811,6 +810,27 @@ Class Thread {
$this->postMessage(self::KIND_EVENTS, $message); $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
)
)
));
}
} }
?> ?>

View File

@ -216,29 +216,6 @@ class ThreadProcessor extends ClientSideProcessor {
protected function sendMessages(Thread $thread, $is_user, $last_message_id) { protected function sendMessages(Thread $thread, $is_user, $last_message_id) {
$messages = $thread->getMessages($is_user, $last_message_id); $messages = $thread->getMessages($is_user, $last_message_id);
if (! empty($messages)) { 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 // Send messages
$this->responses[] = array( $this->responses[] = array(
'token' => md5(time() . rand()), 'token' => md5(time() . rand()),

View File

@ -53,13 +53,7 @@ if (isset($_GET['threadid'])) {
// Build messages list // Build messages list
$lastid = -1; $lastid = -1;
$messages = $thread_info['thread']->getMessages(false, $lastid); $messages = $thread_info['thread']->getMessages(false, $lastid);
$result = array(); $page['threadMessages'] = json_encode($messages);
foreach ($messages as $msg) {
if ($msg['kind'] != Thread::KIND_AVATAR) {
$result[] = $msg;
}
}
$page['threadMessages'] = json_encode($result);
} }
prepare_menu($operator, false); prepare_menu($operator, false);