コード例 #1
0
            public static List <Message> GetMessagesList(MessagesMessages messages)
            {
                if (messages.As <MessagesMessagesConstructor>() != null)
                {
                    return(messages.Cast <MessagesMessagesConstructor>().messages);
                }
                else if (messages.As <MessagesMessagesSliceConstructor>() != null)
                {
                    return(messages.Cast <MessagesMessagesSliceConstructor>().messages);
                }

                return(null);
            }
コード例 #2
0
ファイル: Client.cs プロジェクト: tshemake/Telegram.Library
        /// <summary>
        /// Gets message history for a chat.
        /// </summary>
        /// <param name="contact">User</param>
        /// <param name="offset">Number of list elements to be skipped. As of Layer 15 this value is added to the one that was calculated from max_id. Negative values are also accepted.</param>
        /// <param name="maxId">If a positive value was transferred, the method will return only messages with IDs less than max_id</param>
        /// <returns>Returns message history for a chat..</returns>
        public async Task <Models.History> GetHistoryAsync(Models.Contact contact)
        {
            await ConnectAsync();

            int limit = 30;

            Models.History history = new Models.History
            {
                Messages = new List <Models.Message>(),
            };
            InputPeer peer = null;

            if (contact.IsForeign)
            {
                peer = new InputPeerForeignConstructor(contact.Id, contact.AccessHash);
            }
            else
            {
                peer = new InputPeerContactConstructor(contact.Id);
            }

            MessagesMessages result = await _client.GetHistory(peer, 0, limit);

            if (result is MessagesMessagesConstructor messagesMessagesConstructor)
            {
                history.Messages.AddRange(messagesMessagesConstructor.messages.Select(m => (Models.Message)m).Where(m => m != null));
                history.AddChats(messagesMessagesConstructor.chats.Select(c => (Models.Chat)c).Where(c => c != null));
                history.AddContacts(messagesMessagesConstructor.users.Select(u => (Models.Contact)u).Where(u => u != null));
            }
            else if (result is MessagesMessagesSliceConstructor messagesMessagesSliceConstructor)
            {
                int count = messagesMessagesSliceConstructor.count;
                int total = 0;
                do
                {
                    total += limit;
                    history.Messages.AddRange(messagesMessagesSliceConstructor.messages.Select(m => (Models.Message)m).Where(m => m != null));
                    history.AddChats(messagesMessagesSliceConstructor.chats.Select(c => (Models.Chat)c).Where(c => c != null));
                    history.AddContacts(messagesMessagesSliceConstructor.users.Select(u => (Models.Contact)u).Where(u => u != null));
                    if (total > count)
                    {
                        break;
                    }
                    result = await _client.GetHistory(peer, total, limit);

                    messagesMessagesSliceConstructor = (MessagesMessagesSliceConstructor)result;
                } while (true);
            }

            return(history);
        }
コード例 #3
0
 public override void OnResponse(BinaryReader reader)
 {
     messages = TLObject.Read <MessagesMessages>(reader);
 }