TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

gethistory return type

Open npsniloo opened this issue 8 years ago • 4 comments

hi, I am using the code below to get my messages with chat history, it sometimes doesnt return all messages and just return some of it in a messagesSlice object. I would like to know why this happens sometimes??? could you please help me???

npsniloo avatar Feb 07 '17 11:02 npsniloo

hi you can use this code for solve your probleme

TLAbsMessages tlAbsMessages = 
	await client.GetHistoryAsync(new TLInputPeerUser() { user_id = user.id }, 0, -1, 100);

var tlMessages = (TLMessages) tlAbsMessages;

for (var index = 0; index < tlMessages.messages.lists.Count; index++)
{
	var tlAbsMessage = tlMessages.messages.lists[index];
	var message = (TLMessage) tlAbsMessage;

	_resultUserMessages.Add(new UserMessage()
	{
		FromId = message.from_id,
		Message = message.message,
		CreateDateTime = message.date
	});
}

iarash84 avatar Mar 07 '17 08:03 iarash84

Hi guys. I have this problem too. :( I have used this code and it have been returned last 100 messages!! Could you please help me? (pray) And do you know how can i get specified channel message by message id?

Best Regards Thanks

mmehdidehghani avatar Mar 09 '17 09:03 mmehdidehghani

error in var tlMessages = (TLMessages) tlAbsMessages;

System.InvalidCastException: 'Can not convert an object of type' TeleSharp.TL.Messages.TLMessagesSlice 'to type' TeleSharp.TL.Messages.TLMessages

and now?

carisoftware avatar Mar 01 '18 14:03 carisoftware

I am using this code and I get last 100 messages everytime.

` //-----------------------------------------

    var hist = await client.GetHistoryAsync(target, 0, -1, 0, 100, dia.TopMessage + 1, dia.ReadInboxMaxId);

    var tlMessages = new List<string>();

    foreach (var m in (hist as TLChannelMessages).Messages)
    {
            if (m.GetType().ToString().Equals("TeleSharp.TL.TLMessage"))
            {
                    tlMessages.Add((m as TLMessage).Message.ToString();
            }
    }

//------------------------------ `

arashyazdani avatar Dec 19 '20 10:12 arashyazdani