diff --git a/src/messenger/webim/js/164/chat.js b/src/messenger/webim/js/164/chat.js index c25c2a8d..d3d2926f 100644 --- a/src/messenger/webim/js/164/chat.js +++ b/src/messenger/webim/js/164/chat.js @@ -1,25 +1,30 @@ /* This file is part of Mibew Messenger project. http://mibew.org - + Copyright (c) 2005-2011 Mibew Messenger Community License: http://mibew.org/license.php */ var FrameUtils={getDocument:function(a){return a.contentDocument?a.contentDocument:a.contentWindow?a.contentWindow.document:a.document?a.document:null},initFrame:function(a){var b=this.getDocument(a);b.open();b.write("");b.write('');b.write("");b.write("
"); -b.write("");b.close();a.onload=function(){a.myHtml&&(FrameUtils.getDocument(a).getElementById("content").innerHTML+=a.myHtml,FrameUtils.scrollDown(a))}},insertIntoFrame:function(a,b){var c=this.getDocument(a).getElementById("content");if(null==c){if(!a.myHtml)a.myHtml="";a.myHtml+=b}else c.innerHTML+=b},scrollDown:function(a){var b=this.getDocument(a).getElementById("bottom");if("opera"==myAgent)try{a.contentWindow.scrollTo(0,this.getDocument(a).getElementById("content").clientHeight)}catch(c){}b&& -b.scrollIntoView(!1)}};Ajax.ChatThreadUpdater=Class.create(); -Class.inherit(Ajax.ChatThreadUpdater,Ajax.Base,{initialize:function(a){this.setOptions(a);this._options.onComplete=this.requestComplete.bind(this);this._options.onException=this.handleException.bind(this);this._options.onTimeout=this.handleTimeout.bind(this);this._options.timeout=5E3;this.updater={};this.frequency=this._options.frequency||2;this.lastupdate=0;this.focused=this.skipNextsound=this.cansend=!0;this.ownThread=null!=this._options.message;FrameUtils.initFrame(this._options.container);if(this._options.message)this._options.message.onkeydown= -this.handleKeyDown.bind(this),this._options.message.onfocus=function(){this.focused=!0}.bind(this),this._options.message.onblur=function(){this.focused=!1}.bind(this);this.update()},handleException:function(){this.setStatus("offline, reconnecting");this.stopUpdate();this.timer=setTimeout(this.update.bind(this),1E3)},handleTimeout:function(){this.setStatus("timeout, reconnecting");this.stopUpdate();this.timer=setTimeout(this.update.bind(this),1E3)},updateOptions:function(a){this._options.parameters= -"act="+a+"&thread="+(this._options.threadid||0)+"&token="+(this._options.token||0)+"&lastid="+(this._options.lastid||0);this._options.user&&(this._options.parameters+="&user=true");"refresh"==a&&this._options.message&&""!=this._options.message.value&&(this._options.parameters+="&typed=1")},enableInput:function(a){if(this._options.message)this._options.message.disabled=!a},stopUpdate:function(){this.enableInput(!0);if(this.updater._options)this.updater._options.onComplete=void 0;clearTimeout(this.timer)}, -update:function(){this.updateOptions("refresh");this.updater=new Ajax.Request(this._options.servl,this._options)},requestComplete:function(a){try{this.enableInput(!0);this.cansend=!0;var b=Ajax.getXml(a);b&&"thread"==b.tagName?this.updateContent(b):this.handleError(a,b,"refresh messages failed")}catch(c){}this.skipNextsound=!1;this.timer=setTimeout(this.update.bind(this),1E3*this.frequency)},postMessage:function(a){if(""!=a&&this.cansend){this.cansend=!1;this.stopUpdate();this.skipNextsound=!0;this.updateOptions("post"); -var b={}.extend(this._options);b.parameters+="&message="+encodeURIComponent(a);b.onComplete=function(a){this.requestComplete(a);if(this._options.message)this._options.message.value="",this._options.message.focus()}.bind(this);"opera"!=myRealAgent&&this.enableInput(!1);this.updater=new Ajax.Request(this._options.servl,b)}},changeName:function(a){this.skipNextsound=!0;new Ajax.Request(this._options.servl,{parameters:"act=rename&thread="+(this._options.threadid||0)+"&token="+(this._options.token||0)+ -"&name="+encodeURIComponent(a)})},onThreadClosed:function(a){var b=Ajax.getXml(a);b&&"closed"==b.tagName?setTimeout("window.close()",2E3):this.handleError(a,b,"cannot close")},closeThread:function(){if("undefined"!=typeof Chat.localizedStrings.closeConfirmation&&Chat.localizedStrings.closeConfirmation&&!confirm(Chat.localizedStrings.closeConfirmation))return!1;var a="act=close&thread="+(this._options.threadid||0)+"&token="+(this._options.token||0);this._options.user&&(a+="&user=true");new Ajax.Request(this._options.servl, -{parameters:a,onComplete:this.onThreadClosed.bind(this)})},processMessage:function(a,b){var c=NodeUtils.getNodeText(b);FrameUtils.insertIntoFrame(a,c)},showTyping:function(a){if($("typingdiv"))$("typingdiv").style.display=a?"inline":"none"},setupAvatar:function(a){a=NodeUtils.getNodeText(a);if(this._options.avatar&&this._options.user)this._options.avatar.innerHTML=""!=a?'':""}, -updateContent:function(a){var b=!1,c=this._options.container,d=NodeUtils.getAttrValue(a,"lastid");if(d)this._options.lastid=d;(d=NodeUtils.getAttrValue(a,"typing"))&&this.showTyping("1"==d);if((d=NodeUtils.getAttrValue(a,"canpost"))&&("1"==d&&!this.ownThread||this.ownThread&&"1"!=d))window.location.href=window.location.href;for(d=0;d");b.close();a.onload=function(){a.myHtml&&(FrameUtils.getDocument(a).getElementById("content").innerHTML+=a.myHtml,FrameUtils.scrollDown(a))}},insertIntoFrame:function(a,b){var c=this.getDocument(a).getElementById("content");null==c?(a.myHtml||(a.myHtml=""),a.myHtml+=b):c.innerHTML+=b},scrollDown:function(a){var b=this.getDocument(a).getElementById("bottom");if("opera"==myAgent)try{a.contentWindow.scrollTo(0,this.getDocument(a).getElementById("content").clientHeight)}catch(c){}b&& +b.scrollIntoView(!1)}};ChatServer=Class.create(); +ChatServer.prototype={initialize:function(a){this.updateTimer=null;this.options={servl:"",requestsFrequency:2,onTimeout:function(){},onTransportError:function(){},onCallError:function(){},onUpdateError:function(){},onResponseError:function(){}}.extend(a);this.callbacks={};this.callPeriodically=[];this.ajaxOptions={_method:"post",asynchronous:!0,timeout:5E3,onComplete:this.receiveResponse.bind(this),onException:this.onTransportError.bind(this),onTimeout:this.onTimeout.bind(this)};this.ajaxRequest= +null;this.buffer=[];this.functions={};this.mibewAPI=new MibewAPI(new MibewAPICoreInteraction)},callFunctions:function(a,b,c){try{if(!(a instanceof Array))throw Error("The first arguments must be an array");for(var d in a)a.hasOwnProperty(d)&&this.mibewAPI.checkFunction(a[d],!1);var e=this.generateToken();this.callbacks[e]=b;this.buffer.push({token:e,functions:a});c&&this.update()}catch(f){return this.options.onCallError(f),!1}return!0},callFunctionsPeriodically:function(a,b){this.callPeriodically.push({functionsListBuilder:a, +callbackFunction:b})},generateToken:function(){var a;do a="wnd"+(new Date).getTime().toString()+Math.round(50*Math.random()).toString();while(a in this.callbacks);return a},processRequest:function(a){var b=new MibewAPIExecutionContext,c=this.mibewAPI.getResultFunction(a.functions,this.callbacks.hasOwnProperty(a.token));if(null===c)for(var d in a.functions)a.functions.hasOwnProperty(d)&&(this.processFunction(a.functions[d],b),this.buffer.push(this.mibewAPI.buildResult(b.getResults(),a.token)));else this.callbacks.hasOwnProperty(a.token)&& +(this.callbacks[a.token](c.arguments),delete this.callbacks[a.token])},processFunction:function(a,b){if(this.functions.hasOwnProperty(a["function"])){var c=b.getArgumentsList(a),d={},e;for(e in this.functions[a["function"]])this.functions[a["function"]].hasOwnProperty(e)&&d.extend(this.functions[a["function"]][e](c));b.storeFunctionResults(a,d)}},sendRequests:function(a){this.ajaxRequest=new Ajax.Request(this.options.servl,this.ajaxOptions.extend({parameters:"data="+this.mibewAPI.encodePackage(a)}))}, +runUpdater:function(){null==this.updateTimer&&this.update();this.updateTimer=setTimeout(this.update.bind(this),1E3*this.options.requestsFrequency)},restartUpdater:function(){this.updateTimer&&clearTimeout(this.updateTimer);this.ajaxRequest._options&&(this.ajaxRequest._options.onComplete=void 0);this.update();this.updateTimer=setTimeout(this.update.bind(this),1E3)},update:function(){this.updateTimer&&clearTimeout(this.updateTimer);for(var a=0;a':"")},updateMessages:function(a){a.lastId&&(this.thread.lastid=a.lastId);for(var b=0;b\"\"/" - : ""; + /** + * Update operator's avatar + * @param {Array} args Array of arguments passed from the core + */ + setupAvatar: function(args) { + if (this._options.avatar && this.thread.user) { + this._options.avatar.innerHTML = args.imageLink != "" + ? "\"\"\"\"/" + : ""; } }, - updateContent: function(xmlRoot) { - var haveMessage = false; - - var result_div = this._options.container; - var _lastid = NodeUtils.getAttrValue(xmlRoot, "lastid"); - if( _lastid ) { - this._options.lastid = _lastid; - } - - var typing = NodeUtils.getAttrValue(xmlRoot, "typing"); - if( typing ) { - this.showTyping(typing == '1'); - } - - var canpost = NodeUtils.getAttrValue(xmlRoot, "canpost"); - if( canpost ) { - if( canpost == '1' && !this.ownThread || this.ownThread && canpost != '1' ) { - window.location.href = window.location.href; - } - } - - for( var i = 0; i < xmlRoot.childNodes.length; i++ ) { - var node = xmlRoot.childNodes[i]; - if( node.tagName == 'message' ) { - haveMessage = true; - this.processMessage(result_div, node); - } else if( node.tagName == 'avatar' ) { - this.setupAvatar(node); - } - } - if(window.location.search.indexOf('trace=on')>=0) { - var val = "updated"; - if(this.lastupdate > 0) { - var seconds = ((new Date()).getTime() - this.lastupdate)/1000; - val = val + ", " + seconds + " secs"; - if(seconds > 10) { - alert(val); - } - } - this.lastupdate = (new Date()).getTime(); - this.setStatus(val); - } else { - this.clearStatus(); - } - if( haveMessage ) { - FrameUtils.scrollDown(this._options.container); - if(!this.skipNextsound) { - var tsound = $('soundimg'); - if(tsound == null || tsound.className.match(new RegExp("\\bisound\\b")) ) { - playSound(Chat.webimRoot+'/sounds/new_message.wav'); - } - } - if( !this.focused ) { - window.focus(); - } - } + /** + * Add new messages to chat window + * @param {Object} args object of function arguments passed from the server + * @todo Fix skipNextSound + */ + updateMessages: function(args){ + // Update last message id + if (args.lastId) { + this.thread.lastid = args.lastId; + } + // Add messages + for (var i = 0; i < args.messages.length; i++) { + // TODO: Add template engine + this.processMessage(this._options.container, args.messages[i]); + } + // Clear status string + this.clearStatus(); + // There are some new messages + if (args.messages.length > 0) { + FrameUtils.scrollDown(this._options.container); + if (!this.skipNextsound) { + var tsound = $('soundimg'); + if (tsound == null || tsound.className.match(new RegExp("\\bisound\\b"))) { + playSound(this._options.webimRoot+'/sounds/new_message.wav'); + } + } + if (!this.focused) { + window.focus(); + } + } + this.skipNextsound = false; }, + /** + * Build update function to call at the core + */ + updateFunctionBuilder: function() { + return [ + { + "function": "update", + "arguments": { + "return": {'typing': 'typing', 'canPost': 'canPost'}, + "references": {}, + "threadId": this.thread.threadid, + "token": this.thread.token, + "lastId": this.thread.lastid, + "typed": (this._options.message && this._options.message.value != ''), + "user": this.thread.user + } + } + ]; + }, + + /** + * Set current chat state message + * @param {Array} args Array of arguments passed from the core + */ + updateChatState: function(args) { + if (args.errorCode) { + // Something went wrong + this.handleError(args, 'refresh failed'); + return; + } + // Update typing indicator + if (typeof args.typing != 'undefined') { + this.showTyping(args.typing); + } + + // Check if user can post messages + if (typeof args.canPost != 'undefined') { + if ((args.canPost && !this.ownThread) || (this.ownThread && ! args.canPost)) { + // Refresh the page + window.location.href = window.location.href; + } + } + }, + + /** + * Check if send key (Enter or Ctrl+Enter) pressed + * @param {Boolean} ctrlpressed Indicates ctrl key is pressed or not + * @param {Number} key Key code + */ isSendkey: function(ctrlpressed, key) { return ((key==13 && (ctrlpressed || this._options.ignorectrl)) || (key==10)); }, - + + /** + * Key down handler + * + * @param {Object} k Event object + */ handleKeyDown: function(k) { - if( k ){ ctrl=k.ctrlKey;k=k.which; } else { k=event.keyCode;ctrl=event.ctrlKey; } + if( k ){ctrl=k.ctrlKey;k=k.which;} else {k=event.keyCode;ctrl=event.ctrlKey;} if( this._options.message && this.isSendkey(ctrl, k) ) { var mmsg = this._options.message.value; if( this._options.ignorectrl ) { @@ -284,14 +798,26 @@ Class.inherit( Ajax.ChatThreadUpdater, Ajax.Base, { return true; }, - handleError: function(_response, xmlRoot, _action) { - if( xmlRoot && xmlRoot.tagName == 'error' ) { - this.setStatus(NodeUtils.getNodeValue(xmlRoot,"descr")); - } else { - this.setStatus("reconnecting"); - } + /** + * Update status message + * + * @param {Array} args Array of arguments. Must contain 'errorCode' and + * 'errorMessage' keys + * @param {String} descr Error description + */ + handleError: function(args, descr) { + if (args.errorCode) { + this.setStatus(args.errorMessage); + } else { + this.setStatus('reconnecting'); + } }, + /** + * Displays status div and sets the status string into it + * + * @param {String} k Status string + */ showStatusDiv: function(k) { if( $("engineinfo") ) { $("engineinfo").style.display='inline'; @@ -299,6 +825,11 @@ Class.inherit( Ajax.ChatThreadUpdater, Ajax.Base, { } }, + /** + * Sets the status + * + * @param {String} k Status string + */ setStatus: function(k) { if( this.statusTimeout ) clearTimeout(this.statusTimeout); @@ -306,11 +837,13 @@ Class.inherit( Ajax.ChatThreadUpdater, Ajax.Base, { this.statusTimeout = setTimeout(this.clearStatus.bind(this), 4000); }, + /** + * Hide the status string + */ clearStatus: function() { $("engineinfo").style.display='none'; } -}); - +} var Chat = { threadUpdater : {}, @@ -368,8 +901,7 @@ Behaviour.register({ }, 'a#refresh' : function(el) { el.onclick = function() { - Chat.threadUpdater.stopUpdate(); - Chat.threadUpdater.update(); + Chat.threadUpdater.refresh(); }; }, 'a#togglesound' : function(el) { @@ -396,9 +928,17 @@ Behaviour.register({ }); EventHelper.register(window, 'onload', function(){ - Chat.webimRoot = threadParams.wroot; - Chat.cssfile = threadParams.cssfile; - Chat.predefinedAnswers = (typeof predefinedAnswers != 'undefined')?predefinedAnswers:Array(); - Chat.localizedStrings = localizedStrings; - Chat.threadUpdater = new Ajax.ChatThreadUpdater(({ignorectrl:-1,container:myRealAgent=='safari'?self.frames[0]:$("chatwnd"),avatar:$("avatarwnd"),message:$("msgwnd")}).extend( threadParams || {} )); + Chat.cssfile = chatParams.cssfile; + Chat.predefinedAnswers = chatParams.predefinedAnswers || []; + Chat.localizedStrings = chatParams.localizedStrings; + Chat.threadUpdater = new ChatThreadUpdater( + new ChatServer(chatParams.serverParams), + chatParams.threadParams, + { + ignorectrl: -1, + container: myRealAgent=='safari'?self.frames[0]:$("chatwnd"), + avatar: $("avatarwnd"), + message: $("msgwnd") + }.extend(chatParams.threadUpdaterParams || {}) + ); }); \ No newline at end of file diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 7d8ddeac..3cbc177e 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -26,33 +26,6 @@ function get_user_id() return (time() + microtime()) . rand(0, 99999999); } -function prepare_html_message($text, $allow_formating) -{ - $escaped_text = htmlspecialchars($text); - $text_w_links = preg_replace('/(https?|ftp):\/\/\S*/', '$0', $escaped_text); - $multiline = str_replace("\n", "
", $text_w_links); - if (! $allow_formating) { - return $multiline; - } - $formated = preg_replace('/<(span|strong)>(.*)<\/\1>/U', '<$1>$2', $multiline); - $formated = preg_replace('/<span class="(.*)">(.*)<\/span>/U', '$2', $formated); - return $formated; -} - -function message_to_html($msg) -{ - if ($msg['ikind'] == Thread::KIND_AVATAR) { - return ""; - } - $message = "" . date("H:i:s", $msg['created']) . " "; - $kind = Thread::kindToString($msg['ikind']); - if ($msg['tname']) - $message .= "" . htmlspecialchars($msg['tname']) . ": "; - $allow_formating = ($msg['ikind'] != Thread::KIND_USER && $msg['ikind'] != Thread::KIND_AGENT); - $message .= "" . prepare_html_message($msg['tmessage'], $allow_formating) . "
"; - return $message; -} - function message_to_text($msg) { if ($msg['ikind'] == Thread::KIND_AVATAR) { @@ -71,93 +44,6 @@ function message_to_text($msg) } } -function get_messages($threadid, $meth, $isuser, &$lastid) -{ - global $webim_encoding; - $db = Database::getInstance(); - - $msgs = $db->query( - "select messageid,ikind,dtmcreated as created,tname,tmessage from {chatmessage} " . - "where threadid = :threadid and messageid > :lastid " . - ($isuser ? "and ikind <> ". Thread::KIND_FOR_AGENT : "") . - " order by messageid", - array( - ':threadid' => $threadid, - ':lastid' => $lastid, - ), - array('return_rows' => Database::RETURN_ALL_ROWS) - - ); - - $messages = array(); - foreach ($msgs as $msg) { - $message = ""; - if ($meth == 'xml') { - switch ($msg['ikind']) { - case Thread::KIND_AVATAR: - $message = "" . myiconv($webim_encoding, "utf-8", escape_with_cdata($msg['tmessage'])) . ""; - break; - default: - $message = "" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "\n"; - } - } else { - if ($msg['ikind'] != Thread::KIND_AVATAR) { - $message = (($meth == 'text') ? message_to_text($msg) : topage(message_to_html($msg))); - } - } - - $messages[] = $message; - if ($msg['messageid'] > $lastid) { - $lastid = $msg['messageid']; - } - } - - return $messages; -} - -function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agentid = null) -{ - global $webim_encoding, $webimroot; - $threadid = $thread->id; - $istyping = abs(time() - $isuser ? $thread->lastPingAgent : $thread->lastPingUser) < Thread::CONNECTION_TIMEOUT - && (($isuser ? $thread->agentTyping : $thread->userTyping) == "1") ? "1" : "0"; - - if ($format == "xml") { - $output = get_messages($threadid, "xml", $isuser, $lastid); - - start_xml_output(); - print("agentId) ? 1 : 0) . "\">"); - foreach ($output as $msg) { - print $msg; - } - print(""); - } else if ($format == "html") { - $output = get_messages($threadid, "html", $isuser, $lastid); - - start_html_output(); - $url = "$webimroot/thread.php?act=refresh&thread=$threadid&token=$token&html=on&user=" . ($isuser ? "true" : "false"); - - print( - "" . - "\n\n" . - "\n" . - "\n" . - "\n" . - "chat\n" . - "\n" . - "" . - "
"); - - foreach ($output as $msg) { - print $msg; - } - - print( - "
" . - ""); - } -} - function get_user_name($username, $addr, $id) { return str_replace( diff --git a/src/messenger/webim/libs/demothread.php b/src/messenger/webim/libs/demothread.php deleted file mode 100644 index 7e898dee..00000000 --- a/src/messenger/webim/libs/demothread.php +++ /dev/null @@ -1,89 +0,0 @@ -" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "\n"; - } else { - print topage(message_to_html($msg)); - } -} - -function demo_process_thread($act, $outformat, $lastid, $isuser, $canpost, $istyping, $postmessage) -{ - global $webimroot; - if ($act == "refresh" || $act == "post") { - $lastid++; - if ($outformat == "xml") { - start_xml_output(); - print(""); - } else { - start_html_output(); - $url = "$webimroot/thread.php?act=refresh&thread=0&token=123&html=on&user=" . ($isuser ? "true" : "false"); - - print( - "" . - "\n\n" . - "\n" . - "\n" . - "\n" . - "chat\n" . - "\n" . - "" . - "
"); - - } - if ($lastid == 1) { - demo_print_message( - array('ikind' => Thread::KIND_FOR_AGENT, 'created' => time() - 15, 'tname' => '', - 'tmessage' => getstring2('chat.came.from', array("http://google.com"))), $outformat); - demo_print_message( - array('ikind' => Thread::KIND_INFO, 'created' => time() - 15, 'tname' => '', - 'tmessage' => getstring('chat.wait')), $outformat); - demo_print_message( - array('ikind' => Thread::KIND_EVENTS, 'created' => time() - 10, 'tname' => '', - 'tmessage' => getstring2("chat.status.operator.joined", array("Administrator"))), $outformat); - demo_print_message( - array('ikind' => Thread::KIND_AGENT, 'created' => time() - 9, 'tname' => 'Administrator', - 'tmessage' => getstring("demo.chat.welcome")), $outformat); - demo_print_message( - array('ikind' => Thread::KIND_USER, 'created' => time() - 5, 'tname' => getstring("chat.default.username"), - 'tmessage' => getstring("demo.chat.question")), $outformat); - if ($canpost && $outformat == 'xml') { - demo_print_message( - array('ikind' => Thread::KIND_INFO, 'created' => time() - 5, 'tname' => '', - 'tmessage' => 'Hint: type something in message field to see typing notification'), $outformat); - } - } - if ($act == 'post') { - demo_print_message( - array('ikind' => $isuser ? Thread::KIND_USER : Thread::KIND_AGENT, 'created' => time(), 'tmessage' => $postmessage, - 'tname' => $isuser ? getstring("chat.default.username") : "Administrator"), $outformat); - } - if ($outformat == "xml") { - print(""); - } else { - print( - "
" . - ""); - } - } -} - -?> \ No newline at end of file diff --git a/src/messenger/webim/mail.php b/src/messenger/webim/mail.php index 59c73d76..ac525efe 100644 --- a/src/messenger/webim/mail.php +++ b/src/messenger/webim/mail.php @@ -53,10 +53,10 @@ if( count($errors) > 0 ) { } $history = ""; -$lastid = -1; -$output = get_messages( $threadid,"text",true,$lastid ); -foreach( $output as $msg ) { - $history .= $msg; +$last_id = -1; +$messages = $thread->getMessages(true, $last_id); +foreach ($messages as $msg) { + $history .= message_to_text($msg); } $subject = getstring("mail.user.history.subject"); diff --git a/src/messenger/webim/operator/threadprocessor.php b/src/messenger/webim/operator/threadprocessor.php index b4a85ec8..02cb9f2f 100644 --- a/src/messenger/webim/operator/threadprocessor.php +++ b/src/messenger/webim/operator/threadprocessor.php @@ -45,10 +45,20 @@ function thread_info($id) if (isset($_GET['threadid'])) { + // Load thread info $threadid = verifyparam("threadid", "/^(\d{1,9})?$/", ""); + $thread_info = thread_info($threadid); + $page['thread_info'] = $thread_info; + + // Build messages list $lastid = -1; - $page['threadMessages'] = get_messages($threadid, "html", false, $lastid); - $page['thread_info'] = thread_info($threadid); + $messages = $thread_info['thread']->getMessages(false, $lastid); + foreach ($messages as $msg) { + if ($msg['ikind'] == Thread::KIND_AVATAR) { + continue; + } + $page['threadMessages'][] = Thread::themeMessage($msg); + } } prepare_menu($operator, false); diff --git a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl index 98fada3e..b1792daa 100644 --- a/src/messenger/webim/styles/dialogs/default/templates/chat.tpl +++ b/src/messenger/webim/styles/dialogs/default/templates/chat.tpl @@ -5,13 +5,30 @@ + + diff --git a/src/messenger/webim/styles/dialogs/original/templates/chat.tpl b/src/messenger/webim/styles/dialogs/original/templates/chat.tpl index 7d623f0c..297f351a 100644 --- a/src/messenger/webim/styles/dialogs/original/templates/chat.tpl +++ b/src/messenger/webim/styles/dialogs/original/templates/chat.tpl @@ -5,13 +5,30 @@ + + diff --git a/src/messenger/webim/styles/dialogs/silver/templates/chat.tpl b/src/messenger/webim/styles/dialogs/silver/templates/chat.tpl index 2c0481df..d510060d 100644 --- a/src/messenger/webim/styles/dialogs/silver/templates/chat.tpl +++ b/src/messenger/webim/styles/dialogs/silver/templates/chat.tpl @@ -6,16 +6,31 @@ + + diff --git a/src/messenger/webim/thread.php b/src/messenger/webim/thread.php index 7487cc00..b90ebd3d 100644 --- a/src/messenger/webim/thread.php +++ b/src/messenger/webim/thread.php @@ -19,97 +19,13 @@ require_once('libs/init.php'); require_once('libs/chat.php'); require_once('libs/operator.php'); require_once('libs/classes/thread.php'); +require_once('libs/classes/mibew_api.php'); +require_once('libs/classes/mibew_api_interaction.php'); +require_once('libs/classes/mibew_api_window_interaction.php'); +require_once('libs/classes/mibew_api_execution_context.php'); +require_once('libs/classes/thread_processor.php'); -$act = verifyparam( "act", "/^(refresh|post|rename|close|ping)$/"); -$token = verifyparam( "token", "/^\d{1,9}$/"); -$threadid = verifyparam( "thread", "/^\d{1,9}$/"); -$isuser = verifyparam( "user", "/^true$/", "false") == 'true'; -$outformat = ((verifyparam( "html", "/^on$/", "off") == 'on') ? "html" : "xml"); -$istyping = verifyparam( "typed", "/^1$/", "") == '1'; - -if($threadid == 0 && ($token == 123 || $token == 124)) { - require_once('libs/demothread.php'); - $lastid = verifyparam( "lastid", "/^\d{1,9}$/", 0); - demo_process_thread($act,$outformat,$lastid,$isuser,$token == 123,$istyping,$act=="post"?getrawparam('message') : ""); - exit; -} - -$thread = Thread::load($threadid, $token); -if (! $thread) { - die("wrong thread"); -} - -function show_ok_result($resid) { - start_xml_output(); - echo "<$resid>"; - exit; -} - -function show_error($message) { - start_xml_output(); - echo "$message"; - exit; -} - -$thread->ping($isuser, $istyping); - -if( !$isuser && $act != "rename" ) { - $operator = check_login(); - $thread->checkForReassign($operator); -} - -if( $act == "refresh" ) { - $lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1); - print_thread_messages($thread, $token, $lastid, $isuser,$outformat, $isuser ? null : $operator['operatorid']); - exit; - -} else if( $act == "post" ) { - $lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1); - $message = getrawparam('message'); - - $kind = $isuser ? Thread::KIND_USER : Thread::KIND_AGENT; - $from = $isuser ? $thread->userName : $thread->agentName; - - if(!$isuser && $operator['operatorid'] != $thread->agentId) { - show_error("cannot send"); - } - - $postedid = $thread->postMessage( - $kind, - $message, - $from, - $isuser ? null : $operator['operatorid'] - ); - if($isuser && $thread->shownMessageId == 0) { - $thread->shownMessageId = $postedid; - $thread->save(); - } - print_thread_messages($thread, $token, $lastid, $isuser, $outformat, $isuser ? null : $operator['operatorid']); - exit; - -} else if( $act == "rename" ) { - - if( Settings::get('usercanchangename') != "1" ) { - show_error("server: forbidden to change name"); - } - - $newname = getrawparam('name'); - - $thread->renameUser($newname); - $data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,'); - setcookie($namecookie, $data, time()+60*60*24*365); - show_ok_result("rename"); - -} else if( $act == "ping" ) { - show_ok_result("ping"); - -} else if( $act == "close" ) { - - if( $isuser || $thread->agentId == $operator['operatorid']) { - $thread->close($isuser); - } - show_ok_result("closed"); - -} +$processor = ThreadProcessor::getInstance(); +$processor->receiveRequest($_POST['data']); ?> \ No newline at end of file