From 6faba0f28674a7b2bcd3a9a27b0ff30d5f77bc54 Mon Sep 17 00:00:00 2001 From: omarm Date: Thu, 13 Apr 2017 11:33:46 +0300 Subject: [PATCH] Add length validation foe caption --- TLSharp.Core/TelegramClient.cs | 2 +- TeleSharp.TL/TL/TLInputMediaUploadedPhoto.cs | 55 ++++++++++++-------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index a4fa06a..25ab609 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -269,7 +269,7 @@ namespace TLSharp.Core random_id = Helpers.GenerateRandomLong(), background = false, clear_draft = false, - media = new TLInputMediaUploadedPhoto() { file = file, caption = caption }, + media = new TLInputMediaUploadedPhoto() { file = file, Caption = caption }, peer = peer }); } diff --git a/TeleSharp.TL/TL/TLInputMediaUploadedPhoto.cs b/TeleSharp.TL/TL/TLInputMediaUploadedPhoto.cs index beb4050..7321ad1 100644 --- a/TeleSharp.TL/TL/TLInputMediaUploadedPhoto.cs +++ b/TeleSharp.TL/TL/TLInputMediaUploadedPhoto.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using TeleSharp.TL; namespace TeleSharp.TL { - [TLObject(1661770481)] + [TLObject(1661770481)] public class TLInputMediaUploadedPhoto : TLAbsInputMedia { public override int Constructor @@ -18,41 +18,52 @@ namespace TeleSharp.TL } } - public int flags {get;set;} - public TLAbsInputFile file {get;set;} - public string caption {get;set;} - public TLVector stickers {get;set;} + public int flags { get; set; } + public TLAbsInputFile file { get; set; } + + private string caption; - public void ComputeFlags() - { - flags = 0; -flags = stickers != null ? (flags | 1) : (flags & ~1); + public string Caption + { + get { return caption; } + set + { + caption = value.Length > 200 ? value.Remove(199, value.Length - 199) : value; + } + } + public TLVector stickers { get; set; } - } + + public void ComputeFlags() + { + flags = 0; + flags = stickers != null ? (flags | 1) : (flags & ~1); + + } public override void DeserializeBody(BinaryReader br) { flags = br.ReadInt32(); -file = (TLAbsInputFile)ObjectUtils.DeserializeObject(br); -caption = StringUtil.Deserialize(br); -if ((flags & 1) != 0) -stickers = (TLVector)ObjectUtils.DeserializeVector(br); -else -stickers = null; + file = (TLAbsInputFile)ObjectUtils.DeserializeObject(br); + caption = StringUtil.Deserialize(br); + if ((flags & 1) != 0) + stickers = (TLVector)ObjectUtils.DeserializeVector(br); + else + stickers = null; } public override void SerializeBody(BinaryWriter bw) { - bw.Write(Constructor); + bw.Write(Constructor); ComputeFlags(); -bw.Write(flags); -ObjectUtils.SerializeObject(file,bw); -StringUtil.Serialize(caption,bw); -if ((flags & 1) != 0) -ObjectUtils.SerializeObject(stickers,bw); + bw.Write(flags); + ObjectUtils.SerializeObject(file, bw); + StringUtil.Serialize(caption, bw); + if ((flags & 1) != 0) + ObjectUtils.SerializeObject(stickers, bw); } }