]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Store direct messages as an activity
[quix0rs-gnu-social.git] / classes / Notice.php
index a0b2e910658077273120bcdf9c81c4eae73ee06d..9a4b6db7fffadf8d5b62ee573f5b32bc003e99aa 100644 (file)
@@ -1008,10 +1008,7 @@ class Notice extends Managed_DataObject
                 $users = $ptag->getUserSubscribers();
                 foreach ($users as $id) {
                     if (!array_key_exists($id, $ni)) {
-                        $user = User::staticGet('id', $id);
-                        if (!$user->hasBlocked($profile)) {
-                            $ni[$id] = NOTICE_INBOX_SOURCE_PROFILE_TAG;
-                        }
+                        $ni[$id] = NOTICE_INBOX_SOURCE_PROFILE_TAG;
                     }
                 }
             }
@@ -1020,23 +1017,30 @@ class Notice extends Managed_DataObject
                 if (!array_key_exists($recipient, $ni)) {
                     $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY;
                 }
+            }
 
-                // Exclude any deleted, non-local, or blocking recipients.
-                $profile = $this->getProfile();
-                $originalProfile = null;
-                if ($this->repeat_of) {
-                    // Check blocks against the original notice's poster as well.
-                    $original = Notice::staticGet('id', $this->repeat_of);
-                    if ($original) {
-                        $originalProfile = $original->getProfile();
-                    }
+            // Exclude any deleted, non-local, or blocking recipients.
+            $profile = $this->getProfile();
+            $originalProfile = null;
+            if ($this->repeat_of) {
+                // Check blocks against the original notice's poster as well.
+                $original = Notice::staticGet('id', $this->repeat_of);
+                if ($original) {
+                    $originalProfile = $original->getProfile();
                 }
-                foreach ($ni as $id => $source) {
+            }
+
+            foreach ($ni as $id => $source) {
+                try {
                     $user = User::staticGet('id', $id);
-                    if (empty($user) || $user->hasBlocked($profile) ||
+                    if (empty($user) ||
+                        $user->hasBlocked($profile) ||
                         ($originalProfile && $user->hasBlocked($originalProfile))) {
                         unset($ni[$id]);
                     }
+                } catch (UserNoProfileException $e) {
+                    // User doesn't have a profile; invalid; skip them.
+                    unset($ni[$id]);
                 }
             }
 
@@ -1489,7 +1493,7 @@ class Notice extends Managed_DataObject
      * @return Activity activity object representing this Notice.
      */
 
-    function asActivity($cur)
+    function asActivity($cur=null)
     {
         $act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
 
@@ -1504,7 +1508,6 @@ class Notice extends Managed_DataObject
             $act->time    = strtotime($this->created);
             $act->link    = $this->bestUrl();
             $act->content = common_xml_safe_str($this->rendered);
-            $act->title   = common_xml_safe_str($this->content);
 
             $profile = $this->getProfile();
 
@@ -1515,7 +1518,9 @@ class Notice extends Managed_DataObject
 
             if ($this->repeat_of) {
                 $repeated = Notice::staticGet('id', $this->repeat_of);
-                $act->objects[] = $repeated->asActivity($cur);
+                if (!empty($repeated)) {
+                    $act->objects[] = $repeated->asActivity($cur);
+                }
             } else {
                 $act->objects[] = ActivityObject::fromNotice($this);
             }
@@ -1539,9 +1544,9 @@ class Notice extends Managed_DataObject
             $attachments = $this->attachments();
 
             foreach ($attachments as $attachment) {
-                $enclosure = $attachment->getEnclosure();
-                if ($enclosure) {
-                    $act->enclosures[] = $enclosure;
+                // Save local attachments
+                if (!empty($attachment->filename)) {
+                    $act->attachments[] = ActivityObject::fromFile($attachment);
                 }
             }
 
@@ -1572,6 +1577,7 @@ class Notice extends Managed_DataObject
                 $rprofile = Profile::staticGet('id', $id);
                 if (!empty($rprofile)) {
                     $ctx->attention[] = $rprofile->getUri();
+                    $ctx->attentionType[$rprofile->getUri()] = ActivityObject::PERSON;
                 }
             }
 
@@ -1579,6 +1585,19 @@ class Notice extends Managed_DataObject
 
             foreach ($groups as $group) {
                 $ctx->attention[] = $group->getUri();
+                $ctx->attentionType[$group->getUri()] = ActivityObject::GROUP;
+            }
+
+            switch ($this->scope) {
+            case Notice::PUBLIC_SCOPE:
+                $ctx->attention[] = "http://activityschema.org/collection/public";
+                $ctx->attentionType["http://activityschema.org/collection/public"] = ActivityObject::COLLECTION;
+                break;
+            case Notice::FOLLOWER_SCOPE:
+                $surl = common_local_url("subscribers", array('nickname' => $profile->nickname));
+                $ctx->attention[] = $surl;
+                $ctx->attentionType[$surl] = ActivityObject::COLLECTION;
+                break;
             }
 
             // XXX: deprecated; use ActivityVerb::SHARE instead
@@ -1595,6 +1614,12 @@ class Notice extends Managed_DataObject
 
             $act->context = $ctx;
 
+            $source = $this->getSource();
+
+            if ($source) {
+                $act->generator = ActivityObject::fromNoticeSource($source);
+            }
+
             // Source
 
             $atom_feed = $profile->getAtomFeed();
@@ -2454,7 +2479,11 @@ class Notice extends Managed_DataObject
 
             if ($scope & Notice::FOLLOWER_SCOPE) {
 
-                $author = $this->getProfile();
+                try {
+                    $author = $this->getProfile();
+                } catch (Exception $e) {
+                    return false;
+                }
         
                 if (!Subscription::exists($profile, $author)) {
                     return false;
@@ -2471,10 +2500,16 @@ class Notice extends Managed_DataObject
 
         if (common_config('notice', 'hidespam')) {
 
-            $author = $this->getProfile();
+            try {
+                $author = $this->getProfile();
+            } catch(Exception $e) {
+                // If we can't get an author, keep it hidden.
+                // XXX: technically not spam, but, whatever.
+                return true;
+            }
 
             if ($author->hasRole(Profile_role::SILENCED)) {
-                if (empty($profile) || !$profile->hasRole(Profile_role::MODERATOR)) {
+                if (empty($profile) || (($profile->id !== $author->id) && (!$profile->hasRight(Right::REVIEWSPAM)))) {
                     return true;
                 }
             }