diff --git a/app/models/contact/Contact.php b/app/models/contact/Contact.php index 7aa12e6a3..ae313e817 100644 --- a/app/models/contact/Contact.php +++ b/app/models/contact/Contact.php @@ -309,6 +309,7 @@ class RosterContact extends Contact { protected $delay; protected $chaton; protected $last; + protected $publickey; protected $rosterask; protected $node; protected $ver; @@ -340,7 +341,9 @@ class RosterContact extends Contact { 'delay' : {'type':'date'}, 'last' : - {'type':'int', 'size':11 } + {'type':'int', 'size':11 }, + 'publickey' : + {'type':'text'} }"; } @@ -351,5 +354,6 @@ class RosterContact extends Contact { $this->status = $p->status; $this->delay = $p->delay; $this->last = $p->last; + $this->publickey = $p->publickey; } } diff --git a/app/models/contact/ContactDAO.php b/app/models/contact/ContactDAO.php index 7f6def1a2..9409a3eba 100644 --- a/app/models/contact/ContactDAO.php +++ b/app/models/contact/ContactDAO.php @@ -349,14 +349,13 @@ class ContactDAO extends ModlSQL { return $this->run('RosterContact'); } - + // limit 1 function getRosterChat() { $this->_sql = ' select * from rosterlink left outer join ( select * from presence order by presence.priority desc - limit 1 ) as presence on rosterlink.jid = presence.jid left outer join contact diff --git a/app/models/presence/Presence.php b/app/models/presence/Presence.php index 796a3c8a7..5f0920cd7 100644 --- a/app/models/presence/Presence.php +++ b/app/models/presence/Presence.php @@ -23,6 +23,9 @@ class Presence extends ModlModel { // Last Activity - XEP 0256 protected $last; + + // Current Jabber OpenPGP Usage - XEP-0027 + protected $publickey; public function __construct() { $this->_struct = ' @@ -48,7 +51,9 @@ class Presence extends ModlModel { "delay" : {"type":"date"}, "last" : - {"type":"int", "size":11 } + {"type":"int", "size":11 }, + "publickey" : + {"type":"text"} }'; parent::__construct(); @@ -98,6 +103,18 @@ class Presence extends ModlModel { } else { $this->value = 1; } + + // Specific XEP + if($stanza->x) { + foreach($stanza->children() as $name => $c) { + $ns = $c->getNamespaces(true); + switch($ns['']) { + case 'jabber:x:signed' : + $this->publickey = (string)$c; + break; + } + } + } if($stanza->delay) { $this->delay = diff --git a/app/models/presence/PresenceDAO.php b/app/models/presence/PresenceDAO.php index 5994d732b..396476ad2 100644 --- a/app/models/presence/PresenceDAO.php +++ b/app/models/presence/PresenceDAO.php @@ -22,7 +22,8 @@ class PresenceDAO extends ModlSQL { node = :node, ver = :ver, delay = :delay, - last = :last + last = :last, + publickey = :publickey where id = :id'; $this->prepare( @@ -35,6 +36,7 @@ class PresenceDAO extends ModlSQL { 'ver' => $presence->ver, 'delay' => $presence->delay, 'last' => $presence->last, + 'publickey' => $presence->publickey, 'id' => $id ) ); @@ -44,7 +46,7 @@ class PresenceDAO extends ModlSQL { if(!$this->_effective) { $this->_sql = ' insert into presence - (id,session, jid, ressource, value, priority, status, node, ver, delay,last) + (id,session, jid, ressource, value, priority, status, node, ver, delay,last,publickey) values( :id, :session, @@ -56,7 +58,8 @@ class PresenceDAO extends ModlSQL { :node, :ver, :delay, - :last)'; + :last, + :publickey)'; $this->prepare( 'Presence', @@ -71,7 +74,8 @@ class PresenceDAO extends ModlSQL { 'node' => $presence->node, 'ver' => $presence->ver, 'delay' => $presence->delay, - 'last' => $presence->last + 'last' => $presence->last, + 'publickey' => $presence->publickey ) ); diff --git a/app/models/rosterlink/RosterLink.php b/app/models/rosterlink/RosterLink.php index 0bcfbad44..9dfccfbd1 100644 --- a/app/models/rosterlink/RosterLink.php +++ b/app/models/rosterlink/RosterLink.php @@ -15,6 +15,8 @@ class RosterLink extends ModlModel { public $groupname; public $chaton; + + public $publickey; public function __construct() { $this->_struct = ' diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index 43669178f..af5830ff7 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -218,6 +218,18 @@ class Chat extends WidgetBase $evt = new Event(); $evt->runEvent('openchat'); } + + /** + * Send an encrypted message + * + * @param string $to + * @param string $message + * @return void + */ + function ajaxSendEncryptedMessage($to, $message, $muc = false, $ressource = false) + { + $this->ajaxSendMessage($to, $message, $muc, $ressource, true); + } /** * Send a message @@ -226,7 +238,7 @@ class Chat extends WidgetBase * @param string $message * @return void */ - function ajaxSendMessage($to, $message, $muc = false, $ressource = false) + function ajaxSendMessage($to, $message, $muc = false, $ressource = false, $encrypted = false) { $m = new \modl\Message(); @@ -262,6 +274,7 @@ class Chat extends WidgetBase // We decode URL codes to send the correct message to the XMPP server $m = new \moxl\MessagePublish(); $m->setTo($to) + ->setEncrypted($encrypted) ->setContent(htmlspecialchars(rawurldecode($message))); if($muc) $m->setMuc(); @@ -390,9 +403,15 @@ class Chat extends WidgetBase $html = ''; + // Another filter to fix the database request + $jid = ''; + if(isset($contacts)) { foreach($contacts as $contact) { - $html .= trim($this->prepareChat($contact)); + if($jid != $contact->jid) { + $html .= trim($this->prepareChat($contact)); + $jid = $contact->jid; + } } } @@ -517,9 +536,34 @@ class Chat extends WidgetBase if($contact->chaton == 2) { $tabstyle = ' style="display: none;" '; $panelstyle = ' style="display: block;" '; - } + } $chatview = $this->tpl(); + + /*if($contact->publickey) { + $chatview->assign('publickey', $contact->publickey); + $chatview->assign( + 'send', + $this->genCallAjax( + 'ajaxSendEncryptedMessage', + "'".$contact->jid."'", + "sendEncryptedMessage(this, '".$contact->jid."')", + "false", + "'".$contact->ressource."'" + ) + ); + } else {*/ + $chatview->assign( + 'send', + $this->genCallAjax( + 'ajaxSendMessage', + "'".$contact->jid."'", + "sendMessage(this, '".$contact->jid."')", + "false", + "'".$contact->ressource."'" + ) + ); + //} $chatview->assign('contact', $contact); $chatview->assign('tabstyle', $tabstyle); @@ -533,16 +577,7 @@ class Chat extends WidgetBase 'hidetalk', $this->genCallAjax("ajaxHideTalk", "'".$contact->jid."'") ); - $chatview->assign( - 'send', - $this->genCallAjax( - 'ajaxSendMessage', - "'".$contact->jid."'", - "sendMessage(this, '".$contact->jid."')", - "false", - "'".$contact->ressource."'" - ) - ); + $chatview->assign( 'composing', $this->genCallAjax( diff --git a/app/widgets/Chat/_chat_contact.tpl b/app/widgets/Chat/_chat_contact.tpl index dfffa0cd9..6ad333316 100644 --- a/app/widgets/Chat/_chat_contact.tpl +++ b/app/widgets/Chat/_chat_contact.tpl @@ -7,6 +7,9 @@ {$contact->getTrueName()} + {if="$publickey"} + - Encrypted + {/if}