Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add contact menu integration #13

Merged
merged 3 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@
</dependencies>

<ocsid>162257</ocsid>

<contactsmenu>
<provider>OCA\OJSXC\ContactsMenu\Providers\ChatProvider</provider>
</contactsmenu>
</info>
94 changes: 94 additions & 0 deletions img/actions/chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions img/chat-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 35 additions & 6 deletions js/ojsxc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div/>');

Expand All @@ -14,9 +39,9 @@
});

if ($('#contactsmenu').length > 0) {
$('#contactsmenu').before(div);
$('#contactsmenu').before(div);
} else {
$('#settings').after(div);
$('#settings').after(div);
}
}

Expand Down Expand Up @@ -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));
81 changes: 81 additions & 0 deletions lib/ContactsMenu/Providers/ChatProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace OCA\OJSXC\ContactsMenu\Providers;

use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IL10N;
use OCP\IURLGenerator;

class ChatProvider implements IProvider
{

/** @var IActionFactory */
private $actionFactory;

/** @var IURLGenerator */
private $urlGenerator;

/** @var IL10N */
private $l10n;

/**
* @param IActionFactory $actionFactory
* @param IURLGenerator $urlGenerator
* @param IL10N $l10n
*/
public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator, IL10N $l10n)
{
$this->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);
}
}
}
14 changes: 14 additions & 0 deletions scss/_oc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,17 @@
display: none;
}
}

#contactsmenu-contacts {
.jsxc_statusIndicator {
position: relative;

&:before {
width: 6px;
height: 6px;
right: 13px;
top: 13px;
position: absolute;
}
}
}