Mailbox worker for updating our own mailbox's contact list
The mailbox client for our own mailbox (#2290 (closed)) has a worker for updating the mailbox's contact list. The worker is started when the client is created and destroyed when the client is destroyed.
The worker runs in parallel with the upload and download workers. If a task belonging to an upload or download worker tries to access the inbox or outbox of a contact that hasn't been added to the mailbox's contact list, the task will fail and retry until the mailbox's contact list is brought up to date. If a task belonging to an upload or download worker tries to access the inbox or outbox of a contact that's been removed from the mailbox's contact list, the task will fail and retry until the contact is deassigned from the client, causing the task to be cancelled.
The worker keeps a reference to its current API task, if any, so the task can be cancelled when the worker is destroyed.
The worker's lifecycle is:
- Check connectivity
- Fetch and store the mailbox's supported API versions (#2299 (closed), #2302 (closed))
- Reconcile the mailbox's contact list with the local contact list (#2182 (closed), #2183 (closed), #2187 (closed))
- Wait for the local contact list to change
The worker can be in the following states:
- Waiting for connectivity check
- Fetching API versions
- Updating contact list
- Waiting for changes
When the worker is created:
- Set the current state to "waiting for connectivity check"
- Call the client's connectivity check method
When the worker is destroyed:
- Set the current state to "destroyed"
- Cancel the current API task, if any
When a connectivity check succeeds:
- If the current state is "waiting for connectivity check":
- Set the current state to "updating contact list"
- Start a fetch-api-versions task
When a fetch-api-versions task succeeds:
- If the current state is "fetching API versions":
- Store the mailbox's supported API versions
- Start a get-contact-list task
When a get-contact-list task succeeds:
- If the current state is "updating contact list":
- Load the local contact list
- Compare the remote contact list to the local contact list
- Load the mailbox properties for any contacts that are in the local list but not the remote list
- If any contacts need to be added or deleted:
- Start an add-contact or delete-contact task
- Else:
- Set the current state to "waiting for changes"
When an add-contact or delete-contact task succeeds:
- If the current state is "updating contact list":
- If any more contacts need to be added or deleted:
- Start an add-contact or delete-contact task
- Else:
- Start a get-contact-list task
- If any more contacts need to be added or deleted:
When an event indicates that a contact has been added or removed:
- If the current state is "waiting for changes":
- Set the current state to "updating contact list"
- Start a get-contact-list task