3 module CanAliasContacts
5 aalias = BufferManager.ask(:alias, "Alias for #{p.longname}: ", ContactManager.alias_for(p))
7 aalias = nil if aalias.empty? # allow empty aliases
9 name = BufferManager.ask(:name, "Name for #{p.longname}: ", p.name)
10 return if name.nil? || name.empty? # don't allow empty names
13 ContactManager.update_alias p, aalias
14 BufferManager.flash "Contact updated!"
18 class ContactListMode < LineCursorMode
19 LOAD_MORE_CONTACTS_NUM = 10
21 register_keymap do |k|
22 k.add :load_more, "Load #{LOAD_MORE_CONTACTS_NUM} more contacts", 'M'
23 k.add :reload, "Drop contact list and reload", 'D'
24 k.add :alias, "Edit alias/or name for contact", 'a', 'i'
25 k.add :toggle_tagged, "Tag/untag current line", 't'
26 k.add :apply_to_tagged, "Apply next command to all tagged items", '+'
27 k.add :search, "Search for messages from particular people", 'S'
30 def initialize mode=:regular
32 @tags = Tagger.new self, "contact"
38 include CanAliasContacts
40 p = @contacts[curpos] or return
45 def lines; @text.length; end
46 def [] i; @text[i]; end
49 p = @contacts[curpos] or return
50 @tags.toggle_tag_for p
51 update_text_for_line curpos
55 def multi_toggle_tagged threads
60 def apply_to_tagged; @tags.apply_to_tagged; end
62 def load_more num=LOAD_MORE_CONTACTS_NUM
66 BufferManager.flash "Added #{num.pluralize 'contact'}."
69 def multi_select people
72 mode = ComposeMode.new :to => people
73 BufferManager.spawn "new message", mode
79 p = @contacts[curpos] or return
83 def multi_search people
84 mode = PersonSearchResultsMode.new people
85 BufferManager.spawn "search for #{people.map { |p| p.name }.join(', ')}", mode
86 mode.load_threads :num => mode.buffer.content_height
90 p = @contacts[curpos] or return
100 def load_in_background
101 Redwood::reporting_thread("contact manager load in bg") do
104 BufferManager.draw_screen
109 @num ||= buffer.content_height
110 @user_contacts = ContactManager.contacts_with_aliases
111 num = [@num - @user_contacts.length, 0].max
112 BufferManager.say("Loading #{num} contacts from index...") do
113 recentc = Index.load_contacts AccountManager.user_emails, :num => num
114 @contacts = (@user_contacts + recentc).sort_by { |p| p.sort_by_me }.uniq
122 buffer.mark_dirty if buffer
125 def update_text_for_line line
126 @text[line] = text_for_contact @contacts[line]
127 buffer.mark_dirty if buffer
130 def text_for_contact p
131 aalias = ContactManager.alias_for(p) || ""
132 [[:tagged_color, @tags.tagged?(p) ? ">" : " "],
133 [:none, sprintf("%-#{@awidth}s %-#{@nwidth}s %s", aalias, p.name, p.email)]]
137 @awidth, @nwidth = 0, 0
138 @contacts.each do |p|
139 aalias = ContactManager.alias_for(p)
140 @awidth = aalias.length if aalias && aalias.length > @awidth
141 @nwidth = p.name.length if p.name && p.name.length > @nwidth
144 @text = @contacts.map { |p| text_for_contact p }