diff options
author | sualko <klaus@jsxc.org> | 2017-04-28 16:58:31 +0300 |
---|---|---|
committer | sualko <klaus@jsxc.org> | 2017-04-28 17:06:11 +0300 |
commit | 62f028384191d7b4c9ea2bef875e61036c020b36 (patch) | |
tree | 544cecc297d78e38e705e2f0616623a381104073 /build/lib | |
parent | 4b7393cbc81f055b8974c8011c5746b3cd541168 (diff) |
build v3.2.0-beta.2v3.2.0-beta.2
Diffstat (limited to 'build/lib')
-rw-r--r-- | build/lib/ContactsMenu/Providers/ChatProvider.php | 81 | ||||
-rw-r--r-- | build/lib/Settings/Admin.php | 74 | ||||
-rw-r--r-- | build/lib/Settings/Section.php | 64 | ||||
-rw-r--r-- | build/lib/controller/httpbindcontroller.php | 38 | ||||
-rw-r--r-- | build/lib/db/presencemapper.php | 11 | ||||
-rw-r--r-- | build/lib/db/stanzamapper.php | 6 | ||||
-rw-r--r-- | build/lib/dblock.php | 20 |
7 files changed, 232 insertions, 62 deletions
diff --git a/build/lib/ContactsMenu/Providers/ChatProvider.php b/build/lib/ContactsMenu/Providers/ChatProvider.php new file mode 100644 index 0000000..70aeb59 --- /dev/null +++ b/build/lib/ContactsMenu/Providers/ChatProvider.php @@ -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); + } + } +} diff --git a/build/lib/Settings/Admin.php b/build/lib/Settings/Admin.php new file mode 100644 index 0000000..3c0479f --- /dev/null +++ b/build/lib/Settings/Admin.php @@ -0,0 +1,74 @@ +<?php + +namespace OCA\OJSXC\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; +use OCP\IConfig; + +class Admin implements ISettings +{ + /** @var IConfig */ + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + /** + * @return TemplateResponse + */ + public function getForm() + { + $externalServices = $this->config->getAppValue('ojsxc', 'externalServices'); + $externalServices = explode("|", $externalServices); + + $apiSecret = $this->config->getAppValue('ojsxc', 'apiSecret'); + if (!$apiSecret) { + $apiSecret = \OC::$server->getSecureRandom()->generate(23); + $this->config->setAppValue('ojsxc', 'apiSecret', $apiSecret); + } + + $parameters = [ + 'serverType' => $this->config->getAppValue('ojsxc', 'serverType'), + 'boshUrl' => $this->config->getAppValue('ojsxc', 'boshUrl'), + 'xmppDomain' => $this->config->getAppValue('ojsxc', 'xmppDomain'), + 'xmppPreferMail' => $this->config->getAppValue('ojsxc', 'xmppPreferMail'), + 'xmppResource' => $this->config->getAppValue('ojsxc', 'xmppResource'), + 'xmppOverwrite' => $this->config->getAppValue('ojsxc', 'xmppOverwrite'), + 'xmppStartMinimized' => $this->config->getAppValue('ojsxc', 'xmppStartMinimized'), + 'iceUrl' => $this->config->getAppValue('ojsxc', 'iceUrl'), + 'iceUsername' => $this->config->getAppValue('ojsxc', 'iceUsername'), + 'iceCredential' => $this->config->getAppValue('ojsxc', 'iceCredential'), + 'iceSecret' => $this->config->getAppValue('ojsxc', 'iceSecret'), + 'iceTtl' => $this->config->getAppValue('ojsxc', 'iceTtl'), + 'firefoxExtension' => $this->config->getAppValue('ojsxc', 'firefoxExtension'), + 'chromeExtension' => $this->config->getAppValue('ojsxc', 'chromeExtension'), + 'timeLimitedToken' => $this->config->getAppValue('ojsxc', 'timeLimitedToken'), + 'externalServices' => $externalServices, + 'apiSecret' => $apiSecret + ]; + + return new TemplateResponse('ojsxc', 'settings/admin', $parameters); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() + { + return 'ojsxc'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() + { + return 50; + } +} diff --git a/build/lib/Settings/Section.php b/build/lib/Settings/Section.php new file mode 100644 index 0000000..9613a03 --- /dev/null +++ b/build/lib/Settings/Section.php @@ -0,0 +1,64 @@ +<?php + +namespace OCA\OJSXC\Settings; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\ISection; + +class Section implements ISection +{ + /** @var IL10N */ + private $l; + + /** @var IURLGenerator */ + private $url; + + public function __construct(IL10N $l, IURLGenerator $url) + { + $this->l = $l; + $this->url = $url; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string, + * e.g. 'ldap' + * + * @returns string + */ + public function getID() + { + return 'ojsxc'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName() + { + return 'JavaScript XMPP Client'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + */ + public function getPriority() + { + return 50; + } + + /** + * {@inheritdoc} + */ + public function getIcon() + { + return $this->url->imagePath('ojsxc', 'chat-icon.svg'); + } +} diff --git a/build/lib/controller/httpbindcontroller.php b/build/lib/controller/httpbindcontroller.php index 42af2e1..6ace73e 100644 --- a/build/lib/controller/httpbindcontroller.php +++ b/build/lib/controller/httpbindcontroller.php @@ -5,8 +5,6 @@ namespace OCA\OJSXC\Controller; use OCA\OJSXC\Db\Presence; use OCA\OJSXC\Db\PresenceMapper; use OCA\OJSXC\Db\StanzaMapper; -use OCA\OJSXC\Db\MessageMapper; -use OCA\OJSXC\Exceptions\NewContentException; use OCA\OJSXC\Http\XMPPResponse; use OCA\OJSXC\ILock; use OCA\OJSXC\NewContentContainer; @@ -17,8 +15,6 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Db\DoesNotExistException; use OCP\ILogger; use OCP\IRequest; -use OCP\ISession; -use Sabre\Xml\Writer; use Sabre\Xml\Reader; use Sabre\Xml\LibXMLException; @@ -42,26 +38,6 @@ class HttpBindController extends Controller { private $userId; /** - * @var int $pollingId - */ - private $pollingId; - - /** - * @var string $host - */ - private $host; - - /** - * @var Session OCP\ISession - */ - private $session; - - /** - * @var MessageMapper OCA\OJSXC\Db\MessageMapper - */ - private $messageMapper; - - /** * @var StanzaMapper OCA\OJSXC\Db\StanzaMapper */ private $stanzaMapper; @@ -102,16 +78,6 @@ class HttpBindController extends Controller { private $lock; /** - * @var bool - */ - private $debug; - - /** - * @var ILogger $logger - */ - private $logger; - - /** * @var PresenceHandler $presenceHandler */ private $presenceHandler; @@ -163,9 +129,7 @@ class HttpBindController extends Controller { ) { parent::__construct($appName, $request); $this->userId = $userId; - $this->pollingId = time(); $this->stanzaMapper = $stanzaMapper; - $this->host = $host; $this->iqHandler = $iqHandler; $this->messageHandler = $messageHandler; $this->body = $body; @@ -173,8 +137,6 @@ class HttpBindController extends Controller { $this->maxCicles = $maxCicles; $this->response = new XMPPResponse(); $this->lock = $lock; - $this->debug = defined('JSXC_ENV') && JSXC_ENV === 'dev'; - $this->logger = $logger; $this->presenceHandler = $presenceHandler; $this->presenceMapper = $presenceMapper; $this->newContentContainer = $newContentContainer; diff --git a/build/lib/db/presencemapper.php b/build/lib/db/presencemapper.php index 6beb0e1..b3a36f3 100644 --- a/build/lib/db/presencemapper.php +++ b/build/lib/db/presencemapper.php @@ -52,14 +52,14 @@ class PresenceMapper extends Mapper { /** * PresenceMapper constructor. * - * @param IDb|IDBConnection $db + * @param IDBConnection $db * @param string $host * @param null|string $userId * @param MessageMapper $messageMapper * @param NewContentContainer $newContentContainer * @param int $timeout */ - public function __construct(IDb $db, $host, $userId, MessageMapper $messageMapper, NewContentContainer $newContentContainer, $timeout) { + public function __construct(IDBConnection $db, $host, $userId, MessageMapper $messageMapper, NewContentContainer $newContentContainer, $timeout) { parent::__construct($db, 'ojsxc_presence'); $this->host = $host; $this->userId = $userId; @@ -76,13 +76,14 @@ class PresenceMapper extends Mapper { */ public function setPresence(PresenceEntity $stanza) { $sql = "UPDATE `*PREFIX*ojsxc_presence` SET `presence`=?, `last_active`=? WHERE `userid` = ?"; - $q = $this->db->prepareQuery($sql); + + $q = $this->db->prepare($sql); $q->execute([$stanza->getPresence(), $stanza->getLastActive(), $stanza->getUserid()]); if ($q->rowCount() === 0) { $sql = "INSERT INTO `*PREFIX*ojsxc_presence` (`userid`, `presence`, `last_active`) VALUES(?,?,?)"; - $q = $this->db->prepareQuery($sql); + $q = $this->db->prepare($sql); $q->execute([$stanza->getUserid(), $stanza->getPresence(), $stanza->getLastActive()]); } } @@ -141,7 +142,7 @@ class PresenceMapper extends Mapper { // just do an update since we can assume the user is already online // otherwise this wouldn't make sense $sql = "UPDATE `*PREFIX*ojsxc_presence` SET `last_active`=? WHERE `userid` = ?"; - $q = $this->db->prepareQuery($sql); + $q = $this->db->prepare($sql); $q->execute([time(), $user]); } diff --git a/build/lib/db/stanzamapper.php b/build/lib/db/stanzamapper.php index 0ab8234..10a63d2 100644 --- a/build/lib/db/stanzamapper.php +++ b/build/lib/db/stanzamapper.php @@ -21,10 +21,10 @@ class StanzaMapper extends Mapper { /** * StanzaMapper constructor. * - * @param IDb $db + * @param IDBConnection $db * @param string $host */ - public function __construct(IDb $db, $host) { + public function __construct(IDBConnection $db, $host) { parent::__construct($db, 'ojsxc_stanzas'); $this->host = $host; } @@ -39,7 +39,7 @@ class StanzaMapper extends Mapper { $writer->write($entity); $xml = $writer->outputMemory(); $sql = "INSERT INTO `*PREFIX*ojsxc_stanzas` (`to`, `from`, `stanza`) VALUES(?,?,?)"; - $q = $this->db->prepareQuery($sql); + $q = $this->db->prepare($sql); $q->execute([$entity->getTo(), $entity->getFrom(), $xml]); } diff --git a/build/lib/dblock.php b/build/lib/dblock.php index 8989122..aab0346 100644 --- a/build/lib/dblock.php +++ b/build/lib/dblock.php @@ -3,7 +3,6 @@ namespace OCA\OJSXC; use OCP\IConfig; -use OCP\IDb; /** * Class DbLock @@ -11,12 +10,6 @@ use OCP\IDb; * @package OCA\OJSXC */ class DbLock implements ILock { - - /** - * @var IDb $con - */ - private $con; - /** * @var IConfig $config */ @@ -36,11 +29,9 @@ class DbLock implements ILock { * DbLock constructor. * * @param string $userId - * @param IDb $con * @param IConfig $config */ - public function __construct($userId, IDb $con, IConfig $config) { - $this->con = $con; + public function __construct($userId, IConfig $config) { $this->userId = $userId; $this->config = $config; $this->pollingId = time(); @@ -54,11 +45,8 @@ class DbLock implements ILock { * @return bool */ public function stillLocked() { - $sql = "SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid`='ojsxc' AND `configkey`='longpolling'"; - $q = $this->con->prepareQuery($sql); - $r = $q->execute([$this->userId]); - $r = $r->fetchRow(); - return (int) $r['configvalue'] === (int) $this->pollingId; + $configValue = $this->config->getAppValue('ojsxc', 'longpolling'); + return (int) $configValue === (int) $this->pollingId; } -}
\ No newline at end of file +} |