Improvements for the Diaspora protocol

This commit is contained in:
Michael 2018-04-24 18:34:35 +00:00
parent 8d8aef5624
commit ad45a73bf3

View file

@ -618,10 +618,13 @@ class Diaspora
// This is only needed for private postings since this is already done for public ones before // This is only needed for private postings since this is already done for public ones before
if (is_null($fields)) { if (is_null($fields)) {
$private = true;
if (!($fields = self::validPosting($msg))) { if (!($fields = self::validPosting($msg))) {
logger("Invalid posting"); logger("Invalid posting");
return false; return false;
} }
} else {
$private = false;
} }
$type = $fields->getName(); $type = $fields->getName();
@ -630,27 +633,47 @@ class Diaspora
switch ($type) { switch ($type) {
case "account_migration": case "account_migration":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveAccountMigration($importer, $fields); return self::receiveAccountMigration($importer, $fields);
case "account_deletion": case "account_deletion":
return self::receiveAccountDeletion($importer, $fields); return self::receiveAccountDeletion($fields);
case "comment": case "comment":
return self::receiveComment($importer, $sender, $fields, $msg["message"]); return self::receiveComment($importer, $sender, $fields, $msg["message"]);
case "contact": case "contact":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveContactRequest($importer, $fields); return self::receiveContactRequest($importer, $fields);
case "conversation": case "conversation":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveConversation($importer, $msg, $fields); return self::receiveConversation($importer, $msg, $fields);
case "like": case "like":
return self::receiveLike($importer, $sender, $fields); return self::receiveLike($importer, $sender, $fields);
case "message": case "message":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveMessage($importer, $fields); return self::receiveMessage($importer, $fields);
case "participation": case "participation":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveParticipation($importer, $fields); return self::receiveParticipation($importer, $fields);
case "photo": // Not implemented case "photo": // Not implemented
@ -660,6 +683,10 @@ class Diaspora
return self::receivePollParticipation($importer, $fields); return self::receivePollParticipation($importer, $fields);
case "profile": case "profile":
if (!$private) {
logger('Message with type ' . $type . ' is not private, quitting.');
return false;
}
return self::receiveProfile($importer, $fields); return self::receiveProfile($importer, $fields);
case "reshare": case "reshare":
@ -1601,25 +1628,23 @@ class Diaspora
/** /**
* @brief Processes an account deletion * @brief Processes an account deletion
* *
* @param array $importer Array of the importer user
* @param object $data The message object * @param object $data The message object
* *
* @return bool Success * @return bool Success
*/ */
private static function receiveAccountDeletion($importer, $data) private static function receiveAccountDeletion($data)
{ {
/// @todo Account deletion should remove the contact from the global contacts as well
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
$contact = self::contactByHandle($importer["uid"], $author); $contacts = dba::select('contact', ['id'], ['addr' => $author]);
if (!$contact) { while ($contact = dba::fetch($contacts)) {
logger("cannot find contact for author: ".$author); Contact::remove($contact["id"]);
return false;
} }
// We now remove the contact dba::delete('gcontact', ['addr' => $author]);
Contact::remove($contact["id"]);
logger('Removed contacts for ' . $author);
return true; return true;
} }