]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
getConversationUrl introduced for linking to conversations
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 1 May 2014 13:25:19 +0000 (15:25 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 1 May 2014 13:25:19 +0000 (15:25 +0200)
classes/Conversation.php
classes/Notice.php
lib/noticelistitem.php
plugins/EmailSummary/lib/useremailsummaryhandler.php
plugins/Realtime/RealtimePlugin.php
tests/ActivityGenerationTests.php
theme/neo/css/display.css

index c76b0169ffbd48408e656c56f75de7fe55542879..033b99384b0470f10c7e46d72bd37331eab79b5a 100755 (executable)
@@ -97,4 +97,22 @@ class Conversation extends Managed_DataObject
 
         return $cnt;
     }
+
+    static public function getUrlFromNotice(Notice $notice, $anchor=true)
+    {
+        $conv = self::getKV('id', $notice->conversation);
+        return $conv->getUrl($anchor ? $notice->id : null);
+    }
+
+    public function getUri()
+    {
+        return $this->uri;
+    }
+
+    public function getUrl($noticeId=null)
+    {
+        // FIXME: the URL router should take notice-id as an argument...
+        return common_local_url('conversation', array('id' => $this->id)) .
+                ($noticeId===null ? '' : "#notice-{$noticeId}");
+    }
 }
index d9a954e07dbcc0cdf74e65e39023c14f43e482aa..7311a257a618180d3cdb688fbf8f7d73ea996784 100644 (file)
@@ -210,11 +210,27 @@ class Notice extends Managed_DataObject
         return $this->uri;
     }
 
+    /*
+     * @param $root boolean If true, link to just the conversation root.
+     *
+     * @return URL to conversation
+     */
+    public function getConversationUrl($anchor=true)
+    {
+        return Conversation::getUrlFromNotice($this, $anchor);
+    }
+
+    /*
+     * Get the local representation URL of this notice.
+     */
     public function getLocalUrl()
     {
         return common_local_url('shownotice', array('notice' => $this->id), null, null, false);
     }
 
+    /*
+     * Get the original representation URL of this notice.
+     */
     public function getUrl()
     {
         // The risk is we start having empty urls and non-http uris...
index ad33acb26144939f83bdf60644a647e22c6ab08a..b8ebe3bede27a85264136246cdc99bc38cac1489 100644 (file)
@@ -126,7 +126,9 @@ class NoticeListItem extends Widget
             $this->showNoticeLink();
             $this->showNoticeSource();
             $this->showNoticeLocation();
-            $this->showContext();
+            if ($this->notice->hasConversation()) {
+                $this->showContext();
+            }
             $this->showRepeat();
             Event::handle('EndShowNoticeInfo', array($this));
         }
