ContactManager
Extends:
ContactManager instance is obtained by calling the Session#getContactManager method of Session and must not be directly instantiated. Once the ContactManager instance is obtained ContactManager#init method must be called to initialize it.
Events
create
is emitted every time a new contact is added to the contact list.- Contact
contact
The contact that has just been created.
- Contact
contact-added
is emitted every time a new contact is added to the cache after have been created- Contact
contact
The contact that has just been created.
- Contact
update
is emitted when some contact is updated.- Contact
contact
The contact that has just been updated.
- Contact
delete
is emitted when some contact is deleted.- Contact
contact
The contact that has just been deleted.
- Contact
- start-synchronizing is emitted when a synchronizing process starts
- start-synchronizing-background is emitted when a synchronizing process starts in background
- start-synchronizing-avatars is emitted when a avatar synchronizing process starts
- stop-synchronizing is emitted when a synchronizing process ends
- sync-all-device-contacts is emitted when all device contacts are going to be uploaded
You can check EventEmitter2 documentation for additional information about adding and removing listeners for this events events.
Example:
contactManager.init().then(function() {
contactManager.getContacts().forEach(function(contact) {
console.log(contact.name);
});
});
To sync contacts, a new function must be called (contact Manager has to be initialized previously)
contactManager.launchSynchronize().then(function() {
contactManager.getContacts().forEach(function(contact) {
console.log(contact.name);
});
});
Member Summary
Public Members | ||
public |
Allows to change the presence of this session |
|
public get |
prototypes: Object: {"Contact": *, "GroupContact": *, "Presence": *, "OwnPresence": *} |
Method Summary
Public Methods | ||
public |
Clears all user contacts data and invalidates the cache from the persistent storage |
|
public |
createContact(displayName: String, phones: string | {name: string, address: string}[], emails: {email: string}[]): * Call stack.addContact once the manager is initialized and return a promise. |
|
public |
createGroupContact(displayName: String, participants: Object): * If the contact is successfully created the promise will be resolved, otherwise will be rejected. |
|
public |
getContactByAddress(address: String, sync: boolean): Contact Retrieves a contact given an address |
|
public |
getContactByEmail(email: String): Contact | undefined Retrieves a contact given an email |
|
public |
getContactByWacId(wacId: *): Contact Retrieves a contact given a WAC id |
|
public |
getContacts(): Array<Contact> Retrieves a list with the available contacts |
|
public |
getFakeContact(options: object, name: string, presence: Presence, avatar: string, phone: string, email: string): * Returns a new local only contact with the specified parameters |
|
public |
getPresenceByAddress(address: *): Promise<Presence> Retrieves the presence of a user given an address |
|
public |
getPresenceByWacId(wacId: *): Contact Retrieves the presence of a user given its WAC id |
|
public |
init(): Promise<ContactManager, Error> Initializes the contact manager |
|
public |
Launch the sinchronizing to check if a change has occured |
|
public |
onUpdateAvatarsContacts(avatarsContacts: Map) Internal callback for Synchronizer event. |
|
public |
onUpdateListContacts(contacts: Array) Internal callback for Synchronizer event |
|
public |
Uninitializes the contact manager |
Public Members
Public Methods
public clearContactsDataFromPersistentStorage() source
Clears all user contacts data and invalidates the cache from the persistent storage
public createContact(displayName: String, phones: string | {name: string, address: string}[], emails: {email: string}[]): * source
Call stack.addContact once the manager is initialized and return a promise.
If the contact is successfully created the promise will be resolved, otherwise will be rejected. The wac will send a qs-contact-add event to every session.
Params:
Name | Type | Attribute | Description |
displayName | String | The name of the new contact |
|
phones | string | {name: string, address: string}[] | Phone or phones of the new contact |
|
emails | {email: string}[] | Email or emails of the new contact |
Return:
* |
public createGroupContact(displayName: String, participants: Object): * source
If the contact is successfully created the promise will be resolved, otherwise will be rejected. The wac will send a qs-contact-add event to every session.
Return:
* |
public getContactByAddress(address: String, sync: boolean): Contact source
Retrieves a contact given an address
public getContactByEmail(email: String): Contact | undefined source
Retrieves a contact given an email
Params:
Name | Type | Attribute | Description |
String |
public getContactByWacId(wacId: *): Contact source
Retrieves a contact given a WAC id
Params:
Name | Type | Attribute | Description |
wacId | * |
public getFakeContact(options: object, name: string, presence: Presence, avatar: string, phone: string, email: string): * source
Returns a new local only contact with the specified parameters
Return:
* |
public getPresenceByAddress(address: *): Promise<Presence> source
Retrieves the presence of a user given an address
Params:
Name | Type | Attribute | Description |
address | * |
public getPresenceByWacId(wacId: *): Contact source
Retrieves the presence of a user given its WAC id
Params:
Name | Type | Attribute | Description |
wacId | * |
public init(): Promise<ContactManager, Error> source
Initializes the contact manager
Return:
Promise<ContactManager, Error> | A promise that returns when fulfilled the contact manager instance |
public launchSynchronize(): Promise source
Launch the sinchronizing to check if a change has occured
public onUpdateAvatarsContacts(avatarsContacts: Map) source
Internal callback for Synchronizer event. Update contacts with his avatar.
Params:
Name | Type | Attribute | Description |
avatarsContacts | Map | A map with contactDeviceId as key and avatar as value |