X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDiaspora.php;h=41ed7e7d9f79b9db0f3d29ae37d24066b27012b8;hb=ce3b1210640ce653ef91cbf033788474c1f88b0c;hp=33cbb2659d8aabeec6e9d246ae4a39089f467bf6;hpb=4b80b7caeae957bdf447d4915914e9c3df4fa6cd;p=friendica.git diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 33cbb2659d..41ed7e7d9f 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -27,6 +27,7 @@ use Friendica\Model\Conversation; use Friendica\Model\GContact; use Friendica\Model\Group; use Friendica\Model\Item; +use Friendica\Model\Mail; use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Network\Probe; @@ -211,7 +212,7 @@ class Diaspora */ public static function participantsForThread($thread, array $contacts) { - $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`, + $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`, `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation` INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid` INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid` @@ -223,6 +224,10 @@ class Diaspora } unset($contact['fnetwork']); + if (empty($contact['protocol'])) { + $contact['protocol'] = $contact['network']; + } + if (empty($contact['batch']) && !empty($contact['fbatch'])) { $contact['batch'] = $contact['fbatch']; } @@ -400,7 +405,7 @@ class Diaspora if ($no_exit) { return false; } else { - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } } @@ -419,7 +424,7 @@ class Diaspora if ($no_exit) { return false; } else { - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } } @@ -445,7 +450,7 @@ class Diaspora if ($no_exit) { return false; } else { - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } } @@ -455,7 +460,7 @@ class Diaspora if ($no_exit) { return false; } else { - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } } @@ -465,7 +470,7 @@ class Diaspora if ($no_exit) { return false; } else { - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } } @@ -550,7 +555,7 @@ class Diaspora if (!$base) { Logger::log('unable to locate salmon data in xml'); - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } @@ -588,7 +593,7 @@ class Diaspora if (!$author_link) { Logger::log('Could not retrieve author URI.'); - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } // Once we have the author URI, go to the web and try to find their public key // (first this will look it up locally if it is in the fcontact cache) @@ -599,14 +604,14 @@ class Diaspora if (!$key) { Logger::log('Could not retrieve author key.'); - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { Logger::log('Message did not verify. Discarding.'); - System::httpExit(400); + throw new \Friendica\Network\HTTPException\BadRequestException(); } Logger::log('Message verified.'); @@ -1841,14 +1846,7 @@ class Diaspora $person = self::personByHandle($msg_author); - DBA::lock('mail'); - - if (DBA::exists('mail', ['guid' => $msg_guid, 'uid' => $importer["uid"]])) { - Logger::log("duplicate message already delivered.", Logger::DEBUG); - return false; - } - - DBA::insert('mail', [ + return Mail::insert([ 'uid' => $importer['uid'], 'guid' => $msg_guid, 'convid' => $conversation['id'], @@ -1858,36 +1856,10 @@ class Diaspora 'contact-id' => $contact['id'], 'title' => $subject, 'body' => $body, - 'seen' => 0, - 'reply' => 0, 'uri' => $message_uri, 'parent-uri' => $author . ':' . $guid, 'created' => $msg_created_at ]); - - $message_id = DBA::lastInsertId(); - - DBA::unlock(); - - DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]); - - notification([ - "type" => NOTIFY_MAIL, - "notify_flags" => $importer["notify-flags"], - "language" => $importer["language"], - "to_name" => $importer["username"], - "to_email" => $importer["email"], - "uid" => $importer["uid"], - "item" => ["id" => $message_id, "title" => $subject, "subject" => $subject, "body" => $body], - "parent" => $conversation["id"], - "source_name" => $person["name"], - "source_link" => $person["url"], - "source_photo" => $person["photo"], - "verb" => ACTIVITY_POST, - "otype" => "mail" - ]); - - return true; } /** @@ -2105,14 +2077,7 @@ class Diaspora $body = self::replacePeopleGuid($body, $person["url"]); - DBA::lock('mail'); - - if (DBA::exists('mail', ['guid' => $guid, 'uid' => $importer["uid"]])) { - Logger::log("duplicate message already delivered.", Logger::DEBUG); - return false; - } - - DBA::insert('mail', [ + return Mail::insert([ 'uid' => $importer['uid'], 'guid' => $guid, 'convid' => $conversation['id'], @@ -2122,36 +2087,11 @@ class Diaspora 'contact-id' => $contact['id'], 'title' => $conversation['subject'], 'body' => $body, - 'seen' => 0, 'reply' => 1, 'uri' => $message_uri, 'parent-uri' => $author.":".$conversation['guid'], 'created' => $created_at ]); - - $message_id = DBA::lastInsertId(); - - DBA::unlock(); - - DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]); - - notification([ - "type" => NOTIFY_MAIL, - "notify_flags" => $importer["notify-flags"], - "language" => $importer["language"], - "to_name" => $importer["username"], - "to_email" => $importer["email"], - "uid" => $importer["uid"], - "item" => ["id" => $message_id, "title" => $conversation["subject"], "subject" => $conversation["subject"], "body" => $body], - "parent" => $conversation["id"], - "source_name" => $person["name"], - "source_link" => $person["url"], - "source_photo" => $person["photo"], - "verb" => ACTIVITY_POST, - "otype" => "mail" - ]); - - return true; } /**