Walkthrough: Change the Privacy Relationship of a Contact (Lync 2010 SDK)
This topic demonstrates how to change the privacy relationship of a contact. Each contact has a privacy relationship with the client. This relationship establishes the presence information shared with the contact. By implementing this walkthrough in your client application, your users can set the privacy relationship on their contacts.
Privacy Relationship Options
The following table presents the publishable contact information types that are available to contacts assigned to the five privacy access levels.
Types/Relationships |
Friends |
Workgroup |
Colleague |
External |
Blocked |
---|---|---|---|---|---|
Phones |
Mobile, home, and any other published phone numbers |
None |
|||
Contact Information |
Display name, email address, Job Title, display photo, company, office location and work phone number. |
Display name, email address, job title, company, display photo. |
Display name, email address, company, job title, display photo. |
Display name, email address, company, job title, display photo. |
|
Voicemail |
Voicemail URL when user is enabled for Lync. |
Voicemail URL when user is enabled for Lync. |
Voicemail URL when user is enabled for Lync. |
Voicemail URL when user is enabled for Lync. |
|
Working Calendar |
The working-hour blocks as specified in the user’s calendar. |
The working-hour blocks as specified in the user’s calendar. |
The working-hour blocks as specified in the user’s calendar. |
||
Free/Busy Calendar |
The time periods when the user is free or busy according to the user’s calendar. |
The time periods when the user is free or busy according to the user’s calendar. |
The time periods when the user is free or busy according to the user’s calendar. |
||
Notes |
Presence note, OOF message from the user's Outlook account. |
Presence note, OOF message from the user's Outlook account. |
Presence note, OOF message from the user's Outlook account. |
Presence note, OOF message from the user's Outlook account. |
Changing the Privacy Relationship of a Contact
Get the LyncClient instance. Verify that the client state is signed in to the server. For information about signing in to Microsoft Lync Server 2010, see Walkthrough: Sign In to Lync (Lync 2010 SDK).
Get the Contact instance to be updated. Any valid contact, regardless of it’s source, can be updated to change the privacy relationship setting. For information about getting the contacts in a user’s contact list, see Walkthrough: Fill a Contact List (Lync 2010 SDK).
Call the Contact.BeginChangeSetting method, specifying that the privacy relationship is to be set by setting the ContactSetting.AccessLevel, and an AccessLevel enumerator representing the new privacy relationship. Catch the System.IAsyncResult returned from the call.
Call Contact.EndChangeSetting to complete the operation.
Tip
If you do not want to block execution on your UI thread while the operation runs, pass a System.AsyncCallback method into BeginChangeSetting and make the EndChangeSetting call inside of the callback.
Example
The following example accepts two string parameters representing the URI of a user and the new access level desired. The access level string is converted to an AccessLevel enumerator before an instance of Contact is obtained from ContactManager by calling into GetContactByUri.
The contact setting, ContactSetting.AccessLevel is set by calling into Contact.BeginChangeSetting and passing both an enumerator for the property to be updated and an enumerator for the new property value.
/// <summary>
/// Updates the privacy relationship of a contact specified by Uri
/// </summary>
/// <param name="ContactUri">string. Uri of contact to update.</param>
/// <param name="newAccessLevel">string. New privacy relationship.</param>
public void UpdatePrivacyRelationship(string ContactUri, string newAccessLevel)
{
AccessLevel newLevelEnumerator = AccessLevel.Default;
switch (newAccessLevel.ToUpper().Trim())
{
case "FRIENDS":
newLevelEnumerator = AccessLevel.Friends;
break;
case "WORKGROUP":
newLevelEnumerator = AccessLevel.Workgroup;
break;
case "COLLEAGUE":
newLevelEnumerator = AccessLevel.Colleague;
break;
case "EXTERNAL":
newLevelEnumerator = AccessLevel.External;
break;
case "BLOCKED":
newLevelEnumerator = AccessLevel.Blocked;
break;
}
Contact contactToUpdate = _LyncClient.ContactManager.GetContactByUri(ContactUri);
if (contactToUpdate != null)
{
contactToUpdate.BeginChangeSetting(ContactSetting.AccessLevel, newLevelEnumerator, SetPrivacyCallback, contactToUpdate);
}
}
/// <summary>
/// Handles async callback when set privacy operation completes
/// </summary>
/// <param name="ar">IAsyncResult. The state of the operation.</param>
private void SetPrivacyCallback(IAsyncResult ar)
{
if (ar.IsCompleted == true)
{
((Contact)ar.AsyncState).EndChangeSetting(ar);
Console.WriteLine("Privacy relationship updated for " + ((Contact)ar.AsyncState).GetContactInformation(ContactInformationType.DisplayName).ToString());
}
}
See Also
Concepts
Lync Model API Contacts and Groups Walkthroughs (Lync 2010 SDK)