private void LoadMessage(Dictionary<string, IConversation> conversationHashTable, TextMessage message, ILoadingProgressCallback progressCallback)
        {
            CheckForCancel(progressCallback);

            string conversationKey;
            PhoneNumber messagePhoneNumber = new PhoneNumber(message.Address, message.Country);
            string phoneNumberStripped = PhoneNumber.Strip(messagePhoneNumber);

            if (message.ChatId != null)
            {
                conversationKey = message.ChatId;
            }
            else
            {
                conversationKey = phoneNumberStripped;
            }

            if (string.IsNullOrEmpty(conversationKey))
            {
                return;
            }

            Contact unknownContact = new Contact(Contact.UnknownContactId, null, null, null, messagePhoneNumber);
            message.Contact = GetContactByPhoneNumber(messagePhoneNumber);
            if (message.Contact == null)
            {
                message.Contact = unknownContact;
            }
            else
            {
                //
                // Update the contact's phone number to include country information.
                //

                foreach (PhoneNumber contactPhoneNumber in message.Contact.PhoneNumbers)
                {
                    if (PhoneNumber.NumbersAreEquivalent(contactPhoneNumber, messagePhoneNumber))
                    {
                        contactPhoneNumber.Country = message.Country;
                        break;
                    }
                }
            }

            IConversation conversation;
            if (conversationHashTable.ContainsKey(conversationKey))
            {
                conversation = conversationHashTable[conversationKey];

                // If The contact is not part of the conversation, add them here. This can happen with "orphaned" chat
                // messages.
                if (!message.Contact.Equals(unknownContact) && !conversation.AssociatedContacts.Contains(message.Contact))
                {
                    conversation.AssociatedContacts.Add(message.Contact);
                }
            }
            else if (message.ChatId != null)
            {
                // It's possible to have "orphaned" chat messages, where they appear in the message database with a chat ID
                // but the chat ID was not in the chat room database. Handle those here.
                List<IContact> chatContacts = new List<IContact>();
                if (!message.Contact.Equals(unknownContact))
                {
                    chatContacts.Add(message.Contact);
                }
                conversation = new ChatConversation(chatContacts);
                conversationHashTable.Add(message.ChatId, conversation);
            }
            else
            {
                conversation = new SingleNumberConversation(unknownContact);
                conversationHashTable.Add(conversationKey, conversation);
            }

            _messageLookupTable.Add(message.MessageId, message);

            conversation.AddMessage(message);

            IncrementWorkProgress(progressCallback);
        }
        private void LoadMessage(Dictionary <string, IConversation> conversationHashTable, TextMessage message, ILoadingProgressCallback progressCallback)
        {
            CheckForCancel(progressCallback);

            string      conversationKey;
            PhoneNumber messagePhoneNumber  = new PhoneNumber(message.Address, message.Country);
            string      phoneNumberStripped = PhoneNumber.Strip(messagePhoneNumber);

            if (message.ChatId != null)
            {
                conversationKey = message.ChatId;
            }
            else
            {
                conversationKey = phoneNumberStripped;
            }

            if (string.IsNullOrEmpty(conversationKey))
            {
                return;
            }

            Contact unknownContact = new Contact(Contact.UnknownContactId, null, null, null, messagePhoneNumber);

            message.Contact = GetContactByPhoneNumber(messagePhoneNumber);
            if (message.Contact == null)
            {
                message.Contact = unknownContact;
            }
            else
            {
                //
                // Update the contact's phone number to include country information.
                //

                foreach (PhoneNumber contactPhoneNumber in message.Contact.PhoneNumbers)
                {
                    if (PhoneNumber.NumbersAreEquivalent(contactPhoneNumber, messagePhoneNumber))
                    {
                        contactPhoneNumber.Country = message.Country;
                        break;
                    }
                }
            }

            IConversation conversation;

            if (conversationHashTable.ContainsKey(conversationKey))
            {
                conversation = conversationHashTable[conversationKey];

                // If The contact is not part of the conversation, add them here. This can happen with "orphaned" chat
                // messages.
                if (!message.Contact.Equals(unknownContact) && !conversation.AssociatedContacts.Contains(message.Contact))
                {
                    conversation.AssociatedContacts.Add(message.Contact);
                }
            }
            else if (message.ChatId != null)
            {
                // It's possible to have "orphaned" chat messages, where they appear in the message database with a chat ID
                // but the chat ID was not in the chat room database. Handle those here.
                List <IContact> chatContacts = new List <IContact>();
                if (!message.Contact.Equals(unknownContact))
                {
                    chatContacts.Add(message.Contact);
                }
                conversation = new ChatConversation(chatContacts);
                conversationHashTable.Add(message.ChatId, conversation);
            }
            else
            {
                conversation = new SingleNumberConversation(unknownContact);
                conversationHashTable.Add(conversationKey, conversation);
            }

            _messageLookupTable.Add(message.MessageId, message);

            conversation.AddMessage(message);

            IncrementWorkProgress(progressCallback);
        }