fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-12-29 12:02 pm

[dw-free] In mobile view, display first line of post when subject is empty

[commit: http://hg.dwscoalition.org/dw-free/rev/2e17a24bde7f]

http://bugs.dwscoalition.org/show_bug.cgi?id=2829

Show the first 40 characters of the entry if no subject was provided.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/LJ/CleanHTML.pm
  • htdocs/mobile/read.bml
--------------------------------------------------------------------------------
diff -r 9204faa7f6ec -r 2e17a24bde7f cgi-bin/LJ/CleanHTML.pm
--- a/cgi-bin/LJ/CleanHTML.pm	Thu Dec 29 19:14:06 2011 +0800
+++ b/cgi-bin/LJ/CleanHTML.pm	Thu Dec 29 20:02:31 2011 +0800
@@ -1432,12 +1432,12 @@
 
 # wrapper around clean_subject_all; this also trims the subject to the given length
 sub clean_and_trim_subject {
-    my $ref = shift;
-    my $length = shift || 40;
+    my ( $ref, $length, $truncated ) = @_;
+    $length ||= 40;
 
     LJ::CleanHTML::clean_subject_all($ref);
     $$ref =~ s/\n.*//s;
-    $$ref = LJ::text_trim($$ref, 0, $length);
+    $$ref = LJ::text_trim($$ref, 0, $length, $truncated);
 }
 
 my @comment_close = qw(
diff -r 9204faa7f6ec -r 2e17a24bde7f htdocs/mobile/read.bml
--- a/htdocs/mobile/read.bml	Thu Dec 29 19:14:06 2011 +0800
+++ b/htdocs/mobile/read.bml	Thu Dec 29 20:02:31 2011 +0800
@@ -93,7 +93,16 @@
             $who .= " in " . "<a href='" . $ju->journal_base . "/'><b>$ju->{user}</b></a>";
         }
 
-        $ret .= "$who: " . "<a href='$url'>" . ($entry->subject_text || "(no subject)") . "</a><br />";
+        my $subject = $entry->subject_text;
+        unless ( $subject ) {
+            $subject = $entry->event_text;
+
+            my $truncated = 0;
+            LJ::CleanHTML::clean_and_trim_subject( \$subject, undef, \$truncated );
+            $subject .= "..." if $truncated;
+        }
+
+        $ret .= "$who: " . "<a href='$url'>$subject</a><br />";
     }
     
     $ret .= BML::ml( '.read.noentries', { groupname => $groupname } ) unless $numentries;
--------------------------------------------------------------------------------