diff --git a/appinfo/info.xml b/appinfo/info.xml index d4041530..1af5f6e7 100755 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -42,4 +42,8 @@ 162257 + + + OCA\OJSXC\ContactsMenu\Providers\ChatProvider + diff --git a/img/actions/chat.svg b/img/actions/chat.svg new file mode 100644 index 00000000..7f467380 --- /dev/null +++ b/img/actions/chat.svg @@ -0,0 +1,94 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/img/chat-icon.svg b/img/chat-icon.svg new file mode 100644 index 00000000..d839b37f --- /dev/null +++ b/img/chat-icon.svg @@ -0,0 +1,72 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/js/ojsxc.js b/js/ojsxc.js index b4cdb129..10ca8d68 100644 --- a/js/ojsxc.js +++ b/js/ojsxc.js @@ -5,6 +5,31 @@ (function($) { "use strict"; + function observeContactsMenu() { + var target = document.getElementById('contactsmenu'); + + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.target.id !== 'contactsmenu-contacts') { + return; + } + + $(mutation.target).find('[href^="xmpp:"]').addClass('jsxc_statusIndicator'); + + jsxc.gui.detectUriScheme(mutation.target); + }); + }); + + var config = { + attributes: true, + childList: true, + characterData: true, + subtree: true + }; + + observer.observe(target, config); + } + function injectChatIcon() { var div = $('
'); @@ -14,9 +39,9 @@ }); if ($('#contactsmenu').length > 0) { - $('#contactsmenu').before(div); + $('#contactsmenu').before(div); } else { - $('#settings').after(div); + $('#settings').after(div); } } @@ -245,12 +270,16 @@ $('#body-login form:eq(0) fieldset').append(alt); Strophe.log = function(level, msg) { - if (level === 3 && /^request id/.test(msg)) { - console.warn('Something went wrong during BOSH connection establishment. Continue without chat.'); + if (level === 3 && /^request id/.test(msg)) { + console.warn('Something went wrong during BOSH connection establishment. Continue without chat.'); - jsxc.submitLoginForm(); - } + jsxc.submitLoginForm(); + } }; } + + if ($('#contactsmenu').length > 0) { + observeContactsMenu(); + } }); }(jQuery)); diff --git a/lib/ContactsMenu/Providers/ChatProvider.php b/lib/ContactsMenu/Providers/ChatProvider.php new file mode 100644 index 00000000..70aeb591 --- /dev/null +++ b/lib/ContactsMenu/Providers/ChatProvider.php @@ -0,0 +1,81 @@ +actionFactory = $actionFactory; + $this->urlGenerator = $urlGenerator; + $this->l10n = $l10n; + } + + /** + * @param IEntry $entry + */ + public function process(IEntry $entry) + { + $uid = $entry->getProperty('UID'); + $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('ojsxc', 'actions/chat.svg')); + $localIm = null; + + if (is_null($uid)) { + // Nothing to do + return; + } + + if ($entry->getProperty('isLocalSystemBook') === true) { + // internal user + + $config = \OC::$server->getConfig(); + $serverType = $config->getAppValue('ojsxc', 'serverType', 'external'); + + if ($serverType === 'internal') { + $domain = \OC::$server->getRequest()->getServerHost(); + } else { + $domain = trim($config->getAppValue('ojsxc', 'xmppDomain')); + } + + $localIm = $uid.'@'.$domain; + $chatUrl = 'xmpp:'.$localIm; + + $action = $this->actionFactory->newLinkAction($iconUrl, $localIm, $chatUrl); + $entry->addAction($action); + } + + $imProperties = $entry->getProperty('IMPP'); + + foreach ($imProperties as $externalIm) { + if (!preg_match("/^[a-z0-9\.\-_]+@[a-z0-9\.\-_]+$/i", $externalIm) || $externalIm === $localIm) { + continue; + } + + $chatUrl = 'xmpp:'.$externalIm; + + $action = $this->actionFactory->newLinkAction($iconUrl, $externalIm, $chatUrl); + $entry->addAction($action); + } + } +} diff --git a/scss/_oc.scss b/scss/_oc.scss index f9c2d469..7e0438fa 100644 --- a/scss/_oc.scss +++ b/scss/_oc.scss @@ -218,3 +218,17 @@ display: none; } } + +#contactsmenu-contacts { + .jsxc_statusIndicator { + position: relative; + + &:before { + width: 6px; + height: 6px; + right: 13px; + top: 13px; + position: absolute; + } + } +}