]> git.mxchange.org Git - friendica.git/commitdiff
Fix unfollow for sharing-only contacts
authorHypolite Petovan <mrpetovan@gmail.com>
Thu, 30 Aug 2018 12:27:31 +0000 (08:27 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Thu, 30 Aug 2018 12:28:10 +0000 (08:28 -0400)
- Add removal when unfollowing sharing-only contacts

mod/unfollow.php

index 5c00726e272bfb7224d577ce740eea9ae576217a..5942171247a86f29c6698d5df78b7b34080b2132 100644 (file)
@@ -27,29 +27,37 @@ function unfollow_post(App $a)
        $url = notags(trim($_REQUEST['url']));
        $return_url = $_SESSION['return_url'];
 
-       $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
-                       $uid, Contact::FRIEND, normalise_link($url),
+       $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
+                       $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
                        normalise_link($url), $url, Protocol::STATUSNET];
        $contact = DBA::selectFirst('contact', [], $condition);
 
        if (!DBA::isResult($contact)) {
                notice(L10n::t("Contact wasn't found or can't be unfollowed."));
-       } else {
-               if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
-                       $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)
-                       );
-                       if (DBA::isResult($r)) {
-                               Contact::terminateFriendship($r[0], $contact);
-                       }
+               goaway($return_url);
+       }
+
+       if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
+               $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)
+               );
+               if (DBA::isResult($r)) {
+                       Contact::terminateFriendship($r[0], $contact);
                }
-               DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
+       }
 
-               info(L10n::t('Contact unfollowed').EOL);
-               goaway(System::baseUrl().'/contacts/'.$contact['id']);
+       // Sharing-only contacts get deleted as there no relationship any more
+       if ($contact['rel'] == Contact::SHARING) {
+               Contact::remove($contact['id']);
+               $return_path = 'contacts';
+       } else {
+               DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
+               $return_path = 'contacts/' . $contact['id'];
        }
-       goaway($return_url);
+
+       info(L10n::t('Contact unfollowed'));
+       goaway($return_path);
        // NOTREACHED
 }
 
@@ -66,8 +74,8 @@ function unfollow_content(App $a)
 
        $submit = L10n::t('Submit Request');
 
-       $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
-                       local_user(), Contact::FRIEND, normalise_link($url),
+       $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
+                       local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
                        normalise_link($url), $url, Protocol::STATUSNET];
 
        $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);