Mailbox client manager
- Create a singleton mailbox client manager
- This component manages a set of mailbox clients (#2229 (closed)): one client for each mailbox we know about
- The manager creates the clients when we come online and destroys them when we go offline
- The manager is responsible for assigning contacts to mailboxes for upload and/or download - so each client has a set of contacts assigned for upload and a (possibly different) set of contacts assigned for download
- These assignments can change based on pairing/unpairing a mailbox, learning which API versions our own mailbox supports, a contact being added/removed, or receiving new mailbox properties from a contact
- The assignments don't change based on connecting to a contact or disconnecting from a contact
- A contact's mailbox is "usable" if it supports an API version that we and the contact can both use, according to our hardcoded client-supported versions and the latest server-supported and client-supported versions received from the contact
- Our own mailbox is "usable" by a contact if it supports an API version that we and the contact can both use, according to our hardcoded client-supported versions, the latest server-supported versions fetched from our own mailbox, and the latest client-supported versions received from the contact
- If we have a mailbox, we always have a client for it regardless of whether our hardcoded client-supported versions are compatible with the latest server-supported versions fetched from the mailbox
- If a contact has a mailbox, we only have a client for it if it's usable
When we come online:
- For each contact:
- If the contact has a usable mailbox:
- Create a client for the contact's mailbox
- Assign the contact to the contact's mailbox for upload
- If we don't have a mailbox that's usable by the contact:
- Assign the contact to the contact's mailbox for download
- If the contact has a usable mailbox:
- If we have our own mailbox:
- Create a client for our own mailbox
- For each contact:
- If our own mailbox is usable by the contact:
- Assign the contact to our own mailbox for download
- If the contact doesn't have a usable mailbox:
- Assign the contact to our own mailbox for upload
- If our own mailbox is usable by the contact:
When we go offline:
- Destroy all clients
When we pair a mailbox:
- If we're online:
- Create a client for our own mailbox
- For each contact:
- If the contact has a usable mailbox:
- If our own mailbox is usable by the contact:
- Reassign the contact from the contact's mailbox to our own mailbox for download
- (The contact remains assigned to the contact's mailbox for upload)
- If our own mailbox is usable by the contact:
- Else, if our own mailbox is usable by the contact:
- Assign the contact to our own mailbox for upload and download
- If the contact has a usable mailbox:
When we unpair a mailbox:
- If we're online:
- For each contact:
- If the contact has a usable mailbox:
- If the contact is assigned to our own mailbox for download:
- Reassign the contact from our own mailbox to the contact's mailbox for download
- (The contact is already assigned to the contact's mailbox for upload)
- If the contact is assigned to our own mailbox for download:
- If the contact has a usable mailbox:
- Destroy the client for our own mailbox
- For each contact:
When a contact is added:
- Assumption: the contact has no mailbox properties yet, as the event informing us of the contact's first mailbox update is always delivered after the event informing us that the contact was added
- Wait until we receive the contact's first mailbox update before deciding how to assign the contact for upload and download
When a contact is removed:
- If we're online:
- If we have a client for the contact's mailbox:
- Destroy the client for the contact's mailbox
- If the contact is assigned to our own mailbox for download:
- Deassign the contact from our own mailbox for download
- If the contact is assigned to our own mailbox for upload:
- Deassign the contact from our own mailbox for upload
- If we have a client for the contact's mailbox:
When we receive a mailbox update from a contact:
- If we're online:
- If the contact didn't previously have a usable mailbox and now has one:
- Create a client for the contact's mailbox
- If we have a mailbox that's usable by the contact:
- Reassign the contact from our own mailbox to the contact's mailbox for upload
- (The contact remains assigned to our own mailbox for download)
- Else:
- Assign the contact to the contact's mailbox for upload and download
- Else if the contact previously had a usable mailbox and no longer has one:
- If we have a mailbox that's usable by the contact:
- Reassign the contact from the contact's mailbox to our own mailbox for upload
- (The contact remains assigned to our own mailbox for download)
- Destroy the client for the contact's mailbox
- If we have a mailbox that's usable by the contact:
- Else if the contact previously had a usable mailbox and now has a different mailbox that's also usable:
- Destroy the client for the contact's mailbox
- Create a new client for the contact's mailbox
- Assign the contact to the contact's mailbox for upload
- If we don't have a mailbox that's usable by the contact:
- Assign the contact to the contact's mailbox for download
- If the contact didn't previously have a usable mailbox and now has one:
Edited by akwizgran