]> git.mxchange.org Git - friendica.git/blobdiff - mod/unfollow.php
all endpoints are now working
[friendica.git] / mod / unfollow.php
index 30aca5688e395a39732ef4cc937b35ce9c4a082d..b80263a3ecd33349047e177f8ff964547b4c56d8 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
+use Friendica\Model\User;
 
 function unfollow_post()
 {
@@ -21,14 +22,14 @@ function unfollow_post()
                // NOTREACHED
        }
 
-       if ($_REQUEST['cancel']) {
+       if (!empty($_REQUEST['cancel'])) {
                goaway($return_url);
        }
 
        $uid = local_user();
        $url = notags(trim(defaults($_REQUEST, 'url', '')));
 
-       $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
+       $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
                $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
                normalise_link($url), $url];
        $contact = DBA::selectFirst('contact', [], $condition);
@@ -45,16 +46,15 @@ function unfollow_post()
                // NOTREACHED
        }
 
-       $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);
+       $dissolve = ($contact['rel'] == Contact::SHARING);
+
+       $owner = User::getOwnerDataById($uid);
+       if ($owner) {
+               Contact::terminateFriendship($owner, $contact, $dissolve);
        }
 
        // Sharing-only contacts get deleted as there no relationship any more
-       if ($contact['rel'] == Contact::SHARING) {
+       if ($dissolve) {
                Contact::remove($contact['id']);
                $return_path = 'contacts';
        } else {