diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-06-09 18:22:49 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-06-09 18:22:49 -0300 |
commit | 4bb8e1becefe5a07ee5ec6fbabb44959d85e3a62 (patch) | |
tree | 221d4e0e9049117aa3cfc13c35c1eef947a5c8a9 /service/pixelated/config | |
parent | 786c26b37a89b6f7afc5524dafd35242688dc13b (diff) |
Broke initialization of services down by parts
Diffstat (limited to 'service/pixelated/config')
-rw-r--r-- | service/pixelated/config/services.py | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py index 80932a94..bcfefb88 100644 --- a/service/pixelated/config/services.py +++ b/service/pixelated/config/services.py @@ -12,27 +12,54 @@ from pixelated.adapter.listeners.mailbox_indexer_listener import MailboxIndexerL class Services(object): def __init__(self, leap_home, leap_session): - keymanager = leap_session.nicknym.keymanager soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) - search_engine = SearchEngine(soledad_querier, agent_home=leap_home) - pixelated_mail_sender = MailSender(leap_session.account_email(), leap_session.smtp) + self.search_engine = self.setup_search_engine( + leap_home, + soledad_querier) - pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier, search_engine) + pixelated_mailboxes = Mailboxes( + leap_session.account, + soledad_querier, + self.search_engine) - pixelated_mailboxes.add_welcome_mail_for_fresh_user() + self.mail_service = self.setup_mail_service( + leap_session, + soledad_querier, + self.search_engine, + pixelated_mailboxes) + + self.keymanager = self.setup_keymanager(leap_session) + self.draft_service = self.setup_draft_service(pixelated_mailboxes) - draft_service = DraftService(pixelated_mailboxes) - mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, soledad_querier, search_engine) + self.post_setup(soledad_querier, leap_session) + + def post_setup(self, soledad_querier, leap_session): + self.search_engine.index_mails( + mails=self.mail_service.all_mails(), + callback=soledad_querier.mark_all_as_not_recent) soledad_querier.remove_duplicates() - search_engine.index_mails(mails=mail_service.all_mails(), - callback=soledad_querier.mark_all_as_not_recent) + InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() + def setup_keymanager(self, leap_session): + return leap_session.nicknym.keymanager + + def setup_search_engine(self, leap_home, soledad_querier): + search_engine = SearchEngine(soledad_querier, agent_home=leap_home) MailboxIndexerListener.SEARCH_ENGINE = search_engine - InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() + return search_engine + + def setup_mail_service(self, leap_session, soledad_querier, search_engine, pixelated_mailboxes): + pixelated_mailboxes.add_welcome_mail_for_fresh_user() + pixelated_mail_sender = MailSender( + leap_session.account_email(), + leap_session.smtp) + return MailService( + pixelated_mailboxes, + pixelated_mail_sender, + soledad_querier, + search_engine) - self.keymanager = keymanager - self.search_engine = search_engine - self.mail_service = mail_service - self.draft_service = draft_service + def setup_draft_service(self, pixelated_mailboxes): + return DraftService(pixelated_mailboxes) |