X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fspool.inc.php;fp=banana%2Fspool.inc.php;h=c938a24b1c25e69f5edcde228759d5077cdc9b7f;hb=dc12019c868a8e302a29e2730f7da8afa67ab990;hp=2a6be2e31d9474429d74df95b83478c25c86fdee;hpb=f0d8d46d2ace65fa202a31fd756463352c3bf560;p=banana.git diff --git a/banana/spool.inc.php b/banana/spool.inc.php index 2a6be2e..c938a24 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -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