From 29b39739df3393f138dbdd98591e1331af0393ad Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 04 Nov 2010 09:48:17 -0400
Subject: [PATCH] - Improve responsiveness of messages displaying (#1486986)

---
 CHANGELOG                      |    1 
 program/steps/mail/pagenav.inc |   74 ++++++++++++++++++++++++
 program/steps/mail/func.inc    |   17 ++---
 program/steps/mail/show.inc    |   45 ---------------
 program/js/app.js              |   21 ++++---
 5 files changed, 93 insertions(+), 65 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c3cd2f3..a50d69f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -62,6 +62,7 @@
 - Add option to place replies in the folder of the message being replied to (#1485945)
 - Add missing confirmation/error messages on contact/group/message actions (#1486845)
 - Add 'loading' message on message move/copy/delete/mark actions
+- Improve responsiveness of messages displaying (#1486986)
 
 RELEASE 0.4.2
 -------------
diff --git a/program/js/app.js b/program/js/app.js
index 30eaef5..13711ff 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -210,11 +210,9 @@
           this.enable_command(this.env.message_commands, this.env.uid);
           this.enable_command('reply-list', this.env.list_post);
 
-          if (this.env.next_uid) {
-            this.enable_command('nextmessage', 'lastmessage', true);
-          }
-          if (this.env.prev_uid) {
-            this.enable_command('previousmessage', 'firstmessage', true);
+          if (this.env.action == 'show') {
+            this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox),
+              this.display_message('', 'loading'));
           }
 
           if (this.env.blockedobjects) {
@@ -4595,10 +4593,15 @@
     var date = new Date(),
       id = type + date.getTime();
 
-    // The same message of type 'loading' is already displayed
-    if (type == 'loading' && this.messages[msg]) {
-       this.messages[msg].elements.push(id);
-       return id;
+    if (type == 'loading') {
+      if (!msg)
+        msg = this.get_label('loading');
+
+      // The same message of type 'loading' is already displayed
+      if (this.messages[msg]) {
+        this.messages[msg].elements.push(id);
+        return id;
+      }
     }
 
     var ref = this,
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 11df128..1237c92 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -423,14 +423,16 @@
 
 function rcmail_messagecount_display($attrib)
   {
-  global $IMAP, $OUTPUT;
+  global $RCMAIL;
 
   if (!$attrib['id'])
     $attrib['id'] = 'rcmcountdisplay';
 
-  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
+  $RCMAIL->output->add_gui_object('countdisplay', $attrib['id']);
 
-  return html::span($attrib, rcmail_get_messagecount_text());
+  $content =  $RCMAIL->action != 'show' ? rcmail_get_messagecount_text() : rcube_label('loading');
+
+  return html::span($attrib, $content);
   }
 
 
@@ -495,14 +497,7 @@
 
 function rcmail_get_messagecount_text($count=NULL, $page=NULL)
   {
-  global $RCMAIL, $IMAP, $MESSAGE;
-
-  if (isset($MESSAGE->index))
-    {
-    return rcube_label(array('name' => 'messagenrof',
-        'vars' => array('nr'  => $MESSAGE->index+1,
-        'count' => $count!==NULL ? $count : $IMAP->messagecount(NULL, 'ALL')))); // Only messages, no threads here
-    }
+  global $RCMAIL, $IMAP;
 
   if ($page===NULL)
     $page = $IMAP->list_page;
diff --git a/program/steps/mail/pagenav.inc b/program/steps/mail/pagenav.inc
new file mode 100644
index 0000000..b62520f
--- /dev/null
+++ b/program/steps/mail/pagenav.inc
@@ -0,0 +1,74 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/mail/pagenav.inc                                        |
+ |                                                                       |
+ | This file is part of the Roundcube Webmail client                     |
+ | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
+ | Licensed under the GNU GPL                                            |
+ |                                                                       |
+ | PURPOSE:                                                              |
+ |   Updates message page navigation controls                            |
+ |                                                                       |
+ +-----------------------------------------------------------------------+
+ | Author: Aleksander Machniak <alec@alec.pl>                            |
+ +-----------------------------------------------------------------------+
+
+ $Id: show.inc 4176 2010-11-04 09:59:55Z alec $
+
+*/
+
+$uid = get_input_value('_uid', RCUBE_INPUT_GET);
+$cnt  = $IMAP->messagecount(NULL, 'ALL'); // Only messages, no threads here
+
+if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
+    && empty($_REQUEST['_search']) && !$CONFIG['skip_deleted'] && !$IMAP->threading
+) {
+    // this assumes that we are sorted by date_DESC
+    $seq   = $IMAP->get_id($uid);
+    $index = $cnt - $seq;
+
+    $prev  = $IMAP->get_uid($seq + 1);
+    $first = $IMAP->get_uid($cnt);
+    $next  = $IMAP->get_uid($seq - 1);
+    $last  = $IMAP->get_uid(1);
+}
+else {
+    // Only if we use custom sorting
+    $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
+
+    $index = array_search($IMAP->get_id($uid), $a_msg_index);
+
+    $count = count($a_msg_index);
+    $prev  = isset($a_msg_index[$index-1]) ? $IMAP->get_uid($a_msg_index[$index-1]) : -1;
+    $first = $count > 1 ? $IMAP->get_uid($a_msg_index[0]) : -1;
+    $next  = isset($a_msg_index[$index+1]) ? $IMAP->get_uid($a_msg_index[$index+1]) : -1;
+    $last  = $count > 1 ? $IMAP->get_uid($a_msg_index[$count-1]) : -1;
+}
+
+// Set UIDs and activate navigation buttons
+if ($prev > 0) {
+    $OUTPUT->set_env('prev_uid', $prev);
+    $OUTPUT->command('enable_command', 'previousmessage', 'firstmessage', true);
+}
+if ($next > 0) {
+    $OUTPUT->set_env('next_uid', $next);
+    $OUTPUT->command('enable_command', 'nextmessage', 'lastmessage', true);
+}
+if ($first > 0)
+    $OUTPUT->set_env('first_uid', $first);
+if ($last > 0)
+    $OUTPUT->set_env('last_uid', $last);
+
+// Don't need a real messages count value
+$OUTPUT->set_env('messagecount', 1);
+
+// Set rowcount text
+$OUTPUT->command('set_rowcount', rcube_label(array(
+    'name' => 'messagenrof',
+    'vars' => array('nr'  => $index+1, 'count' => $cnt)
+)));
+
+$OUTPUT->send();
+
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index 41b4bc6..e660207 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -94,51 +94,6 @@
     }
   }
 
-  // get previous, first, next and last message UID
-  if ($RCMAIL->action != 'preview' && $RCMAIL->action != 'print')
-    {
-    $next = $prev = $first = $last = -1;
-
-    if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC'
-        && empty($_REQUEST['_search']) && !$CONFIG['skip_deleted'] && !$IMAP->threading)
-      {
-      // this assumes that we are sorted by date_DESC
-      $cnt = $IMAP->messagecount();
-      $seq = $IMAP->get_id($MESSAGE->uid);
-      $MESSAGE->index = $cnt - $seq;
-
-      $prev = $IMAP->get_uid($seq + 1);
-      $first = $IMAP->get_uid($cnt);
-      $next = $IMAP->get_uid($seq - 1);
-      $last = $IMAP->get_uid(1);
-      }
-    else 
-      {
-      // Only if we use custom sorting
-      $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
-
-      $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index);
-
-      $count = count($a_msg_index);
-      $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1;
-      $first = $count > 1 ? $IMAP->get_uid($a_msg_index[0]) : -1;
-      $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1;
-      $last = $count > 1 ? $IMAP->get_uid($a_msg_index[$count-1]) : -1;
-      }
-
-    if ($prev > 0)
-      $OUTPUT->set_env('prev_uid', $prev);
-    if ($first > 0)
-      $OUTPUT->set_env('first_uid', $first);
-    if ($next > 0)
-      $OUTPUT->set_env('next_uid', $next);
-    if ($last > 0)
-      $OUTPUT->set_env('last_uid', $last);
-
-    // Don't need a real messages count value
-    $OUTPUT->set_env('messagecount', 1);
-    }
-
   if (!$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0)))
     $RCMAIL->plugins->exec_hook('message_read', array('uid' => $MESSAGE->uid,
       'mailbox' => $mbox_name, 'message' => $MESSAGE));

--
Gitblit v1.9.1