fix forward mesages

This commit is contained in:
meysam navaei 2017-12-15 15:37:49 +03:30
parent 7a01fa84b4
commit a3b58d6bb0
3 changed files with 467 additions and 363 deletions

View file

@ -319,6 +319,10 @@ namespace TLSharp.Core.Network
{ {
throw new CloudPasswordNeededException("This Account has Cloud Password !"); throw new CloudPasswordNeededException("This Account has Cloud Password !");
} }
else if (errorMessage == "MESSAGE_ID_INVALID")
{
throw new InvalidOperationException("The provided message id is invalid " + errorMessage);
}
else else
{ {
throw new InvalidOperationException(errorMessage); throw new InvalidOperationException(errorMessage);

View file

@ -274,7 +274,22 @@ namespace TLSharp.Core
return await SendRequestAsync<TLUpdates>(aa); return await SendRequestAsync<TLUpdates>(aa);
} }
public async Task<TLAbsUpdates> ForwardMessageAsync(TLAbsInputPeer peerfrom, int messageId) public async Task<TLAbsUpdates> ForwardMessagesAsync(TLAbsInputPeer peerfrom, TLAbsInputPeer peerto, TLVector<int> messagesId)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
return await SendRequestAsync<TLAbsUpdates>(
new TLRequestForwardMessages()
{
Id = messagesId,
ToPeer = peerto,
FromPeer = peerfrom,
RandomId = new TLVector<long>() { Helpers.GenerateRandomLong() }
});
}
public async Task<TLAbsUpdates> ForwardMessageAsync(TLAbsInputPeer peer, int messageId)
{ {
if (!IsUserAuthorized()) if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!"); throw new InvalidOperationException("Authorize user first!");
@ -282,9 +297,8 @@ namespace TLSharp.Core
return await SendRequestAsync<TLAbsUpdates>( return await SendRequestAsync<TLAbsUpdates>(
new TLRequestForwardMessage() new TLRequestForwardMessage()
{ {
//MessageId = _session.GetNewMessageId(),
Id = messageId, Id = messageId,
Peer = peerfrom, Peer = peer,
RandomId = Helpers.GenerateRandomLong() RandomId = Helpers.GenerateRandomLong()
}); });
} }
@ -369,6 +383,22 @@ namespace TLSharp.Core
return await SendRequestAsync<TLAbsMessages>(req); return await SendRequestAsync<TLAbsMessages>(req);
} }
public async Task<TLAbsMessages> GetHistoryAsync(TLAbsInputPeer peer, int offset, int max_id, int min_id, int limit)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestGetHistory()
{
Peer = peer,
AddOffset = offset,
MaxId = max_id,
MinId = min_id,
Limit = limit
};
return await SendRequestAsync<TLAbsMessages>(req);
}
/// <summary> /// <summary>
/// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found;
/// </summary> /// </summary>

View file

@ -7,6 +7,76 @@ using System.Threading.Tasks;
using TeleSharp.TL; using TeleSharp.TL;
namespace TeleSharp.TL.Messages namespace TeleSharp.TL.Messages
{ {
//[TLObject(0x708e0195)]
//public class TLRequestForwardMessages : TLMethod
//{
// // Methods
// public void ComputeFlags()
// {
// this.flags = 0;
// this.flags = this.silent ? (this.flags | 0x20) : (this.flags & -33);
// this.flags = this.background ? (this.flags | 0x40) : (this.flags & -65);
// this.flags = this.with_my_score ? (this.flags | 0x100) : (this.flags & -257);
// }
// public override void DeserializeBody(BinaryReader br)
// {
// this.flags = br.ReadInt32();
// this.silent = (this.flags & 0x20) > 0;
// this.background = (this.flags & 0x40) > 0;
// this.with_my_score = (this.flags & 0x100) > 0;
// this.from_peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br);
// this.id = ObjectUtils.DeserializeVector<int>(br);
// this.random_id = ObjectUtils.DeserializeVector<long>(br);
// this.to_peer = (TLAbsInputPeer)ObjectUtils.DeserializeObject(br);
// }
// public override void DeserializeResponse(BinaryReader br)
// {
// this.Response = (TLAbsUpdates)ObjectUtils.DeserializeObject(br);
// }
// public override void SerializeBody(BinaryWriter bw)
// {
// bw.Write(this.Constructor);
// this.ComputeFlags();
// bw.Write(this.flags);
// ObjectUtils.SerializeObject(this.from_peer, bw);
// ObjectUtils.SerializeObject(this.id, bw);
// ObjectUtils.SerializeObject(this.random_id, bw);
// ObjectUtils.SerializeObject(this.to_peer, bw);
// }
// // Properties
// public bool background { get; set; }
// public override int Constructor
// {
// get
// {
// return 0x708e0195;
// }
// }
// public int flags { get; set; }
// public TLAbsInputPeer from_peer { get; set; }
// public TLVector<int> id { get; set; }
// public TLVector<long> random_id { get; set; }
// public TLAbsUpdates Response { get; set; }
// public bool silent { get; set; }
// public TLAbsInputPeer to_peer { get; set; }
// public bool with_my_score { get; set; }
//}
[TLObject(1888354709)] [TLObject(1888354709)]
public class TLRequestForwardMessages : TLMethod public class TLRequestForwardMessages : TLMethod
{ {