mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2010-01-08 11:43 pm

[dw-free] add an inbox area for "Unread items"

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

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

Add new area to the inbox to see only unread items.

Patch by [personal profile] afuna.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/LJ/NotificationInbox.pm
  • cgi-bin/LJ/Widget/InboxFolderNav.pm
  • htdocs/js/esn_inbox.js
--------------------------------------------------------------------------------
diff -r 158ae7b4a767 -r c9ab986c6c8d bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Fri Jan 08 23:41:34 2010 +0000
+++ b/bin/upgrading/en.dat	Fri Jan 08 23:43:26 2010 +0000
@@ -1985,6 +1985,8 @@ inbox.menu.poll_votes=Poll Votes
 
 inbox.menu.sent=Sent
 
+inbox.menu.unread=Unread
+
 inbox.message=Message
 
 inbox.messages=Messages
diff -r 158ae7b4a767 -r c9ab986c6c8d cgi-bin/LJ/NotificationInbox.pm
--- a/cgi-bin/LJ/NotificationInbox.pm	Fri Jan 08 23:41:34 2010 +0000
+++ b/cgi-bin/LJ/NotificationInbox.pm	Fri Jan 08 23:43:26 2010 +0000
@@ -195,6 +195,13 @@ sub archived_items {
     my $u = $self->u;
     my $archive = $u->notification_archive;
     return $archive->items;
+}
+
+# return unread notifications
+sub unread_items {
+    my $self = shift;
+
+    return grep { $_->unread } $self->items;
 }
 
 sub count {
@@ -572,6 +579,8 @@ sub delete_all {
         @items = $self->singleentry_items( $itemid );
     } elsif ( $view eq 'pollvote' ) {
         @items = $self->pollvote_items;
+    } elsif ( $view eq 'unread' ) {
+        @items = $self->unread_items;
     }
 
     @items = grep { !$self->is_bookmark($_->qid) } @items
@@ -620,6 +629,8 @@ sub mark_all_read {
         @items = $self->singleentry_items( $itemid );
     } elsif ( $view eq 'pollvote' ) {
         @items = $self->pollvote_items;
+    } elsif ( $view eq 'unread' ) {
+        @items = $self->unread_items;
     }
 
     # Mark read
diff -r 158ae7b4a767 -r c9ab986c6c8d cgi-bin/LJ/Widget/InboxFolderNav.pm
--- a/cgi-bin/LJ/Widget/InboxFolderNav.pm	Fri Jan 08 23:41:34 2010 +0000
+++ b/cgi-bin/LJ/Widget/InboxFolderNav.pm	Fri Jan 08 23:43:26 2010 +0000
@@ -79,9 +79,11 @@ sub render_body {
             $message_button
             <div class="folders"><p>
     };
+
+    my $unread_all_html = $unread_html->( $unread_count );
     $body .= '<a href="." id="esn_folder_all"';
     $body .= ' class="active"' unless $opts{view};
-    $body .= "><?_ml inbox.menu.all _ml?>" . $unread_html->( $unread_count ) . "</a>";
+    $body .= "><?_ml inbox.menu.all _ml?>$unread_all_html</a>";
     $body .= $subfolder_link->( "usermsg_recvd", "inbox.menu.messages", "subs", 
         $unread_html->( $inbox->usermsg_recvd_event_count ) ) if LJ::is_enabled( 'user_messaging' );
     $body .= $subfolder_link->( "circle", "inbox.menu.circle_updates", "subs", $unread_html->( $inbox->circle_event_count ) );
@@ -90,6 +92,7 @@ sub render_body {
     $body .= $subfolder_link->( "entrycomment", "inbox.menu.entries_and_comments", "subs", $unread_html->( $inbox->entrycomment_event_count ) );
     $body .= $subfolder_link->( "pollvote", "inbox.menu.poll_votes", "subs", $unread_html->( $inbox->pollvote_event_count ) );
     $body .= qq{<span class="subs">---</span>\n};
+    $body .= $subfolder_link->( "unread", "inbox.menu.unread", "subs", $unread_all_html );
     $body .= $subfolder_link->( "bookmark", "inbox.menu.bookmarks", "subs", "", 
         qq{<img src="$LJ::IMGPREFIX/flag_on.gif" width="12" height="14" border="0" />} );
     $body .= $subfolder_link->( "usermsg_sent", "inbox.menu.sent", "subs", 
diff -r 158ae7b4a767 -r c9ab986c6c8d htdocs/js/esn_inbox.js
--- a/htdocs/js/esn_inbox.js	Fri Jan 08 23:41:34 2010 +0000
+++ b/htdocs/js/esn_inbox.js	Fri Jan 08 23:43:26 2010 +0000
@@ -317,10 +317,10 @@ ESN_Inbox.finishedUpdate = function (inf
 
         if (!qid) return;
 
-        if (!read && !deleted) unread_count++;
-
         var rowElement = $(folder + "_Row_" + qid);
         if (!rowElement) return;
+
+        if (!read && !deleted) unread_count++;
 
         var bookmarks = DOM.getElementsByClassName(rowElement, "InboxItem_Bookmark") || [];
         for (var i=0; i<bookmarks.length; i++) {
@@ -353,6 +353,7 @@ ESN_Inbox.finishedUpdate = function (inf
     });
 
     ESN_Inbox.refresh_count("esn_folder_all", info.unread_all);
+    ESN_Inbox.refresh_count("esn_folder_unread", info.unread_all);
     ESN_Inbox.refresh_count("esn_folder_usermsg_recvd", info.unread_usermsg_recvd);
     ESN_Inbox.refresh_count("esn_folder_circle", info.unread_friend);
     ESN_Inbox.refresh_count("esn_folder_entrycomment", info.unread_entrycomment);
@@ -367,7 +368,10 @@ ESN_Inbox.finishedUpdate = function (inf
         // no rows left, refresh page if more messages
         if (inbox_count != 0)
             window.location.href = $("RefreshLink").href;
-    }
+    } else if ( cur_folder == "unread" && info.unread_all > 0 && unread_count == 0 ) {
+        // unread folder, there are still more unread items, but we have marked everything on this page read
+        window.location.href = $("RefreshLink").href;
+    } 
 
     if (inbox_count == 0) {
         // reset if no messages
--------------------------------------------------------------------------------