]> git.mxchange.org Git - friendica.git/commitdiff
Improvements for following/unfollowing of Diaspora and OStatus
authorMichael <heluecht@pirati.ca>
Sat, 23 Sep 2017 14:48:27 +0000 (14:48 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 23 Sep 2017 14:48:27 +0000 (14:48 +0000)
include/diaspora.php
include/follow.php
mod/contacts.php
mod/unfollow.php

index 63958f30bf416616548a769f584d9bcdd73e0252..bc3541183d38574937183a280fab29dc9b62187d 100644 (file)
@@ -2018,7 +2018,7 @@ class Diaspora {
 
                $a = get_app();
 
-               if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
+               if ($contact["rel"] == CONTACT_IS_SHARING) {
                        dba::update('contact', array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
                                        array('id' => $contact["id"], 'uid' => $importer["uid"]));
                }
@@ -2129,8 +2129,8 @@ class Diaspora {
                // perhaps we were already sharing with this person. Now they're sharing with us.
                // That makes us friends.
                if ($contact) {
-                       if ($following && $sharing) {
-                               logger("Author ".$author." (Contact ".$contact["id"].") wants to have a bidirectional conection.", LOGGER_DEBUG);
+                       if ($following) {
+                               logger("Author ".$author." (Contact ".$contact["id"].") wants to follow us.", LOGGER_DEBUG);
                                self::receive_request_make_friend($importer, $contact);
 
                                // refetch the contact array
@@ -2138,7 +2138,7 @@ class Diaspora {
 
                                // If we are now friends, we are sending a share message.
                                // Normally we needn't to do so, but the first message could have been vanished.
-                               if (in_array($contact["rel"], array(CONTACT_IS_FRIEND, CONTACT_IS_FOLLOWER))) {
+                               if (in_array($contact["rel"], array(CONTACT_IS_FRIEND))) {
                                        $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer["uid"]));
                                        if ($u) {
                                                logger("Sending share message to author ".$author." - Contact: ".$contact["id"]." - User: ".$importer["uid"], LOGGER_DEBUG);
@@ -2146,9 +2146,10 @@ class Diaspora {
                                        }
                                }
                                return true;
-                       } else { /// @todo Handle all possible variations of adding and retracting of permissions
-                               logger("Author ".$author." (Contact ".$contact["id"].") wants to change the relationship: Following: ".$following." - sharing: ".$sharing. "(By now unsupported)", LOGGER_DEBUG);
-                               return false;
+                       } else {
+                               logger("Author ".$author." doesn't want to follow us anymore.", LOGGER_DEBUG);
+                               lose_follower($importer, $contact);
+                               return true;
                        }
                }
 
index 48e23bff627dc6341b628e4b0afccc84dce6d74c..cac713b12f93def8d69703b58305e54cf23ce721 100644 (file)
@@ -187,14 +187,10 @@ function new_contact($uid,$url,$interactive = false) {
 
        if (dbm::is_result($r)) {
                // update contact
-               if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) {
-                       q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d",
-                               intval(CONTACT_IS_FRIEND),
-                               intval($subhub),
-                               intval($r[0]['id']),
-                               intval($uid)
-                       );
-               }
+               $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
+
+               $fields = array('rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false);
+               dba::update('contact', $fields, array('id' => $r[0]['id']));
        } else {
                // check service class limits
 
@@ -222,7 +218,7 @@ function new_contact($uid,$url,$interactive = false) {
                        return $result;
                }
 
-               $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
+               $new_relation = ((in_array($ret['network'], array(NETWORK_MAIL))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
 
                // create contact record
                $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `network`, `pubkey`, `rel`, `priority`,
index 2539360552d20ad487e7127819f2b3c478edf010..eae4141bc9fe1b2294430e3211efa3060ca9f114 100644 (file)
@@ -348,7 +348,16 @@ function _contact_archive($contact_id, $orig_record) {
 function _contact_drop($contact_id, $orig_record) {
        $a = get_app();
 
-       terminate_friendship($a->user,$a->contact,$orig_record);
+       $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
+               WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
+               intval($a->user['uid'])
+       );
+       if (!dbm::is_result($r)) {
+               return;
+       }
+
+       $self = ""; // Unused parameter
+       terminate_friendship($r[0], $self, $orig_record);
        contact_remove($orig_record['id']);
 }
 
index d0baf87c441da88f338edb8531a63b66f5a07c63..8ee96a14c829e1b5e47e6baf1e98736f0d400464 100644 (file)
@@ -32,7 +32,7 @@ function unfollow_post(App $a) {
        if (!dbm::is_result($contact)) {
                notice(t("Contact wasn't found or can't be unfollowed."));
        } else {
-               if (in_array($contact['network'], array(NETWORK_OSTATUS))) {
+               if (in_array($contact['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA))) {
                        $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
                                WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
                                intval($uid)