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 !");
}
else if (errorMessage == "MESSAGE_ID_INVALID")
{
throw new InvalidOperationException("The provided message id is invalid " + errorMessage);
}
else
{
throw new InvalidOperationException(errorMessage);
@ -548,7 +552,7 @@ namespace TLSharp.Core.Network
private const string REPORT_MESSAGE =
" See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error";
protected DataCenterMigrationException(string msg, int dc) : base (msg + REPORT_MESSAGE)
protected DataCenterMigrationException(string msg, int dc) : base(msg + REPORT_MESSAGE)
{
DC = dc;
}
@ -557,7 +561,7 @@ namespace TLSharp.Core.Network
internal class PhoneMigrationException : DataCenterMigrationException
{
internal PhoneMigrationException(int dc)
: base ($"Phone number registered to a different DC: {dc}.", dc)
: base($"Phone number registered to a different DC: {dc}.", dc)
{
}
}
@ -565,7 +569,7 @@ namespace TLSharp.Core.Network
internal class FileMigrationException : DataCenterMigrationException
{
internal FileMigrationException(int dc)
: base ($"File located on a different DC: {dc}.", dc)
: base($"File located on a different DC: {dc}.", dc)
{
}
}

View file

@ -274,7 +274,22 @@ namespace TLSharp.Core
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())
throw new InvalidOperationException("Authorize user first!");
@ -282,9 +297,8 @@ namespace TLSharp.Core
return await SendRequestAsync<TLAbsUpdates>(
new TLRequestForwardMessage()
{
//MessageId = _session.GetNewMessageId(),
Id = messageId,
Peer = peerfrom,
Peer = peer,
RandomId = Helpers.GenerateRandomLong()
});
}
@ -369,6 +383,22 @@ namespace TLSharp.Core
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>
/// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found;
/// </summary>

View file

@ -7,6 +7,76 @@ using System.Threading.Tasks;
using TeleSharp.TL;
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)]
public class TLRequestForwardMessages : TLMethod
{