Class: BMF::Folder
- Inherits:
-
Object
- Object
- BMF::Folder
- Defined in:
- lib/bmf/lib/folder.rb
Constant Summary collapse
- VALID_FOLDERS =
%w{chans inbox sent lists}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #delete_thread(address, thread) ⇒ Object
-
#initialize(folder_name) ⇒ Folder
constructor
A new instance of Folder.
- #messages(opts = {}) ⇒ Object
- #new_messages? ⇒ Boolean
- #thread_messages(address, thread_name, opts = {}) ⇒ Object
- #threads_for_address(address, opts = {}) ⇒ Object
Constructor Details
#initialize(folder_name) ⇒ Folder
Returns a new instance of Folder.
9 10 11 12 13 |
# File 'lib/bmf/lib/folder.rb', line 9 def initialize folder_name raise "Bad folder #{folder_name}" if !VALID_FOLDERS.include?(folder_name) @name = folder_name @messages = BMF::MessageStore.instance.send(folder_name) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/bmf/lib/folder.rb', line 7 def name @name end |
Instance Method Details
#delete_thread(address, thread) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bmf/lib/folder.rb', line 58 def delete_thread address, thread msgs = (address, thread) return [] if msgs.nil? alerts = [] msgs.each do |msg| msgid = msg['msgid'] if msg['_source'] == 'sent' alerts << (BMF::XmlrpcClient.instance.trashSentMessage(msgid) + msgid) else alerts << (BMF::XmlrpcClient.instance.trashMessage(msgid) + msgid) end end alerts end |
#messages(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/bmf/lib/folder.rb', line 23 def opts={} msgs = @messages if opts[:sort] == :new msgs = msgs.sort{ |a,b| BMF::MessageStore.instance.address_last_updates[a[0]] <=> BMF::MessageStore.instance.address_last_updates[b[0]] }.reverse end msgs end |
#new_messages? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/bmf/lib/folder.rb', line 15 def @messages.each_pair do |address, threads| return true if BMF::ThreadStatus.instance.(address, threads.keys) end return false end |
#thread_messages(address, thread_name, opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bmf/lib/folder.rb', line 43 def address, thread_name, opts={} threads = threads_for_address(address) return nil if threads.nil? msgs = threads[thread_name] msgs = [] if msgs.nil? if opts[:sort] == :old msgs = msgs.sort { |a,b| BMF::Message.time(a) <=> BMF::Message.time(b) } end msgs end |
#threads_for_address(address, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/bmf/lib/folder.rb', line 33 def threads_for_address address, opts={} threads = @messages[address] if threads && opts[:sort] == :new threads = threads.sort{ |a,b| BMF::MessageStore.instance.thread_last_updates[address][a[0]] <=> BMF::MessageStore.instance.thread_last_updates[address][b[0]] }.reverse end threads end |