public bool OpenSecretPhoto(TLDecryptedMessageMediaPhoto mediaPhoto) { if (mediaPhoto == null) { return(false); } TLDecryptedMessage17 message = null; for (var i = 0; i < Items.Count; i++) { var message17 = Items[i] as TLDecryptedMessage17; if (message17 != null && message17.Media == mediaPhoto) { message = message17; break; } } if (message == null) { return(false); } if (message.Status == MessageStatus.Sending) { return(false); } var result = false; if (!message.Out.Value) { if (message.TTL != null && message.TTL.Value > 0 && message.TTL.Value <= 60.0) { if (mediaPhoto.TTLParams == null) { message.IsTTLStarted = true; message.DeleteDate = new TLLong(DateTime.Now.Ticks + message.TTL.Value * TimeSpan.TicksPerSecond); mediaPhoto.TTLParams = new TTLParams { StartTime = DateTime.Now, IsStarted = true, Total = message.TTL.Value }; message.Unread = new TLBool(false); message.Status = MessageStatus.Read; CacheService.SyncDecryptedMessage(message, Chat, r => { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var action = new TLDecryptedMessageActionReadMessages(); action.RandomIds = new TLVector <TLLong> { message.RandomId }; var decryptedTuple = GetDecryptedServiceMessageAndObject(action, chat, MTProtoService.CurrentUserId, CacheService); SendEncryptedService(chat, decryptedTuple.Item2, MTProtoService, CacheService, sentEncryptedMessage => { }); }); } SecretPhoto = message; NotifyOfPropertyChange(() => SecretPhoto); result = true; } } else { SecretPhoto = message; NotifyOfPropertyChange(() => SecretPhoto); result = true; } return(result); }
public Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageBase, TLObject> GetDecryptedMessageAndObject(TLString text, TLDecryptedMessageMediaBase media, TLEncryptedChat chat, bool delaySeq = false) { TLDecryptedMessageBase decryptedMessage; TLObject decryptedObject; var randomId = TLLong.Random(); var encryptedChat17 = chat as TLEncryptedChat17; if (encryptedChat17 != null) { var cachedEncryptedChat17 = (TLEncryptedChat17)CacheService.GetEncryptedChat(encryptedChat17.Id); TLInt inSeqNo; TLInt outSeqNo; if (!delaySeq) { inSeqNo = TLUtils.GetInSeqNo(MTProtoService.CurrentUserId, cachedEncryptedChat17); outSeqNo = TLUtils.GetOutSeqNo(MTProtoService.CurrentUserId, cachedEncryptedChat17); cachedEncryptedChat17.RawOutSeqNo = new TLInt(cachedEncryptedChat17.RawOutSeqNo.Value + 1); } else { inSeqNo = new TLInt(-1); outSeqNo = new TLInt(-1); } TLDecryptedMessageBase decryptedMessageBase; if (encryptedChat17.Layer.Value >= 73) { decryptedMessageBase = new TLDecryptedMessage73 { Flags = new TLInt(0), Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength), //Entities = new TLVector<TLMessageEntityBase>(), //ViaBotName = TLString.Empty, //ReplyToRandomMsgId = new TLLong(0), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL ?? new TLInt(0), InSeqNo = inSeqNo, OutSeqNo = outSeqNo }; media.TTLSeconds = decryptedMessageBase.TTL; if (!(media is TLDecryptedMessageMediaEmpty)) { ((TLDecryptedMessage45)decryptedMessageBase).SetMedia(); } } else if (encryptedChat17.Layer.Value >= 45) { decryptedMessageBase = new TLDecryptedMessage45 { Flags = new TLInt(0), Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength), //Entities = new TLVector<TLMessageEntityBase>(), //ViaBotName = TLString.Empty, //ReplyToRandomMsgId = new TLLong(0), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL ?? new TLInt(0), InSeqNo = inSeqNo, OutSeqNo = outSeqNo }; if (!(media is TLDecryptedMessageMediaEmpty)) { ((TLDecryptedMessage45)decryptedMessageBase).SetMedia(); } } else { decryptedMessageBase = new TLDecryptedMessage17 { Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL ?? new TLInt(0), InSeqNo = inSeqNo, OutSeqNo = outSeqNo }; } var decryptedMessageLayer17 = TLUtils.GetDecryptedMessageLayer(encryptedChat17.Layer, inSeqNo, outSeqNo, decryptedMessageBase); decryptedMessage = decryptedMessageBase; decryptedObject = decryptedMessageLayer17; } else { var decryptedMessage8 = new TLDecryptedMessage { Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.Random(Telegram.Api.Constants.MinRandomBytesLength), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL }; decryptedMessage = decryptedMessage8; decryptedObject = decryptedMessage; } return(new Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageBase, TLObject>(decryptedMessage, decryptedObject)); }
public Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageBase, TLObject> GetDecryptedMessageAndObject(TLString text, TLDecryptedMessageMediaBase media, TLEncryptedChat chat, bool delaySeq = false) { TLDecryptedMessageBase decryptedMessage; TLObject decryptedObject; var random = new Random(); var randomId = TLLong.Random(); var textString = text.ToString(); var randomBytes = new byte[] { }; if (string.IsNullOrEmpty(textString) || textString.Length < 16) { randomBytes = new byte[16]; random.NextBytes(randomBytes); } var encryptedChat17 = chat as TLEncryptedChat17; if (encryptedChat17 != null) { var cachedEncryptedChat17 = (TLEncryptedChat17)CacheService.GetEncryptedChat(encryptedChat17.Id); TLInt inSeqNo; TLInt outSeqNo; if (!delaySeq) { inSeqNo = TLUtils.GetInSeqNo(MTProtoService.CurrentUserId, cachedEncryptedChat17); outSeqNo = TLUtils.GetOutSeqNo(MTProtoService.CurrentUserId, cachedEncryptedChat17); cachedEncryptedChat17.RawOutSeqNo = new TLInt(cachedEncryptedChat17.RawOutSeqNo.Value + 1); } else { inSeqNo = new TLInt(-1); outSeqNo = new TLInt(-1); } var decryptedMessage17 = new TLDecryptedMessage17 { Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.FromBigEndianData(randomBytes), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL ?? new TLInt(0), InSeqNo = inSeqNo, OutSeqNo = outSeqNo }; var decryptedMessageLayer17 = new TLDecryptedMessageLayer17(); decryptedMessageLayer17.Layer = encryptedChat17.Layer; decryptedMessageLayer17.InSeqNo = inSeqNo; decryptedMessageLayer17.OutSeqNo = outSeqNo; decryptedMessageLayer17.RandomBytes = TLString.Empty; decryptedMessageLayer17.Message = decryptedMessage17; decryptedMessage = decryptedMessage17; decryptedObject = decryptedMessageLayer17; } else { var decryptedMessage8 = new TLDecryptedMessage { Media = media, Message = text, RandomId = randomId, RandomBytes = TLString.FromBigEndianData(randomBytes), ChatId = chat.Id, FromId = new TLInt(StateService.CurrentUserId), Out = new TLBool(true), Unread = new TLBool(true), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Status = MessageStatus.Sending, TTL = chat.MessageTTL }; decryptedMessage = decryptedMessage8; decryptedObject = decryptedMessage; } return(new Telegram.Api.WindowsPhone.Tuple <TLDecryptedMessageBase, TLObject>(decryptedMessage, decryptedObject)); }