Change keys of array return by Thread::getMessages

This commit is contained in:
Dmitriy Simushev 2012-10-10 13:33:25 +00:00
parent f5a970e50f
commit 38668789b9
5 changed files with 46 additions and 45 deletions

View File

@ -607,48 +607,48 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
// Create messages
// The first
$first_message = array(
'ikind' => Thread::KIND_USER,
'tmessage' => 'The first message',
'kind' => Thread::KIND_USER,
'message' => 'The first message',
'created' => time(),
'tname' => 'System message only for agent'
'name' => 'System message only for agent'
);
// The second
$second_message = array(
'ikind' => Thread::KIND_AGENT,
'tmessage' => 'The second message',
'kind' => Thread::KIND_AGENT,
'message' => 'The second message',
'created' => time(),
'tname' => 'User'
'name' => 'User'
);
// The third
$third_message = array(
'ikind' => Thread::KIND_FOR_AGENT,
'tmessage' => 'The third message',
'kind' => Thread::KIND_FOR_AGENT,
'message' => 'The third message',
'created' => time(),
'tname' => 'Agent'
'name' => 'Agent'
);
// Send messages
// The first
$first_message['messageid'] = $thread->postMessage(
$first_message['ikind'],
$first_message['tmessage'],
$first_message['tname'],
$first_message['id'] = $thread->postMessage(
$first_message['kind'],
$first_message['message'],
$first_message['name'],
12,
$first_message['created']
);
// The second
$second_message['messageid'] = $thread->postMessage(
$second_message['ikind'],
$second_message['tmessage'],
$second_message['tname'],
$second_message['id'] = $thread->postMessage(
$second_message['kind'],
$second_message['message'],
$second_message['name'],
14,
$second_message['created']
);
// The third
$third_message['messageid'] = $thread->postMessage(
$third_message['ikind'],
$third_message['tmessage'],
$third_message['tname'],
$third_message['id'] = $thread->postMessage(
$third_message['kind'],
$third_message['message'],
$third_message['name'],
16,
$third_message['created']
);
@ -660,7 +660,7 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$thread->getMessages(false, $last_id)
);
// Check last message id
$this->assertEquals($third_message['messageid'], $last_id);
$this->assertEquals($third_message['id'], $last_id);
// Check messages for user with ids starts from $msg_id
$last_id = $msg_id;
@ -669,16 +669,16 @@ class ThreadTest extends PHPUnit_Framework_TestCase {
$thread->getMessages(true, $last_id)
);
// Check last message id
$this->assertEquals($second_message['messageid'], $last_id);
$this->assertEquals($second_message['id'], $last_id);
// Check messages for agent with ids starts from first message's id
$last_id = $first_message['messageid'];
$last_id = $first_message['id'];
$this->assertEquals(
array($second_message, $third_message),
$thread->getMessages(false, $last_id)
);
// Check last message id
$this->assertEquals($third_message['messageid'], $last_id);
$this->assertEquals($third_message['id'], $last_id);
// Delete thread
$thread->delete();

View File

@ -28,19 +28,19 @@ function get_user_id()
function message_to_text($msg)
{
if ($msg['ikind'] == Thread::KIND_AVATAR) {
if ($msg['kind'] == Thread::KIND_AVATAR) {
return "";
}
$message_time = date("H:i:s ", $msg['created']);
if ($msg['ikind'] == Thread::KIND_USER || $msg['ikind'] == Thread::KIND_AGENT) {
if ($msg['tname'])
return $message_time . $msg['tname'] . ": " . $msg['tmessage'] . "\n";
if ($msg['kind'] == Thread::KIND_USER || $msg['kind'] == Thread::KIND_AGENT) {
if ($msg['name'])
return $message_time . $msg['name'] . ": " . $msg['message'] . "\n";
else
return $message_time . $msg['tmessage'] . "\n";
} else if ($msg['ikind'] == Thread::KIND_INFO) {
return $message_time . $msg['tmessage'] . "\n";
return $message_time . $msg['message'] . "\n";
} else if ($msg['kind'] == Thread::KIND_INFO) {
return $message_time . $msg['message'] . "\n";
} else {
return $message_time . "[" . $msg['tmessage'] . "]\n";
return $message_time . "[" . $msg['message'] . "]\n";
}
}

View File

@ -391,26 +391,26 @@ Class Thread {
global $webim_encoding;
// No theming for avatars
if ($message['ikind'] == Thread::KIND_AVATAR) {
if ($message['kind'] == Thread::KIND_AVATAR) {
return '';
}
// Prepare messages fields
$creation_date = date("H:i:s", $message['created']);
$kind_name = Thread::kindToString($message['ikind']);
$sender_name = $message['tname']
? "<span class='n{$kind_name}'>" . htmlspecialchars($message['tname']) . "</span>: "
$kind_name = Thread::kindToString($message['kind']);
$sender_name = $message['name']
? "<span class='n{$kind_name}'>" . htmlspecialchars($message['name']) . "</span>: "
: '';
// Prepare message text
// Escape special chars
$text = htmlspecialchars($message['tmessage']);
$text = htmlspecialchars($message['message']);
// Replace URL's by <a> tags
$text = preg_replace('/(https?|ftp):\/\/\S*/', '<a href="$0" target="_blank">$0</a>', $text);
// Add <br> tags instead of \n chars
$text = str_replace("\n", "<br/>", $text);
// Span and storng tags available for system messages
if ($message['ikind'] != Thread::KIND_USER && $message['ikind'] != Thread::KIND_AGENT) {
if ($message['kind'] != Thread::KIND_USER && $message['kind'] != Thread::KIND_AGENT) {
$text = preg_replace('/&lt;(span|strong)&gt;(.*)&lt;\/\1&gt;/U', '<$1>$2</$1>', $text);
$text = preg_replace(
'/&lt;span class=&quot;(.*)&quot;&gt;(.*)&lt;\/span&gt;/U',
@ -675,7 +675,8 @@ Class Thread {
// Load messages
$messages = $db->query(
"select messageid,ikind,dtmcreated as created,tname,tmessage from {chatmessage} " .
"select messageid as id, ikind as kind, dtmcreated as created, tname as name, tmessage as message " .
"from {chatmessage} " .
"where threadid = :threadid and messageid > :lastid " .
($is_user ? "and ikind <> " . self::KIND_FOR_AGENT : "") .
" order by messageid",
@ -688,8 +689,8 @@ Class Thread {
foreach ($messages as $msg) {
// Get last message ID
if ($msg['messageid'] > $last_id) {
$last_id = $msg['messageid'];
if ($msg['id'] > $last_id) {
$last_id = $msg['id'];
}
}

View File

@ -239,7 +239,7 @@ class ThreadProcessor extends RequestProcessor {
if (! empty($messages)) {
foreach($messages as $key => $msg) {
// Check if message is avatar
if ($msg['ikind'] == Thread::KIND_AVATAR) {
if ($msg['kind'] == Thread::KIND_AVATAR) {
// Update avatar
$this->responses[] = array(
'token' => md5(time() . rand()),
@ -251,7 +251,7 @@ class ThreadProcessor extends RequestProcessor {
'token' => $thread->lastToken,
'return' => array(),
'references' => array(),
'imageLink' => $msg['tmessage']
'imageLink' => $msg['message']
)
)
)

View File

@ -54,7 +54,7 @@ if (isset($_GET['threadid'])) {
$lastid = -1;
$messages = $thread_info['thread']->getMessages(false, $lastid);
foreach ($messages as $msg) {
if ($msg['ikind'] == Thread::KIND_AVATAR) {
if ($msg['kind'] == Thread::KIND_AVATAR) {
continue;
}
$page['threadMessages'][] = Thread::themeMessage($msg);