mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
UserFullConstructor : UserFull no accepts self id.
Added test method to GetUserFull Added info to README.md
This commit is contained in:
parent
2fff2d11c2
commit
6365297aaf
13
README.md
13
README.md
|
|
@ -179,6 +179,19 @@ var hist = await client.GetMessagesHistoryForContact(userId, offset, limit);
|
|||
|
||||
**Returns**: **List\<Message\>**, message history
|
||||
|
||||
####Get UserFull Request
|
||||
Returns user's full information for specified userId.
|
||||
|
||||
_Example_:
|
||||
|
||||
```
|
||||
var userFull = await client.GetUserFull(userId);
|
||||
```
|
||||
|
||||
* userId - **int**, user id
|
||||
|
||||
**Returns**: **UserFull**, User's information
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributing is highly appreciated!
|
||||
|
|
|
|||
|
|
@ -7126,10 +7126,15 @@ namespace TLSharp.Core.MTProto
|
|||
|
||||
public override void Read(BinaryReader reader)
|
||||
{
|
||||
this.user = new UserRequestConstructor();
|
||||
uint dataCode = reader.ReadUInt32();
|
||||
if (reader.ReadUInt32() == 0x7007b451)
|
||||
{
|
||||
this.user = new UserSelfConstructor();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.user = new UserRequestConstructor();
|
||||
}
|
||||
this.user.Read(reader);
|
||||
|
||||
this.link = TL.Parse<contacts_Link>(reader);
|
||||
this.profile_photo = TL.Parse<Photo>(reader);
|
||||
this.notify_settings = TL.Parse<PeerNotifySettings>(reader);
|
||||
|
|
|
|||
42
TLSharp.Core/Requests/GetUserFullRequest.cs
Normal file
42
TLSharp.Core/Requests/GetUserFullRequest.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class GetUserFullRequest : MTProtoRequest
|
||||
{
|
||||
private InputUser _inputUser;
|
||||
public UserFull _userFull;
|
||||
|
||||
public GetUserFullRequest(int id)
|
||||
{
|
||||
_inputUser = new InputUserContactConstructor(id);
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0xca30a5b1);
|
||||
_inputUser.Write(writer);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
_userFull = new UserFullConstructor();
|
||||
var dataCode = reader.ReadUInt32();
|
||||
_userFull.Read(reader);
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Responded
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +71,7 @@
|
|||
<Compile Include="Requests\GetFileRequest.cs" />
|
||||
<Compile Include="Requests\GetHistoryRequest.cs" />
|
||||
<Compile Include="Requests\GetNearestDcRequest.cs" />
|
||||
<Compile Include="Requests\GetUserFullRequest.cs" />
|
||||
<Compile Include="Requests\GetUsersRequest.cs" />
|
||||
<Compile Include="Requests\ImportByUserName.cs" />
|
||||
<Compile Include="Requests\ImportContactRequest.cs" />
|
||||
|
|
|
|||
|
|
@ -241,6 +241,15 @@ namespace TLSharp.Core
|
|||
return request.messages;
|
||||
}
|
||||
|
||||
public async Task<UserFull> GetUserFull(int user_id)
|
||||
{
|
||||
var request = new GetUserFullRequest(user_id);
|
||||
await _sender.Send(request);
|
||||
await _sender.Recieve(request);
|
||||
|
||||
return request._userFull;
|
||||
}
|
||||
|
||||
private bool validateNumber(string number)
|
||||
{
|
||||
var regex = new Regex("^\\d{7,20}$");
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ namespace TLSharp.Tests
|
|||
|
||||
private string UserNameToSendMessage { get; set; }
|
||||
|
||||
private string NumberToGetUserFull { get; set; }
|
||||
|
||||
private string apiHash = "";
|
||||
|
||||
private int apiId = 0;
|
||||
|
|
@ -39,6 +41,10 @@ namespace TLSharp.Tests
|
|||
if (string.IsNullOrEmpty(UserNameToSendMessage))
|
||||
throw new InvalidOperationException("UserNameToSendMessage is null. Specify userName in app.config");
|
||||
|
||||
NumberToGetUserFull = ConfigurationManager.AppSettings["numberToGetUserFull"];
|
||||
if (string.IsNullOrEmpty(NumberToGetUserFull))
|
||||
throw new InvalidOperationException("NumberToGetUserFull is null. Specify Number in app.config");
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -197,5 +203,23 @@ namespace TLSharp.Tests
|
|||
Assert.IsNotNull(authKey.AuthKey.Data);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetUserFullRequest()
|
||||
{
|
||||
var store = new FileSessionStore();
|
||||
var client = new TelegramClient(store, "session", apiId, apiHash);
|
||||
await client.Connect();
|
||||
|
||||
Assert.IsTrue(client.IsUserAuthorized());
|
||||
|
||||
var res = await client.ImportContactByPhoneNumber(NumberToGetUserFull);
|
||||
|
||||
Assert.IsNotNull(res);
|
||||
|
||||
var userFull = await client.GetUserFull(res.Value);
|
||||
|
||||
Assert.IsNotNull(userFull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@
|
|||
<add key="numberToAuthenticate" value="" />
|
||||
<add key="numberToSendMessage" value=""/>
|
||||
<add key="userNameToSendMessage" value=""/>
|
||||
<add key="NumberToGetUserFull" value=""/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
|
|
|
|||
Loading…
Reference in a new issue