-function diaspora_queue_hook(App $a, &$b) {
- $hostname = $a->getHostName();
-
- $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
- DBA::escape(Protocol::DIASPORA2)
- );
-
- if (!DBA::isResult($qi)) {
- return;
- }
-
- foreach ($qi as $x) {
- if ($x['network'] !== Protocol::DIASPORA2) {
- continue;
- }
-
- Logger::log('diaspora_queue: run');
-
- $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid`
- WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
- intval($x['cid'])
- );
-
- if (!DBA::isResult($r)) {
- continue;
- }
-
- $userdata = $r[0];
-
- $handle = PConfig::get($userdata['uid'], 'diaspora', 'handle');
- $password = PConfig::get($userdata['uid'], 'diaspora', 'password');
- $aspect = PConfig::get($userdata['uid'], 'diaspora', 'aspect');
-
- $success = false;
-
- if ($handle && $password) {
- Logger::log('diaspora_queue: able to post for user '.$handle);
-
- $z = unserialize($x['content']);
-
- $post = $z['post'];
-
- Logger::log('diaspora_queue: post: '.$post, Logger::DATA);
-
- try {
- Logger::log('diaspora_queue: prepare', Logger::DEBUG);
- $conn = new Diaspora_Connection($handle, $password);
- Logger::log('diaspora_queue: try to log in '.$handle, Logger::DEBUG);
- $conn->logIn();
- Logger::log('diaspora_queue: try to send '.$body, Logger::DEBUG);
- $conn->provider = $hostname;
- $conn->postStatusMessage($post, $aspect);
-
- Logger::log('diaspora_queue: send '.$userdata['uid'].' success', Logger::DEBUG);
-
- $success = true;
-
- Queue::removeItem($x['id']);
- } catch (Exception $e) {
- Logger::log("diaspora_queue: Send ".$userdata['uid']." failed: ".$e->getMessage(), Logger::DEBUG);
- }
- } else {
- Logger::log('diaspora_queue: send '.$userdata['uid'].' missing username or password', Logger::DEBUG);
- }
-
- if (!$success) {
- Logger::log('diaspora_queue: delayed');
- Queue::updateTime($x['id']);
- }
- }
-}
-