Subject: [sup-talk] [PATCH] Show unread message count in thread index

From: [email-masked] (Colin Bell)
Date: Mon, 05 Nov 2007 21:01:31 +1100

Hi,

This patch shows the unread message count in the thread index as well
as the total number of messages in the thread.

E.G:

2:17pm Marcus,Grant,William (1/ 3)  [sup-talk] [PATCH] Check IMAP
2:15pm Marcus,William       (0/ 2)  [sup-talk] [PATCH] More IMAP/

--
Col

-------------- next part --------------
A non-text attachment was scrubbed...
Name: unread.diff
Type: application/octet-stream
Size: 1745 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071105/167121b3/attachment.obj

---

From: [email-masked] (William Morgan)
Date: Tue, 06 Nov 2007 18:09:46 -0800

Hi Colin,

> as the total number of messages in the thread.

I personally don't like this, because I feel like it clutters up
index-mode. But I'd like people to be able to do this sort of thing.

How about an "index-mode-widget" hook instead, that lets you replace the
"(###)" with any string you want, based on the thread? (And if the
return value is nil, use the current thread.size string.)

You'll have to scan over them twice to get the sizing right, but it
shouldn't be too bad of a patch...

-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Colin Bell)
Date: Wed, 07 Nov 2007 14:55:17 +1100

> return value is nil, use the current thread.size string.)

Good idea. I'll try to take a look at it tonight.

---

From: [email-masked] (Colin Bell)
Date: Wed, 07 Nov 2007 21:29:03 +1100

> shouldn't be too bad of a patch...

Attempt 2 :-)

I've attached an example hook as well as the diff. If you accept the
patch something like the example should go up on the wiki.

Please take a careful look at this patch as I am just learning Ruby so
I've probably done a few silly things.

index-mode-widget
-----------------
File: ~/.sup/hooks/index-mode-widget.rb
Executes when formatting the output of the number of messages for each thread in the thread index.
Variables:
      thread: The message thread to be formatted.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: widget.diff
Type: application/octet-stream
Size: 2708 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071107/dd62a04e/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: index-mode-widget.rb
Type: application/octet-stream
Size: 203 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071107/dd62a04e/attachment-0001.obj

---

From: [email-masked] (William Morgan)
Date: Wed, 07 Nov 2007 12:08:50 -0800

> I've probably done a few silly things.

I've applied this patch in modified form. There was a little work to be
done when the size of the widget changes (namely, if a widget suddenly
exceeds the previous size due to a change, the whole screen has to be
redrawn).

I've also renamed the hook "index-mode-size-widget", in case there are
other widgets you'll want to tweak later. :)

I've been trying it and I actually quite like this slight modification
of your hook code, which only displays the unread/total breakdown in the
case where some, but not all, messages in a thread are unread:

  unread_size = thread.map { |m, *o| m && m.has_label?(:unread) ? 1 : 0 }.sum
  size = thread.size
  
  case
    when size == 1 : ""
    when (unread_size == 0) || (unread_size == size) : "(#{size})"
    else "(#{unread_size}/#{size})"
  end

---

From: [email-masked] (Marcus Williams)
Date: Wed, 07 Nov 2007 21:09:10 +0000

> other widgets you'll want to tweak later. :)

... status bar for instance :) I'm in the middle of doing one for this
but its causing me bother! Is there any way to get the new message
count without search for unread labels? How fast is that in ferret?
What happens if your result set has 60k messages in it, does it chew
memory? I cant imagine having 60k new messages, but on initial
sup-sync you might on a big mailbox.

Marcus

---

From: [email-masked] (William Morgan)
Date: Wed, 07 Nov 2007 15:12:03 -0800

Excerpts from Marcus Williams's message of Wed Nov 07 13:09:10 -0800 2007:
> Is there any way to get the new message count without search for
> unread labels?

Nope. Unread is just another label, so you've got to do the search.

> How fast is that in ferret?

Pretty fast!

  $ sh devel/console.sh
  [Wed Nov 07 15:03:42 -0800 2007] loading index...
  [Wed Nov 07 15:03:42 -0800 2007] loaded index of 65765 messages
  >> require 'benchmark'
  >> all = "+label:unread -label:deleted -label:killed -label:spam"
  >> inbox = all + " +label:inbox"
  >> puts Benchmark.measure { Index.ferret.search(all).total_hits }
    0.020000   0.000000   0.020000 (  0.015534)
  >> Index.ferret.search(all).total_hits
  => 57551
  >> puts Benchmark.measure { Index.ferret.search(inbox).total_hits }
  => nil
  >> Index.ferret.search(inbox).total_hits
  => 13

The number in parentheses is elapsed real time. Probably fast enough to
call on every keypress, but feel free to cache it if you like.

> memory?

Nope. Play around with the methods above. Ferret is pretty good about
this.

> I cant imagine having 60k new messages, but on initial sup-sync you
> might on a big mailbox.

As you can see above, 57k of the 66k messages in my index are new.
(It's the last few years of ruby-talk.) Have I blown your mind? :)

---

From: [email-masked] (Marcus Williams)
Date: Thu, 08 Nov 2007 08:31:35 +0000

> (It's the last few years of ruby-talk.) Have I blown your mind? :)

ruby seems to do this regularly (at the moment daily!) :)