Export (0) Print
Expand All

Managing Contacts

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In Office Communicator Automation API, a contact is represented by an object implementing the IMessengerContact interface and a contact list is represented by an object implementing the IMessengerContacts interface. Managing a contact means finding a contact (see Building a Custom Contact List), adding a user to or removing a user from the contact list (see below), and maintaining contacts in groups.

There are two ways to add a user to the caller's contact list in a Communicator application. The first one uses the IMessenger::AddContact method. This method starts Add a Contact Wizard for adding a user to the contact list. It is equivalent to clicking Add a Contact on the Contacts menu in the Communicator window. The second one uses the IMessengerPrivate::AddContact method.

This method bypasses the wizard and adds the contact without any user intervention.

The following C# code snippet illustrates how to add a user to the contact list of the caller.

CommunicatorAPI.Messenger communicator = null;
CommunicatorPrivate.MessengerPrivClass communicatorPrivate = null


void AddContact(string userId, bool useWizard)
{
   if (useWizard)
      communicator.AddContact(0, userId);
   else
      communicatorPrivate.AddContact(userId, communicator.MyServiceId);
}

Finding a user involves calling the IMessenger::GetContact method and specifying the user ID as an input parameter. If the user is in the contact list of the caller, the application can get the user object off the connected Communicator instance. If the user is not in the caller's contact list, the application must retrieve the user from the Session Initiation Protocol (SIP) provider of Communicator that is the Communications Server. These are illustrated in the following C# code snippet.

private IMessengerContact FindContact(string userID)
{
    IMessengerContact contact = null;
    // Try the local contact list first
    try
    {
        contact = (IMessengerContact)communicator.GetContact(userID, "");
    }
    catch
    {
        contact = null;
    }

    // For a nonlocal contact, try the SIP Provider of Communicator
    if (contact == null || contact.Status == MISTATUS.MISTATUS_UNKNOWN)
    {
        try
        {
            contact =
                (IMessengerContact)communicator.GetContact(userID,
                communicator.MyServiceId);
            return contact;
        }
        catch
        {
            contact = null;
            return contact;
        }
    }
    else
    {
        return contact;
    }
}

To remove a contact from the caller's contact list, an application can call the IMessengerContacts::Remove method. The following C# code snippet illustrates how to remove a contact from the contact list of the caller.

void RemoveContact(string signinName)
{
    IMessengerContact contact = communicator.GetContact(signinName, "") as IMessengerContact;
    IMessengerContacts contacts = communicator.MyContacts as IMessengerContacts;
    contacts.Remove(contact);
}

Community Additions

ADD
Show:
© 2014 Microsoft