@@ -520,32 +522,11 @@ class NoticeListItem extends Widget
      */
     function showContext()
     {
-        if ($this->notice->hasConversation()) {
-            $conv = Conversation::getKV(
-                'id',
-                $this->notice->conversation
-            );
-            $convurl = $conv->uri;
-            if (!empty($convurl)) {
-                $this->out->text(' ');
-                $this->out->element(
-                    'a',
-                    array(
-                    'href' => $convurl.'#notice-'.$this->notice->id,
-                    'class' => 'response'),
-                    // TRANS: Addition in notice list item if notice is part of a conversation.
-                    _('in context')
-                );
-            } else {
-                $msg = sprintf(
-                    "Couldn't find Conversation ID %d to make 'in context'"
-                    . "link for Notice ID %d",
-                    $this->notice->conversation,
-                    $this->notice->id
-                );
-                common_log(LOG_WARNING, $msg);
-            }
-        }
+        $this->out->element('a',
+                            array('href' => $this->notice->getConversationUrl(),
+                                  'class' => 'conversation'),
+                            // TRANS: Addition in notice list item if notice is part of a conversation.
+                            _('in context'));
     }
 
     /**
index 15c1c85e80070cfb2470ced6037426984bb4e269..fe814a3fb5ba0610b5547a980f4ae63381c1b263 100644 (file)
@@ -183,17 +183,9 @@ class UserEmailSummaryHandler extends QueueHandler
                                         'title' => $dt),
                           common_date_string($notice->created));
             $out->elementEnd('a');
-            if ($notice->hasConversation()) {
-                $conv = Conversation::getKV('id', $notice->conversation);
-                $convurl = $conv->uri;
-                if (!empty($convurl)) {
-                    $out->text(' ');
-                    $out->element('a',
-                                  array('href' => $convurl.'#notice-'.$notice->id),
-                                  // TRANS: Link text for link to conversation view.
-                                  _m('in context'));
-                }
-            }
+            $out->element('a', array('href' => $notice->getConversationUrl()),
+                          // TRANS: Link text for link to conversation view.
+                          _m('in context'));
             $out->elementEnd('div');
             $out->elementEnd('td');
             $out->elementEnd('tr');
index 8087edd9df1e0f0748166f35d22d0959f9edda54..dfd3a9298fe713157f87a5eec4d8c060ee7f5095 100644 (file)
@@ -321,7 +321,7 @@ class RealtimePlugin extends Plugin
         $arr['url'] = $notice->getUrl();
         $arr['html'] = htmlspecialchars($notice->rendered);
         $arr['source'] = htmlspecialchars($arr['source']);
-        $arr['conversation_url'] = $this->getConversationUrl($notice);
+        $arr['conversation_url'] = $notice->getConversationUrl();
 
         $profile = $notice->getProfile();
         $arr['user']['profile_url'] = $profile->profileurl;
@@ -336,7 +336,7 @@ class RealtimePlugin extends Plugin
                 $arr['retweeted_status']['source'] = htmlspecialchars($original->source);
                 $originalProfile = $original->getProfile();
                 $arr['retweeted_status']['user']['profile_url'] = $originalProfile->profileurl;
-                $arr['retweeted_status']['conversation_url'] = $this->getConversationUrl($original);
+                $arr['retweeted_status']['conversation_url'] = $original->getConversationUrl();
             }
             unset($original);
         }
@@ -364,33 +364,6 @@ class RealtimePlugin extends Plugin
         return $tags;
     }
 
-    function getConversationUrl($notice)
-    {
-        $convurl = null;
-
-        if ($notice->hasConversation()) {
-            $conv = Conversation::getKV(
-                'id',
-                $notice->conversation
-            );
-            $convurl = $conv->uri;
-
-            if(empty($convurl)) {
-                $msg = sprintf( "Could not find Conversation ID %d to make 'in context'"
-                    . "link for Notice ID %d.",
-                    $notice->conversation,
-                    $notice->id
-                );
-
-                common_log(LOG_WARNING, $msg);
-            } else {
-                $convurl .= '#notice-' . $notice->id;
-            }
-        }
-
-        return $convurl;
-    }
-
     function _getScripts()
     {
         $urlpath = self::staticPath(str_replace('Plugin','',__CLASS__),
index 8e89024ac01447fb4f14302a27d83f7f019b6821..bf0dcb2377558e5ec4fdfa82126cbc7b46a7712d 100644 (file)
@@ -526,7 +526,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
 
         $element = $this->_entryToElement($entry, true);
 
-        $this->assertEquals($conv->uri, ActivityUtils::getLink($element, 'ostatus:conversation'));
+        $this->assertEquals($conv->getUri(), ActivityUtils::getLink($element, 'ostatus:conversation'));
     }
 
     function __destruct()
index 7c883922bb0257a49d34736bca2e64ec312e3f46..c5da9e7d8cb3d1ceafab26564ab7501be6294ac8 100644 (file)
@@ -457,11 +457,11 @@ h6 {font-size: 1em;}
     max-width: 440px;
 }
 
-div.entry-content a.response:before {
-       content: "(";
+.entry-content a.conversation:before {
+       content: " (";
 }
 
-div.entry-content a.response:after {
+.entry-content a.conversation:after {
        content: ")";
 }