Add a 'next unread message' button
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sat, 5 Aug 2006 16:38:03 +0000 (16:38 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:07 +0000 (00:35 +0100)
To be tested...

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@130 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/post.inc.php
banana/spool.inc.php
img/next_unread.gif [new file with mode: 0644]

index 1da8783..3ee59cf 100644 (file)
@@ -360,9 +360,10 @@ class BananaPost
     {
         global $banana;
         $ret = '<div class="banana_menu">';
-        $actions = Array('prevThread' => Array('prev_thread', _b_('Discussion précédente')),
+        $actions = Array('nextUnread' => Array('next_unread', _b_('Message non-lu suivant')),
                          'prevPost'   => Array('prev',        _b_('Article précédent')),
                          'nextPost'   => Array('next',        _b_('Article suivant')),
+                         'prevThread' => Array('prev_thread', _b_('Discussion précédente')),
                          'nextThread' => Array('next_thread', _b_('Discussion suivante')));
         foreach ($actions as $method=>$params) {
             $id = $banana->spool->$method($this->id);
index 2a6be2e..c938a24 100644 (file)
@@ -561,6 +561,59 @@ class BananaSpool
         }
         return null;
     }
+
+    /** Look for an unread message in the thread rooted by the message
+     * @param id INTEGER message number
+     */
+    function _nextUnread($id)
+    {
+        if (!$this->overview[$id]->isread) {
+            return $id;
+        }
+        foreach ($this->overview[$id]->children as $child) {
+            return $this->_nextUnread($child);
+        }
+        return null;
+    }
+
+    /** Find next unread message
+     * @param id INTEGER message number
+     */
+    function nextUnread($id)
+    {
+        // Look in message children
+        foreach ($this->overview[$id]->children as $child) {
+            $next = $this->_nextUnread($child);
+            if (is_null($next)) {
+                return $next;
+            }
+        }
+
+        // Look in current thread
+        $cur = $id;
+        while (true) {
+            $parent = $this->overview[$cur]->parent;
+            $ok     = false;
+            if (is_null($parent)) {
+                $array = &$this->overview[$parent]->children;
+            } else {
+                $array = &$this->roots;
+            }
+            foreach ($array as $child) {
+                if ($ok) {
+                    $next = $this->_nextUnread($child);
+                    if (!is_null($next)) {
+                        return $next;
+                    }
+                }
+                if ($child == $cur) {
+                    $ok = true;
+                }
+            }
+            $cur = $parent;
+        }
+        return null;
+    }    
 }
 
 // vim:set et sw=4 sts=4 ts=4
diff --git a/img/next_unread.gif b/img/next_unread.gif
new file mode 100644 (file)
index 0000000..f17429c
Binary files /dev/null and b/img/next_unread.gif differ