summaryrefslogtreecommitdiff
path: root/src/leap/mail/mail.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-06-29 11:57:20 -0400
committerKali Kaneko <kali@leap.se>2015-06-29 13:12:47 -0400
commit0dbf2be49db228e43fe4b196199f82ea281886bf (patch)
tree2bc5b874323915bad2669cdd5085954bcbc3e418 /src/leap/mail/mail.py
parentc0f3a6afa81f93f8d1b078a62e4411b2321ba9f0 (diff)
[bug] allow mailbox to be notified of collection changes
in a previous refactor, we decoupled the incoming mail service from the IMAP layer. However, this left the IMAPMailbox unable to react to changes in the underlying collection when a new message is inserted. in this commit, we add a Listener mechanism to the collection itself, so that IMAPMailbox (and any other object that uses it) can subscribe to changes on the number of messages of the collection. Resolves: #7191 Releases: 0.4.0
Diffstat (limited to 'src/leap/mail/mail.py')
-rw-r--r--src/leap/mail/mail.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index faaabf6..4a73186 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -378,6 +378,7 @@ class MessageCollection(object):
# of by doc_id. See get_message_by_content_hash
self.mbox_indexer = mbox_indexer
self.mbox_wrapper = mbox_wrapper
+ self._listeners = set([])
def is_mailbox_collection(self):
"""
@@ -639,11 +640,24 @@ class MessageCollection(object):
notify_just_mdoc=notify_just_mdoc,
pending_inserts_dict=self._pending_inserts)
d.addCallback(insert_mdoc_id, wrapper)
- d.addErrback(lambda failure: log.err(failure))
d.addCallback(self.cb_signal_unread_to_ui)
+ d.addCallback(self.notify_new_to_listeners)
+ d.addErrback(lambda failure: log.err(failure))
return d
+ # Listeners
+
+ def addListener(self, listener):
+ self._listeners.add(listener)
+
+ def removeListener(self, listener):
+ self._listeners.remove(listener)
+
+ def notify_new_to_listeners(self, *args):
+ for listener in self._listeners:
+ listener.notify_new()
+
def cb_signal_unread_to_ui(self, result):
"""
Sends an unread event to ui, passing *only* the number of unread