X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fmodes%2Finbox-mode.rb;h=ba095dab7c09696f60efb7e68c993d614da9e7b8;hb=b8dd68f59f6b9930e3cc1d30aed8ae4059874821;hp=559892d5655f07b80a1186e114950156220a13c5;hpb=1a84450dc26aab7b0a2a84876509d860b942149e;p=sup diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb index 559892d..ba095da 100644 --- a/lib/sup/modes/inbox-mode.rb +++ b/lib/sup/modes/inbox-mode.rb @@ -1,4 +1,4 @@ -require 'thread' +require 'sup' module Redwood @@ -15,9 +15,7 @@ class InboxMode < ThreadIndexMode @@instance = self end - def is_relevant? m - m.has_label?(:inbox) && ([:spam, :deleted, :killed] & m.labels).empty? - end + def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([:inbox]) end ## label-list-mode wants to be able to raise us if the user selects ## the "inbox" label, so we need to keep our singletonness around @@ -26,12 +24,27 @@ class InboxMode < ThreadIndexMode def archive return unless cursor_thread + thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread + + UndoManager.register "archiving thread" do + thread.apply_label :inbox + add_or_unhide thread.first + end + cursor_thread.remove_label :inbox hide_thread cursor_thread regen_text end def multi_archive threads + UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do + threads.map do |t| + t.apply_label :inbox + add_or_unhide t.first + end + regen_text + end + threads.each do |t| t.remove_label :inbox hide_thread t @@ -41,6 +54,14 @@ class InboxMode < ThreadIndexMode def read_and_archive return unless cursor_thread + thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread + + UndoManager.register "reading and archiving thread" do + thread.apply_label :inbox + thread.apply_label :unread + add_or_unhide thread.first + end + cursor_thread.remove_label :unread cursor_thread.remove_label :inbox hide_thread cursor_thread @@ -48,12 +69,23 @@ class InboxMode < ThreadIndexMode end def multi_read_and_archive threads + old_labels = threads.map { |t| t.labels.dup } + threads.each do |t| t.remove_label :unread t.remove_label :inbox hide_thread t end regen_text + + UndoManager.register "reading and archiving #{threads.size.pluralize 'thread'}" do + threads.zip(old_labels).each do |t, l| + t.labels = l + add_or_unhide t.first + end + regen_text + end + end def handle_unarchived_update sender, m