]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Minor labeling things for StatusNet to GNU social migration
[quix0rs-gnu-social.git] / classes / Notice.php
index df05ce465061dd0eacf2fe8f5bf9e2c0e9f04da3..4b0db2988da188bd2374cb136efd29407ae0f641 100644 (file)
  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Table Definition for notice
  */
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
 /* We keep 200 notices, the max number of notices available per API request,
  * in the memcached cache. */
@@ -162,7 +159,7 @@ class Notice extends Managed_DataObject
         $this->_profile = $profile;
     }
 
-    function delete()
+    function delete($useWhere=false)
     {
         // For auditing purposes, save a record that the notice
         // was deleted.
@@ -171,11 +168,11 @@ class Notice extends Managed_DataObject
         // insert fails.
         $deleted = Deleted_notice::getKV('id', $this->id);
 
-        if (!$deleted) {
+        if (!$deleted instanceof Deleted_notice) {
             $deleted = Deleted_notice::getKV('uri', $this->uri);
         }
 
-        if (!$deleted) {
+        if (!$deleted instanceof Deleted_notice) {
             $deleted = new Deleted_notice();
 
             $deleted->id         = $this->id;
@@ -202,7 +199,7 @@ class Notice extends Managed_DataObject
             // NOTE: we don't clear queue items
         }
 
-        $result = parent::delete();
+        $result = parent::delete($useWhere);
 
         $this->blowOnDelete();
         return $result;
@@ -410,9 +407,8 @@ class Notice extends Managed_DataObject
         $notice->url = $url;
 
         // Get the groups here so we can figure out replies and such
-
         if (!isset($groups)) {
-            $groups = self::groupsFromText($notice->content, $profile);
+            $groups = User_group::idsFromText($notice->content, $profile);
         }
 
         $reply = null;
@@ -1154,7 +1150,7 @@ class Notice extends Managed_DataObject
         $groups = array();
         foreach (array_unique($group_ids) as $id) {
             $group = User_group::getKV('id', $id);
-            if ($group) {
+            if ($group instanceof User_group) {
                 common_log(LOG_ERR, "Local delivery to group id $id, $group->nickname");
                 $result = $this->addToGroupInbox($group);
                 if (!$result) {
@@ -1181,48 +1177,7 @@ class Notice extends Managed_DataObject
         return $groups;
     }
 
-    /**
-     * Parse !group delivery and record targets into group_inbox.
-     * @return array of Group objects
-     */
-    function saveGroups()
-    {
-        // Don't save groups for repeats
-
-        if (!empty($this->repeat_of)) {
-            return array();
-        }
-
-        $profile = $this->getProfile();
-
-        $groups = self::groupsFromText($this->content, $profile);
-
-        /* Add them to the database */
-
-        foreach ($groups as $group) {
-            /* XXX: remote groups. */
-
-            if (empty($group)) {
-                continue;
-            }
-
-
-            if ($profile->isMember($group)) {
-
-                $result = $this->addToGroupInbox($group);
-
-                if (!$result) {
-                    common_log_db_error($gi, 'INSERT', __FILE__);
-                }
-
-                $groups[] = clone($group);
-            }
-        }
-
-        return $groups;
-    }
-
-    function addToGroupInbox($group)
+    function addToGroupInbox(User_group $group)
     {
         $gi = Group_inbox::pkeyGet(array('group_id' => $group->id,
                                          'notice_id' => $this->id));
@@ -1445,7 +1400,7 @@ class Notice extends Managed_DataObject
 
     /**
      * Pull list of groups this notice needs to be delivered to,
-     * as previously recorded by saveGroups() or saveKnownGroups().
+     * as previously recorded by saveKnownGroups().
      *
      * @return array of Group objects
      */
@@ -2500,29 +2455,6 @@ class Notice extends Managed_DataObject
         return false;
     }
 
-    static function groupsFromText($text, $profile)
-    {
-        $groups = array();
-
-        /* extract all !group */
-        $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/',
-                                strtolower($text),
-                                $match);
-
-        if (!$count) {
-            return $groups;
-        }
-
-        foreach (array_unique($match[1]) as $nickname) {
-            $group = User_group::getForNickname($nickname, $profile);
-            if ($group instanceof User_group && $profile->isMember($group)) {
-                $groups[] = $group->id;
-            }
-        }
-
-        return $groups;
-    }
-
     public function getParent()
     {
         $parent = Notice::getKV('id', $this->reply_to);