Exemple #1
0
        /// <summary>
        /// Returns the current user dialog list.
        /// </summary>
        /// <returns>Returns the current user dialog list.</returns>
        public async Task <Models.MessagesDialog> GetDialogsAsync()
        {
            await ConnectAsync();

            int limit = 30;

            Models.MessagesDialog messagesDialog = new Models.MessagesDialog
            {
                Dialogs  = new List <Models.Dialog>(),
                Messages = new List <Models.Message>()
            };
            MessagesDialogs result = await _client.GetDialogs(0, limit);

            if (result is MessagesDialogsConstructor messagesDialogsConstructor)
            {
                messagesDialog.Dialogs.AddRange(messagesDialogsConstructor.dialogs.Select(d => (Models.Dialog)d).Where(d => d != null));
                messagesDialog.Messages.AddRange(messagesDialogsConstructor.messages.Select(m => (Models.Message)m).Where(m => m != null));
                messagesDialog.AddChats(messagesDialogsConstructor.chats.Select(c => (Models.Chat)c).Where(c => c != null));
                messagesDialog.AddContacts(messagesDialogsConstructor.users.Select(u => (Models.Contact)u).Where(u => u != null));
            }
            else if (result is MessagesDialogsSliceConstructor messagesDialogsSliceConstructor)
            {
                int count = messagesDialogsSliceConstructor.count;
                int total = 0;
                do
                {
                    total += limit;
                    messagesDialog.Dialogs.AddRange(messagesDialogsSliceConstructor.dialogs.Select(d => (Models.Dialog)d).Where(d => d != null));
                    messagesDialog.Messages.AddRange(messagesDialogsSliceConstructor.messages.Select(m => (Models.Message)m).Where(m => m != null));
                    messagesDialog.AddChats(messagesDialogsSliceConstructor.chats.Select(c => (Models.Chat)c).Where(c => c != null));
                    messagesDialog.AddContacts(messagesDialogsSliceConstructor.users.Select(u => (Models.Contact)u).Where(u => u != null));
                    if (total > count)
                    {
                        break;
                    }
                    result = await _client.GetDialogs(total, limit);

                    messagesDialogsSliceConstructor = (MessagesDialogsSliceConstructor)result;
                } while (true);
            }

            return(messagesDialog);
        }