]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/contact-list-mode.rb
Allow to hit 'y' to send a draft in thread-view-mode
[sup] / lib / sup / modes / contact-list-mode.rb
index 989396b89def22a957ba6548378cc3d58473c498..7c16babd61aacf220998bfb93aca300c0629d112 100644 (file)
@@ -2,12 +2,16 @@ module Redwood
 
 module CanAliasContacts
   def alias_contact p
-    a = BufferManager.ask(:alias, "Nickname for #{p.longname}: ", ContactManager.alias_for(p)) or return
-    if a.empty?
-      ContactManager.drop_contact p
-    else
-      ContactManager.set_contact p, a
-    end
+    aalias = BufferManager.ask(:alias, "Alias for #{p.longname}: ", ContactManager.alias_for(p))
+    return if aalias.nil?
+    aalias = nil if aalias.empty? # allow empty aliases
+
+    name = BufferManager.ask(:name, "Name for #{p.longname}: ", p.name)
+    return if name.nil? || name.empty? # don't allow empty names
+    p.name = name
+
+    ContactManager.update_alias p, aalias
+    BufferManager.flash "Contact updated!"
   end
 end
 
@@ -17,15 +21,15 @@ class ContactListMode < LineCursorMode
   register_keymap do |k|
     k.add :load_more, "Load #{LOAD_MORE_CONTACTS_NUM} more contacts", 'M'
     k.add :reload, "Drop contact list and reload", 'D'
-    k.add :alias, "Edit nickname/alias for contact", 'a'
+    k.add :alias, "Edit alias/or name for contact", 'a', 'i'
     k.add :toggle_tagged, "Tag/untag current line", 't'
     k.add :apply_to_tagged, "Apply next command to all tagged items", ';'
     k.add :search, "Search for messages from particular people", 'S'
   end
 
-  def initialize mode = :regular
+  def initialize mode=:regular
     @mode = mode
-    @tags = Tagger.new self
+    @tags = Tagger.new self, "contact"
     @num = nil
     @text = []
     super()
@@ -35,7 +39,7 @@ class ContactListMode < LineCursorMode
   def alias
     p = @contacts[curpos] or return
     alias_contact p
-    regen_text
+    update
   end
 
   def lines; @text.length; end
@@ -50,7 +54,7 @@ class ContactListMode < LineCursorMode
 
   def multi_toggle_tagged threads
     @tags.drop_all_tags
-    regen_text
+    update
   end
 
   def apply_to_tagged; @tags.apply_to_tagged; end
@@ -58,8 +62,8 @@ class ContactListMode < LineCursorMode
   def load_more num=LOAD_MORE_CONTACTS_NUM
     @num += num
     load
-    regen_text
-    BufferManager.flash "Added #{num} contacts."
+    update
+    BufferManager.flash "Added #{num.pluralize 'contact'}."
   end
 
   def multi_select people
@@ -67,7 +71,7 @@ class ContactListMode < LineCursorMode
     when :regular
       mode = ComposeMode.new :to => people
       BufferManager.spawn "new message", mode
-      mode.edit
+      mode.edit_message
     end
   end
 
@@ -94,16 +98,16 @@ class ContactListMode < LineCursorMode
   end
 
   def load_in_background
-    Redwood::reporting_thread do
+    Redwood::reporting_thread("contact manager load in bg") do
       load
-      regen_text
+      update
       BufferManager.draw_screen
     end
   end
 
   def load
     @num ||= buffer.content_height
-    @user_contacts = ContactManager.contacts
+    @user_contacts = ContactManager.contacts_with_aliases
     num = [@num - @user_contacts.length, 0].max
     BufferManager.say("Loading #{num} contacts from index...") do
       recentc = Index.load_contacts AccountManager.user_emails, :num => num
@@ -113,9 +117,14 @@ class ContactListMode < LineCursorMode
   
 protected
 
+  def update
+    regen_text
+    buffer.mark_dirty if buffer
+  end
+
   def update_text_for_line line
     @text[line] = text_for_contact @contacts[line]
-    buffer.mark_dirty
+    buffer.mark_dirty if buffer
   end
 
   def text_for_contact p
@@ -133,7 +142,6 @@ protected
     end
 
     @text = @contacts.map { |p| text_for_contact p }
-    buffer.mark_dirty
   end
 end