]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/thread-index-mode.rb
Merge branch 'draft-colors' into next
[sup] / lib / sup / modes / thread-index-mode.rb
index c8096a753f7ee95fc770e6233b0c5b13a88badc4..7a0b8150c455cc4df19cdb581e3ae9144cacd1e0 100644 (file)
@@ -113,19 +113,32 @@ EOS
     threads.each { |t| select t }
   end
 
-  ## this is called by thread-view-modes when the user wants to view
-  ## the next thread without going to index-mode. we update the cursor
-  ## as a convenience.
+  ## these two methods are called by thread-view-modes when the user
+  ## wants to view the previous/next thread without going back to
+  ## index-mode. we update the cursor as a convenience.
   def launch_next_thread_after thread, &b
+    launch_another_thread thread, 1, &b
+  end
+
+  def launch_prev_thread_before thread, &b
+    launch_another_thread thread, -1, &b
+  end
+
+  def launch_another_thread thread, direction, &b
     l = @lines[thread] or return
+    target_l = l + direction
     t = @mutex.synchronize do
-      if l < @threads.length - 1
-        set_cursor_pos l + 1 # move out of mutex?
-        @threads[l + 1]
+      if target_l >= 0 && target_l < @threads.length
+        @threads[target_l]
       end
-    end or return
+    end
 
-    select t, b
+    if t # there's a next thread
+      set_cursor_pos target_l # move out of mutex?
+      select t, b
+    elsif b # no next thread. call the block anyways
+      b.call
+    end
   end
   
   def handle_single_message_labeled_update sender, m
@@ -172,10 +185,16 @@ EOS
   end
 
   def handle_deleted_update sender, m
-    @ts_mutex.synchronize do
-      return unless @ts.contains? m
-      @ts.remove_thread_containing_id m.id
-    end
+    t = @ts_mutex.synchronize { @ts.thread_for m }
+    return unless t
+    hide_thread t
+    update
+  end
+
+  def handle_spammed_update sender, m
+    t = @ts_mutex.synchronize { @ts.thread_for m }
+    return unless t
+    hide_thread t
     update
   end