]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/contact-list-mode.rb
Merge branch 'preemptive-loading' into next
[sup] / lib / sup / modes / contact-list-mode.rb
index 37ecc28aff9921203baad761800424977d80092b..edbef5e3a27f3f9cba65c8cf1cfaecec05021e3e 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 :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()
@@ -59,7 +63,7 @@ class ContactListMode < LineCursorMode
     @num += num
     load
     update
-    BufferManager.flash "Added #{num} contacts."
+    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,7 +98,7 @@ class ContactListMode < LineCursorMode
   end
 
   def load_in_background
-    Redwood::reporting_thread do
+    Redwood::reporting_thread("contact manager load in bg") do
       load
       update
       BufferManager.draw_screen
@@ -103,7 +107,7 @@ class ContactListMode < LineCursorMode
 
   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