]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/subs.php
removed a stay bit of debug
[quix0rs-gnu-social.git] / lib / subs.php
index 1c240c475d40c7f71fd428de44eec07499dc3baa..e2ce0667eb19f78e3c2e9f5aed9fb0fdcc76df47 100644 (file)
@@ -42,4 +42,47 @@ function subs_unsubscribe_to($user, $other)
     } catch (Exception $e) {
         return $e->getMessage();
     }
-}
\ No newline at end of file
+}
+
+function subs_unsubscribe_from($user, $other){
+   $local = User::staticGet("nickname",$other);
+   if($local){
+     return subs_unsubscribe_to($local,$user);
+   } else {
+    try {
+        $remote = Profile::staticGet("nickname",$other);
+        if(is_string($remote)){
+          return $remote;
+        }
+        if (Event::handle('StartUnsubscribe', array($remote,$user))) {
+
+            $sub = DB_DataObject::factory('subscription');
+
+            $sub->subscriber = $remote->id;
+            $sub->subscribed = $user->id;
+
+            $sub->find(true);
+
+            // note we checked for existence above
+
+            if (!$sub->delete())
+              return _('Couldn\'t delete subscription.');
+
+            $cache = common_memcache();
+
+            if ($cache) {
+                $cache->delete(common_cache_key('user:notices_with_friends:' . $remote->id));
+            }
+
+
+            $user->blowSubscribersCount();
+            $remote->blowSubscribersCount();
+
+            Event::handle('EndUnsubscribe', array($remote, $user));
+        }
+    } catch (Exception $e) {
+        return $e->getMessage();
+    }
+   }
+}
+