diff options
author | Kali Kaneko <kali@leap.se> | 2015-02-24 23:05:48 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-02-24 23:05:48 -0400 |
commit | 3570f697335814a768f35bb984498f31d9de7ace (patch) | |
tree | c0f8d50426ab5324433cf67ca1167a4331e34d8c /src | |
parent | 9a52e73518c0918ff8bb372127e9c6aab02b496d (diff) |
move notifications cb to mail module
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/mail/imap/mailbox.py | 27 | ||||
-rw-r--r-- | src/leap/mail/mail.py | 24 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index c29d572..3769a3e 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -30,8 +30,6 @@ from twisted.python import log from twisted.mail import imap4 from zope.interface import implements -from leap.common import events as leap_events -from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL from leap.common.check import leap_assert from leap.mail.constants import INBOX_NAME, MessageFlags from leap.mail.imap.messages import IMAPMessage @@ -340,7 +338,7 @@ class IMAPMailbox(object): d = self._get_notify_count() d.addCallback(cbNotifyNew) - d.addCallback(self.cb_signal_unread_to_ui) + d.addCallback(self.collection.cb_signal_unread_to_ui) def _get_notify_count(self): """ @@ -512,8 +510,6 @@ class IMAPMailbox(object): d = self._get_messages_range(messages_asked) d.addCallback(get_imap_messages_for_range) - # TODO -- call signal_to_ui - # d.addCallback(self.cb_signal_unread_to_ui) return d def _get_messages_range(self, messages_asked): @@ -659,25 +655,6 @@ class IMAPMailbox(object): for msgid in seq_messg) return result - def cb_signal_unread_to_ui(self, result): - """ - Sends unread event to ui. - Used as a callback in several commands. - - :param result: ignored - """ - d = defer.maybeDeferred(self.getUnseenCount) - d.addCallback(self.__cb_signal_unread_to_ui) - return result - - def __cb_signal_unread_to_ui(self, unseen): - """ - Send the unread signal to UI. - :param unseen: number of unseen messages. - :type unseen: int - """ - leap_events.signal(IMAP_UNREAD_MAIL, str(unseen)) - def store(self, messages_asked, flags, mode, uid): """ Sets the flags of one or more messages. @@ -722,7 +699,7 @@ class IMAPMailbox(object): mode, uid, d) if PROFILE_CMD: do_profile_cmd(d, "STORE") - d.addCallback(self.cb_signal_unread_to_ui) + d.addCallback(self.collection.cb_signal_unread_to_ui) d.addErrback(lambda f: log.msg(f.getTraceback())) return d diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py index 9a32483..3127ef5 100644 --- a/src/leap/mail/mail.py +++ b/src/leap/mail/mail.py @@ -27,6 +27,8 @@ from email.utils import formatdate from twisted.internet import defer from leap.common.check import leap_assert_type +from leap.common import events as leap_events +from leap.common.events.events_pb2 import IMAP_UNREAD_MAIL from leap.common.mail import get_email_charset from leap.mail.adaptors.soledad import SoledadMailAdaptor @@ -606,8 +608,30 @@ class MessageCollection(object): d = self.add_msg(message, flags=flags, date=date, notify_just_mdoc=True) d.addErrback(lambda f: logger.warning(f.getTraceback())) + d.addCallback(self.cb_signal_unread_to_ui) return d + def cb_signal_unread_to_ui(self, result): + """ + Sends unread event to ui. + Used as a callback in several commands. + + :param result: ignored + """ + if self.mbox_name.lower() == "inbox": + d = defer.maybeDeferred(self.count_unseen) + d.addCallback(self.__cb_signal_unread_to_ui) + return result + + def __cb_signal_unread_to_ui(self, unseen): + """ + Send the unread signal to UI. + :param unseen: number of unseen messages. + :type unseen: int + """ + # TODO change name of the signal, non-imap now. + leap_events.signal(IMAP_UNREAD_MAIL, str(unseen)) + def copy_msg(self, msg, new_mbox_uuid): """ Copy the message to another collection. (it only makes sense for |