mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-08 07:55:22 +00:00
- fix file Uploader
- refactor file uploader - added test for file uploading
This commit is contained in:
parent
7fd0413c7e
commit
1d6035aeb7
4 changed files with 213 additions and 106 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using TeleSharp.TL;
|
||||
using TeleSharp.TL.Auth;
|
||||
using TeleSharp.TL.Contacts;
|
||||
|
|
@ -10,6 +11,8 @@ using TeleSharp.TL.Messages;
|
|||
using TLSharp.Core.Auth;
|
||||
using TLSharp.Core.MTProto.Crypto;
|
||||
using TLSharp.Core.Network;
|
||||
using TLSharp.Core.Requests;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Core
|
||||
{
|
||||
|
|
@ -53,7 +56,15 @@ namespace TLSharp.Core
|
|||
|
||||
//set-up layer
|
||||
var config = new TLRequestGetConfig();
|
||||
var request = new TLRequestInitConnection() { api_id = _apiId, app_version = "1.0.0", device_model = "PC", lang_code = "en", query = config, system_version = "Win 10.0" };
|
||||
var request = new TLRequestInitConnection()
|
||||
{
|
||||
api_id = _apiId,
|
||||
app_version = "1.0.0",
|
||||
device_model = "PC",
|
||||
lang_code = "en",
|
||||
query = config,
|
||||
system_version = "Win 10.0"
|
||||
};
|
||||
var invokewithLayer = new TLRequestInvokeWithLayer() { layer = 57, query = request };
|
||||
await _sender.Send(invokewithLayer);
|
||||
await _sender.Receive(invokewithLayer);
|
||||
|
|
@ -165,14 +176,12 @@ namespace TLSharp.Core
|
|||
if (!IsUserAuthorized())
|
||||
throw new InvalidOperationException("Authorize user first!");
|
||||
|
||||
long uniqueId = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
|
||||
|
||||
return await SendRequestAsync<TLAbsUpdates>(
|
||||
new TLRequestSendMessage()
|
||||
{
|
||||
peer = peer,
|
||||
message = message,
|
||||
random_id = uniqueId
|
||||
random_id = Helpers.GenerateRandomLong()
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -193,6 +202,37 @@ namespace TLSharp.Core
|
|||
new TLRequestGetDialogs() { offset_date = 0, offset_peer = peer, limit = 100 });
|
||||
}
|
||||
|
||||
public async Task<TLAbsUpdates> SendUploadedPhoto(TLAbsInputPeer peer, TLAbsInputFile file, string caption)
|
||||
{
|
||||
return await SendRequestAsync<TLAbsUpdates>(new TLRequestSendMedia()
|
||||
{
|
||||
random_id = Helpers.GenerateRandomLong(),
|
||||
background = false,
|
||||
clear_draft = false,
|
||||
media = new TLInputMediaUploadedPhoto() { file = file, caption = caption },
|
||||
peer = peer
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<TLAbsUpdates> SendUploadedDocument(
|
||||
TLAbsInputPeer peer, TLAbsInputFile file, string caption, string mimeType, TLVector<TLAbsDocumentAttribute> attributes)
|
||||
{
|
||||
return await SendRequestAsync<TLAbsUpdates>(new TLRequestSendMedia()
|
||||
{
|
||||
random_id = Helpers.GenerateRandomLong(),
|
||||
background = false,
|
||||
clear_draft = false,
|
||||
media = new TLInputMediaUploadedDocument()
|
||||
{
|
||||
file = file,
|
||||
caption = caption,
|
||||
mime_type = mimeType,
|
||||
attributes = attributes
|
||||
},
|
||||
peer = peer
|
||||
});
|
||||
}
|
||||
|
||||
private void OnUserAuthenticated(TLUser TLUser)
|
||||
{
|
||||
_session.TLUser = TLUser;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue