mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Added GetUpdatesDifference and GetUpdatesState functions implementations.
This commit is contained in:
parent
d6331c2352
commit
1c31794751
43
TLSharp.Core/Requests/GetUpdatesDifferenceRequest.cs
Normal file
43
TLSharp.Core/Requests/GetUpdatesDifferenceRequest.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using TLSharp.Core.MTProto;
|
||||||
|
|
||||||
|
namespace TLSharp.Core.Requests
|
||||||
|
{
|
||||||
|
public class GetUpdatesDifferenceRequest : MTProtoRequest
|
||||||
|
{
|
||||||
|
public readonly int pts;
|
||||||
|
public readonly int date;
|
||||||
|
public readonly int qts;
|
||||||
|
|
||||||
|
public GetUpdatesDifferenceRequest(int pts, int date, int qts)
|
||||||
|
{
|
||||||
|
this.pts = pts;
|
||||||
|
this.date = date;
|
||||||
|
this.qts = qts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public updates_Difference updatesDifference { get; private set; }
|
||||||
|
|
||||||
|
public override void OnSend(BinaryWriter writer)
|
||||||
|
{
|
||||||
|
writer.Write(0xa041495);
|
||||||
|
writer.Write(pts);
|
||||||
|
writer.Write(date);
|
||||||
|
writer.Write(qts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnResponse(BinaryReader reader)
|
||||||
|
{
|
||||||
|
updatesDifference = TL.Parse<updates_Difference>(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnException(Exception exception)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Confirmed => true;
|
||||||
|
public override bool Responded { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
29
TLSharp.Core/Requests/GetUpdatesStateRequest.cs
Normal file
29
TLSharp.Core/Requests/GetUpdatesStateRequest.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using TLSharp.Core.MTProto;
|
||||||
|
|
||||||
|
namespace TLSharp.Core.Requests
|
||||||
|
{
|
||||||
|
public class GetUpdatesStateRequest : MTProtoRequest
|
||||||
|
{
|
||||||
|
public updates_State updates { get; private set; }
|
||||||
|
|
||||||
|
public override void OnSend(BinaryWriter writer)
|
||||||
|
{
|
||||||
|
writer.Write(0xedd4882a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnResponse(BinaryReader reader)
|
||||||
|
{
|
||||||
|
updates = TL.Parse<updates_State>(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnException(Exception exception)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Confirmed => true;
|
||||||
|
public override bool Responded { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -69,11 +69,13 @@
|
||||||
<Compile Include="Requests\AuthSendSmsRequest.cs" />
|
<Compile Include="Requests\AuthSendSmsRequest.cs" />
|
||||||
<Compile Include="Requests\AuthSignInRequest.cs" />
|
<Compile Include="Requests\AuthSignInRequest.cs" />
|
||||||
<Compile Include="Requests\AuthSignUpRequest.cs" />
|
<Compile Include="Requests\AuthSignUpRequest.cs" />
|
||||||
|
<Compile Include="Requests\GetUpdatesDifferenceRequest.cs" />
|
||||||
<Compile Include="Requests\GetContactsRequest.cs" />
|
<Compile Include="Requests\GetContactsRequest.cs" />
|
||||||
<Compile Include="Requests\GetDialogsRequest.cs" />
|
<Compile Include="Requests\GetDialogsRequest.cs" />
|
||||||
<Compile Include="Requests\GetFileRequest.cs" />
|
<Compile Include="Requests\GetFileRequest.cs" />
|
||||||
<Compile Include="Requests\GetHistoryRequest.cs" />
|
<Compile Include="Requests\GetHistoryRequest.cs" />
|
||||||
<Compile Include="Requests\GetNearestDcRequest.cs" />
|
<Compile Include="Requests\GetNearestDcRequest.cs" />
|
||||||
|
<Compile Include="Requests\GetUpdatesStateRequest.cs" />
|
||||||
<Compile Include="Requests\GetUserFullRequest.cs" />
|
<Compile Include="Requests\GetUserFullRequest.cs" />
|
||||||
<Compile Include="Requests\GetUsersRequest.cs" />
|
<Compile Include="Requests\GetUsersRequest.cs" />
|
||||||
<Compile Include="Requests\ImportByUserName.cs" />
|
<Compile Include="Requests\ImportByUserName.cs" />
|
||||||
|
|
|
||||||
|
|
@ -310,5 +310,24 @@ namespace TLSharp.Core
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<updates_State> GetUpdatesState()
|
||||||
|
{
|
||||||
|
var request = new GetUpdatesStateRequest();
|
||||||
|
|
||||||
|
await _sender.Send(request);
|
||||||
|
await _sender.Receive(request);
|
||||||
|
|
||||||
|
return request.updates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<updates_Difference> GetUpdatesDifference(int lastPts, int lastDate, int lastQts)
|
||||||
|
{
|
||||||
|
var request = new GetUpdatesDifferenceRequest(lastPts, lastDate, lastQts);
|
||||||
|
|
||||||
|
await _sender.Send(request);
|
||||||
|
await _sender.Receive(request);
|
||||||
|
|
||||||
|
return request.updatesDifference;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -294,5 +294,42 @@ namespace TLSharp.Tests
|
||||||
|
|
||||||
Assert.IsNotNull(userFull);
|
Assert.IsNotNull(userFull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task GetUpdates()
|
||||||
|
{
|
||||||
|
var store = new FileSessionStore();
|
||||||
|
var client = new TelegramClient(store, "session", apiId, apiHash);
|
||||||
|
await client.Connect();
|
||||||
|
|
||||||
|
Assert.IsTrue(client.IsUserAuthorized());
|
||||||
|
|
||||||
|
var updatesState = await client.GetUpdatesState();
|
||||||
|
var initialState = updatesState as Updates_stateConstructor;
|
||||||
|
|
||||||
|
Assert.IsNotNull(initialState);
|
||||||
|
|
||||||
|
var difference = await client.GetUpdatesDifference(initialState.pts, initialState.date, initialState.qts);
|
||||||
|
Assert.IsNotNull(difference);
|
||||||
|
Assert.AreEqual(difference.Constructor, Constructor.updates_differenceEmpty);
|
||||||
|
|
||||||
|
var userIdToSendMessage = await client.ImportContactByPhoneNumber(NumberToSendMessage);
|
||||||
|
|
||||||
|
await client.SendMessage(userIdToSendMessage.Value, "test");
|
||||||
|
|
||||||
|
var differenceAfterMessage = await client.GetUpdatesDifference(initialState.pts, initialState.date, initialState.qts);
|
||||||
|
|
||||||
|
Assert.IsNotNull(differenceAfterMessage);
|
||||||
|
Assert.AreEqual(differenceAfterMessage.Constructor, Constructor.updates_difference);
|
||||||
|
|
||||||
|
var differenceUpdate = differenceAfterMessage as Updates_differenceConstructor;
|
||||||
|
Assert.IsNotNull(differenceUpdate);
|
||||||
|
Assert.AreEqual(1, differenceUpdate.new_messages.Count);
|
||||||
|
|
||||||
|
var messageUpdate = differenceUpdate.new_messages[0] as MessageConstructor;
|
||||||
|
Assert.IsNotNull(messageUpdate);
|
||||||
|
|
||||||
|
Assert.AreEqual("test", messageUpdate.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue