Merge fix.

This commit is contained in:
steavy29 2016-09-14 14:57:07 +03:00
parent 8411235fe1
commit 78e3a7794f
4 changed files with 103 additions and 16 deletions

View file

@ -78,7 +78,12 @@ Currently supported methods:
- [Get Contact by Username](#get-contact-by-username) - [Get Contact by Username](#get-contact-by-username)
- [Send Message to Contact](#send-message-to-contact) - [Send Message to Contact](#send-message-to-contact)
- [Send Media to Contact](#send-media-to-contact) - [Send Media to Contact](#send-media-to-contact)
- [Get Messages History for a Contact](#get-messages-history) - [Get Messages History for Contact](#get-messages-history-for-contact)
- [Get UserFull](#get-userfull)
- [Create Chat](#create-chat)
- [Add Chat user](#add-chat-user)
- [Delete Chat user](#delete-chat-user)
- [Leave Chat](#leave-chat)
- [Get Updates State](#get-updates-state) - [Get Updates State](#get-updates-state)
- [Get Updates Difference](#get-updates-difference) - [Get Updates Difference](#get-updates-difference)
@ -185,7 +190,7 @@ var res = await client.SendMediaMessage(userId, mediaFile);
**Returns**: **bool**, file sent or not **Returns**: **bool**, file sent or not
####Get Messages History ####Get Messages History for Contact
Returns messages history for specified userId. Returns messages history for specified userId.
_Example_: _Example_:
@ -200,7 +205,7 @@ var hist = await client.GetMessagesHistoryForContact(userId, offset, limit);
**Returns**: **List\<Message\>**, message history **Returns**: **List\<Message\>**, message history
####Get UserFull Request ####Get UserFull
Returns user's full information for specified userId. Returns user's full information for specified userId.
_Example_: _Example_:
@ -213,6 +218,61 @@ var userFull = await client.GetUserFull(userId);
**Returns**: **UserFull**, User's information **Returns**: **UserFull**, User's information
####Create Chat
Creates a new chat.
_Example_:
```
var statedMessage = await client.CreateChat(title, new List<string> { userId1, userId2 });
```
* title - **string**, chat name
* userIdsToInvite - **List<int>**, list of userIds to invite to chat. Current user will be automatically added to this chat.
**Returns**: **Messages_statedMessageConstructor**, Message that contains information about created chat.
####Add Chat user
Adds a user to a chat and sends a service message on it.
_Example_:
```
var statedMessage = await client.AddChatUser(chatId, userId);
```
* chatId - **int**, Chat ID
* userId - **int**, User ID to be added
**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat.
####Delete Chat user
Deletes a user from a chat and sends a service message on it.
_Example_:
```
var statedMessage = await client.DeleteChatUser(chatId, userId);
```
* chatId - **int**, Chat ID
* userId - **int**, User ID to be deleted
**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat.
####Leave Chat
Leaves the chat by deleting currently authenticated user from it.
_Example_:
```
var statedMessage = await client.LeaveChat(chatId);
```
* chatId - **int**, Chat ID
**Returns**: **Messages_statedMessageConstructor**, Message that contains information about modified chat.
####Get Updates State ####Get Updates State
Returns a current state of updates. Returns a current state of updates.

View file

@ -312,23 +312,23 @@ namespace TLSharp.Core
public async Task<Messages_statedMessageConstructor> CreateChat(string title, List<string> userPhonesToInvite) public async Task<Messages_statedMessageConstructor> CreateChat(string title, List<string> userPhonesToInvite)
{ {
var request = new GetUpdatesStateRequest(); var userIdsToInvite = new List<int>();
foreach (var userPhone in userPhonesToInvite)
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); var uid = await ImportContactByPhoneNumber(userPhone);
if (!uid.HasValue)
throw new InvalidOperationException($"Failed to retrieve contact {userPhone}");
await _sender.Send(request); userIdsToInvite.Add(uid.Value);
await _sender.Receive(request);
return request.updatesDifference;
} }
return await CreateChat(title, userIdsToInvite);
}
public async Task<Messages_statedMessageConstructor> CreateChat(string title, List<int> userIdsToInvite)
{
var request = new CreateChatRequest(userIdsToInvite.Select(uid => new InputUserContactConstructor(uid)).ToList(), title);
await _sender.Send(request); await _sender.Send(request);
await _sender.Receive(request); await _sender.Receive(request);
@ -359,5 +359,25 @@ namespace TLSharp.Core
{ {
return await DeleteChatUser(chatId, ((UserSelfConstructor) _session.User).id); return await DeleteChatUser(chatId, ((UserSelfConstructor) _session.User).id);
} }
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;
}
} }
} }

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -25,6 +26,8 @@ namespace TLSharp.Tests
private string NumberToGetUserFull { get; set; } private string NumberToGetUserFull { get; set; }
private string NumberToAddToChat { get; set; }
private string apiHash = ""; private string apiHash = "";
private int apiId = 0; private int apiId = 0;
@ -53,6 +56,9 @@ namespace TLSharp.Tests
if (string.IsNullOrEmpty(NumberToGetUserFull)) if (string.IsNullOrEmpty(NumberToGetUserFull))
Debug.WriteLine("NumberToGetUserFull not configured in app.config! Some tests may fail."); Debug.WriteLine("NumberToGetUserFull not configured in app.config! Some tests may fail.");
NumberToAddToChat = ConfigurationManager.AppSettings[nameof(NumberToAddToChat)];
if (string.IsNullOrEmpty(NumberToAddToChat))
Debug.WriteLine("NumberToAddToChat not configured in app.config! Some tests may fail.");
} }
[TestMethod] [TestMethod]
@ -321,7 +327,7 @@ namespace TLSharp.Tests
var createdChat = GetChatFromStatedMessage(statedMessageAfterCreation); var createdChat = GetChatFromStatedMessage(statedMessageAfterCreation);
var addUserId = await client.ImportContactByPhoneNumber("380685004559"); var addUserId = await client.ImportContactByPhoneNumber(NumberToAddToChat);
var statedMessageAfterAddUser = await client.AddChatUser(createdChat.id, addUserId.Value); var statedMessageAfterAddUser = await client.AddChatUser(createdChat.id, addUserId.Value);
var modifiedChat = GetChatFromStatedMessage(statedMessageAfterAddUser); var modifiedChat = GetChatFromStatedMessage(statedMessageAfterAddUser);

View file

@ -6,5 +6,6 @@
<add key="NumberToSendMessage" value=""/> <add key="NumberToSendMessage" value=""/>
<add key="UserNameToSendMessage" value=""/> <add key="UserNameToSendMessage" value=""/>
<add key="NumberToGetUserFull" value=""/> <add key="NumberToGetUserFull" value=""/>
<add key="NumberToAddToChat" value=""/>
</appSettings> </appSettings>
</configuration> </configuration>