]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Work in progress: subscription approval policy field in place on user, hooked up...
[quix0rs-gnu-social.git] / classes / Profile.php
index d84d5da290dee37111a7c15fefb250079006b2dd..98fe9ede2facf0bcf7fc700291ed1e534f7cf84c 100644 (file)
@@ -198,90 +198,16 @@ class Profile extends Memcached_DataObject
 
     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
     {
-        $ids = Notice::stream(array($this, '_streamTaggedDirect'),
-                              array($tag),
-                              'profile:notice_ids_tagged:' . $this->id . ':' . $tag,
-                              $offset, $limit, $since_id, $max_id);
-        return Notice::getStreamByIds($ids);
-    }
+        $stream = new TaggedProfileNoticeStream($this, $tag);
 
-    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
-    {
-        // XXX: I'm not sure this is going to be any faster. It probably isn't.
-        $ids = Notice::stream(array($this, '_streamDirect'),
-                              array(),
-                              'profile:notice_ids:' . $this->id,
-                              $offset, $limit, $since_id, $max_id);
-
-        return Notice::getStreamByIds($ids);
+        return $stream->getNotices($offset, $limit, $since_id, $max_id);
     }
 
-    function _streamTaggedDirect($tag, $offset, $limit, $since_id, $max_id)
+    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
     {
-        // XXX It would be nice to do this without a join
-        // (necessary to do it efficiently on accounts with long history)
-
-        $notice = new Notice();
-
-        $query =
-          "select id from notice join notice_tag on id=notice_id where tag='".
-          $notice->escape($tag) .
-          "' and profile_id=" . intval($this->id);
-
-        $since = Notice::whereSinceId($since_id, 'id', 'notice.created');
-        if ($since) {
-            $query .= " and ($since)";
-        }
-
-        $max = Notice::whereMaxId($max_id, 'id', 'notice.created');
-        if ($max) {
-            $query .= " and ($max)";
-        }
-
-        $query .= ' order by notice.created DESC, id DESC';
-
-        if (!is_null($offset)) {
-            $query .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset);
-        }
-
-        $notice->query($query);
-
-        $ids = array();
+        $stream = new ProfileNoticeStream($this);
 
-        while ($notice->fetch()) {
-            $ids[] = $notice->id;
-        }
-
-        return $ids;
-    }
-
-    function _streamDirect($offset, $limit, $since_id, $max_id)
-    {
-        $notice = new Notice();
-
-        $notice->profile_id = $this->id;
-
-        $notice->selectAdd();
-        $notice->selectAdd('id');
-
-        Notice::addWhereSinceId($notice, $since_id);
-        Notice::addWhereMaxId($notice, $max_id);
-
-        $notice->orderBy('created DESC, id DESC');
-
-        if (!is_null($offset)) {
-            $notice->limit($offset, $limit);
-        }
-
-        $notice->find();
-
-        $ids = array();
-
-        while ($notice->fetch()) {
-            $ids[] = $notice->id;
-        }
-
-        return $ids;
+        return $stream->getNotices($offset, $limit, $since_id, $max_id);
     }
 
     function isMember($group)
@@ -371,52 +297,10 @@ class Profile extends Memcached_DataObject
         return $join;
     }
 
-    /**
-     * Cancel a pending group join...
-     *
-     * @param User_group $group
-     */
-    function cancelJoinGroup(User_group $group)
-    {
-        $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
-                                                   'group_id' => $group->id));
-        if ($request) {
-            if (Event::handle('StartCancelJoinGroup', array($group, $this))) {
-                $request->delete();
-                Event::handle('EndCancelJoinGroup', array($group, $this));
-            }
-        }
-    }
-
-    /**
-     * Complete a pending group join on our end...
-     *
-     * @param User_group $group
-     */
-    function completeJoinGroup(User_group $group)
-    {
-        $join = null;
-        $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
-                                                   'group_id' => $group->id));
-        if ($request) {
-            if (Event::handle('StartJoinGroup', array($group, $this))) {
-                $join = Group_member::join($group->id, $this->id);
-                $request->delete();
-                Event::handle('EndJoinGroup', array($group, $this));
-            }
-        } else {
-            throw new Exception(_m('Invalid group join approval: not pending.'));
-        }
-        if ($join) {
-            $join->notify();
-        }
-        return $join;
-    }
-
     /**
      * Leave a group that this profile is a member of.
      *
-     * @param User_group $group 
+     * @param User_group $group
      */
     function leaveGroup(User_group $group)
     {
@@ -552,7 +436,7 @@ class Profile extends Memcached_DataObject
             // This is the stream of favorite notices, in rev chron
             // order. This forces it into cache.
 
-            $ids = Fave::stream($this->id, 0, NOTICE_CACHE_WINDOW);
+            $ids = Fave::idStream($this->id, 0, CachingNoticeStream::CACHE_WINDOW);
 
             // If it's in the list, then it's a fave
 
@@ -564,7 +448,7 @@ class Profile extends Memcached_DataObject
             // then the cache has all available faves, so this one
             // is not a fave.
 
-            if (count($ids) < NOTICE_CACHE_WINDOW) {
+            if (count($ids) < CachingNoticeStream::CACHE_WINDOW) {
                 return false;
             }