]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / classes / User.php
index 022044aac117ba366d374937ff164964a2bd9de5..15ec4ad946192896d527b2e0fc4a6c1878c6fb5a 100644 (file)
@@ -48,11 +48,6 @@ class User extends Memcached_DataObject
     public $language;                        // varchar(50)
     public $timezone;                        // varchar(50)
     public $emailpost;                       // tinyint(1)   default_1
-    public $jabber;                          // varchar(255)  unique_key
-    public $jabbernotify;                    // tinyint(1)
-    public $jabberreplies;                   // tinyint(1)
-    public $jabbermicroid;                   // tinyint(1)   default_1
-    public $updatefrompresence;              // tinyint(1)
     public $sms;                             // varchar(64)  unique_key
     public $carrier;                         // int(4)
     public $smsnotify;                       // tinyint(1)
@@ -80,11 +75,7 @@ class User extends Memcached_DataObject
 
     function isSubscribed($other)
     {
-        assert(!is_null($other));
-        // XXX: cache results of this query
-        $sub = Subscription::pkeyGet(array('subscriber' => $this->id,
-                                           'subscribed' => $other->id));
-        return (is_null($sub)) ? false : true;
+        return Subscription::exists($this->getProfile(), $other);
     }
 
     // 'update' won't write key columns, so we have to do it ourselves.
@@ -92,7 +83,7 @@ class User extends Memcached_DataObject
     function updateKeys(&$orig)
     {
         $parts = array();
-        foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
+        foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
             if (strcmp($this->$k, $orig->$k) != 0) {
                 $parts[] = $k . ' = ' . $this->_quote($this->$k);
             }
@@ -167,17 +158,8 @@ class User extends Memcached_DataObject
 
     function hasBlocked($other)
     {
-
-        $block = Profile_block::get($this->id, $other->id);
-
-        if (is_null($block)) {
-            $result = false;
-        } else {
-            $result = true;
-            $block->free();
-        }
-
-        return $result;
+        $profile = $this->getProfile();
+        return $profile->hasBlocked($other);
     }
 
     /**
@@ -219,6 +201,7 @@ class User extends Memcached_DataObject
         if(! User::allowed_nickname($nickname)){
             common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
                        __FILE__);
+            return false;
         }
         $profile->profileurl = common_profile_url($nickname);
 
@@ -250,10 +233,6 @@ class User extends Memcached_DataObject
 
         $user->nickname = $nickname;
 
-        if (!empty($password)) { // may not have a password for OpenID users
-            $user->password = common_munge_password($password, $id);
-        }
-
         // Users who respond to invite email have proven their ownership of that address
 
         if (!empty($code)) {
@@ -286,6 +265,9 @@ class User extends Memcached_DataObject
 
             $user->id = $id;
             $user->uri = common_user_uri($user);
+            if (!empty($password)) { // may not have a password for OpenID users
+                $user->password = common_munge_password($password, $id);
+            }
 
             $result = $user->insert();
 
@@ -470,28 +452,28 @@ class User extends Memcached_DataObject
         return $user;
     }
 
-    function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $ids = Reply::stream($this->id, $offset, $limit, $since_id, $before_id, $since);
+        $ids = Reply::stream($this->id, $offset, $limit, $since_id, $before_id);
         return Notice::getStreamByIds($ids);
     }
 
-    function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) {
+    function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
         $profile = $this->getProfile();
         if (!$profile) {
             return null;
         } else {
-            return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id, $since);
+            return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
         }
     }
 
-    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
         $profile = $this->getProfile();
         if (!$profile) {
             return null;
         } else {
-            return $profile->getNotices($offset, $limit, $since_id, $before_id, $since);
+            return $profile->getNotices($offset, $limit, $since_id, $before_id);
         }
     }
 
@@ -501,30 +483,24 @@ class User extends Memcached_DataObject
         return Notice::getStreamByIds($ids);
     }
 
-    function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
-        return Notice::getStreamByIds($ids);
+        return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, false);
     }
 
-    function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-        return Notice::getStreamByIds($ids);
+        return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, true);
     }
 
-    function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
-
-        return Notice::getStreamByIds($ids);
+        return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, false);
     }
 
-    function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+    function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-
-        return Notice::getStreamByIds($ids);
+        return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, true);
     }
 
     function blowFavesCache()
@@ -632,28 +608,8 @@ class User extends Memcached_DataObject
 
     function getGroups($offset=0, $limit=null)
     {
-        $qry =
-          'SELECT user_group.* ' .
-          'FROM user_group JOIN group_member '.
-          'ON user_group.id = group_member.group_id ' .
-          'WHERE group_member.profile_id = %d ' .
-          'ORDER BY group_member.created DESC ';
-
-        if ($offset>0 && !is_null($limit)) {
-            if ($offset) {
-                if (common_config('db','type') == 'pgsql') {
-                    $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-                } else {
-                    $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-                }
-            }
-        }
-
-        $groups = new User_group();
-
-        $cnt = $groups->query(sprintf($qry, $this->id));
-
-        return $groups;
+        $profile = $this->getProfile();
+        return $profile->getGroups($offset, $limit);
     }
 
     function getSubscriptions($offset=0, $limit=null)
@@ -809,7 +765,7 @@ class User extends Memcached_DataObject
         return Notice::getStreamByIds($ids);
     }
 
-    function _repeatedByMeDirect($offset, $limit, $since_id, $max_id, $since)
+    function _repeatedByMeDirect($offset, $limit, $since_id, $max_id)
     {
         $notice = new Notice();
 
@@ -833,10 +789,6 @@ class User extends Memcached_DataObject
             $notice->whereAdd('id <= ' . $max_id);
         }
 
-        if (!is_null($since)) {
-            $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
-        }
-
         $ids = array();
 
         if ($notice->find()) {
@@ -856,12 +808,12 @@ class User extends Memcached_DataObject
         $ids = Notice::stream(array($this, '_repeatsOfMeDirect'),
                               array(),
                               'user:repeats_of_me:'.$this->id,
-                              $offset, $limit, $since_id, $max_id, null);
+                              $offset, $limit, $since_id, $max_id);
 
         return Notice::getStreamByIds($ids);
     }
 
-    function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id, $since)
+    function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id)
     {
         $qry =
           'SELECT DISTINCT original.id AS id ' .
@@ -876,10 +828,6 @@ class User extends Memcached_DataObject
             $qry .= 'AND original.id <= ' . $max_id . ' ';
         }
 
-        if (!is_null($since)) {
-            $qry .= 'AND original.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
-        }
-
         // NOTE: we sort by fave time, not by notice time!
 
         $qry .= 'ORDER BY original.id DESC ';
@@ -945,9 +893,9 @@ class User extends Memcached_DataObject
 
             $pr->orderBy('created');
 
-            $pr->limit(0, 1);
+            $pr->limit(1);
 
-            if ($pr->fetch($true)) {
+            if ($pr->find(true)) {
                 $owner = User::staticGet('id', $pr->profile_id);
             } else {
                 $owner = null;