// Add new dialog or fetch existing one. public static Dialog LoadDialog(string login) { // Fetch user data. var anotherUser = AppUser.GetInstance().Client.FetchUser(login); if (anotherUser != null) { // Construct new dialog. var dialog = new Dialog() { Partner = anotherUser }; dialog.Messages = GetDialogMessages(dialog); // Assume that if dialog exist it contains messages. if (dialog.Messages != null && dialog.Messages.Count > 0) { // Try to restore dialog key. TryToRestoreKeyFromDialog(ref dialog); return(dialog); } // Client method call. if (AppUser.GetInstance().Client.AddDialog(anotherUser)) { // Generate key. var aesKey = AesKey.GenerateKey(); dialog.LoadKey(aesKey); // Send message. SendKeyExchangeMessage(dialog); return(dialog); } } Logger.Info("Unable to load another user."); return(null); }