API modified to receive events instead of relying on polling to update chats.

This commit is contained in:
Paulo Rogerio Panhoto 2018-01-02 18:04:21 -02:00
parent 017f5ddc1b
commit f871597de7

View file

@ -18,6 +18,8 @@ namespace TLSharp.Core.Network
{
//private ulong sessionId = GenerateRandomUlong();
private readonly uint UpdatesTooLongID = (uint) new TeleSharp.TL.TLUpdatesTooLong ().Constructor;
private TcpTransport _transport;
private Session _session;
@ -190,7 +192,6 @@ namespace TLSharp.Core.Network
uint code = messageReader.ReadUInt32();
messageReader.BaseStream.Position -= 4;
Console.WriteLine ("Msg code: {0:x8}", code);
switch (code)
{
case 0x73f1f8dc: // container
@ -227,14 +228,15 @@ namespace TLSharp.Core.Network
//logger.debug("MSG gzip_packed");
return HandleGzipPacked(messageId, sequence, messageReader, request);
case 0xe317af7e:
case 0xd3f45784:
case 0x2b2fbd4e:
case 0x914fbf11:
case 0x16812688:
case 0x78d4dec1:
case 0x725b04c3:
case 0x74ae4240:
case 0x11f1331c:
return HandleUpdate(code, sequence, messageReader, request);
default:
//logger.debug("unknown message: {0}", code);
Console.WriteLine ("Msg code: {0:x8}", code);
return false;
}
}
@ -245,10 +247,13 @@ namespace TLSharp.Core.Network
{
var update = ParseUpdate (code, messageReader);
if (update != null && UpdatesEvent != null)
{
UpdatesEvent (update);
}
catch
}
catch (Exception ex)
{
Console.WriteLine (ex);
}
return false;
}
@ -259,9 +264,9 @@ namespace TLSharp.Core.Network
{
case 0xe317af7e:
return DecodeUpdate<TeleSharp.TL.TLUpdatesTooLong>(messageReader);
case 0xd3f45784:
case 0x914fbf11:
return DecodeUpdate<TeleSharp.TL.TLUpdateShortMessage> (messageReader);
case 0x2b2fbd4e:
case 0x16812688:
return DecodeUpdate<TeleSharp.TL.TLUpdateShortChatMessage> (messageReader);
case 0x78d4dec1:
return DecodeUpdate<TeleSharp.TL.TLUpdateShort> (messageReader);
@ -269,15 +274,17 @@ namespace TLSharp.Core.Network
return DecodeUpdate<TeleSharp.TL.TLUpdatesCombined> (messageReader);
case 0x74ae4240:
return DecodeUpdate<TeleSharp.TL.TLUpdates> (messageReader);
case 0x11f1331c:
return DecodeUpdate<TeleSharp.TL.TLUpdateShortSentMessage> (messageReader);
default:
return null;
}
}
private TeleSharp.TL.TLAbsUpdates DecodeUpdate<T>(BinaryReader messageReader) where T: TeleSharp.TL.TLAbsUpdates, new()
private TeleSharp.TL.TLAbsUpdates DecodeUpdate<T>(BinaryReader messageReader) where T: TeleSharp.TL.TLAbsUpdates
{
var update = new T ();
update.DeserializeBody (messageReader);
var ms = messageReader.BaseStream as MemoryStream;
var update = (T) TeleSharp.TL.ObjectUtils.DeserializeObject (messageReader);
return update;
}