public override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowExceptionIfIncorrect(ref position, Signature); MessageId = GetObject <TLLong>(bytes, ref position); PingId = GetObject <TLLong>(bytes, ref position); return(this); }
private UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, string fileName, long fileLength) { FileUtils.SwitchIdleDetectionMode(false); var item = new UploadableItem(fileId, owner, fileName, fileLength); item.Parts = GetItemParts(item, fileLength); return(item); }
public UploadableItem(TLLong fileId, TLObject owner, StorageFile file, TLString key, TLString iv) { FileId = fileId; Owner = owner; File = file; Key = key; IV = iv; }
public override TLObject FromBytes(byte[] bytes, ref int position) { TLUtils.WriteLine("--Parse TLImportedContact--"); bytes.ThrowExceptionIfIncorrect(ref position, Signature); UserId = GetObject <TLInt>(bytes, ref position); ClientId = GetObject <TLLong>(bytes, ref position); return(this); }
public override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowExceptionIfIncorrect(ref position, Signature); SecureAlgo = GetObject <TLSecurePasswordKdfAlgoBase>(bytes, ref position); SecureSecret = GetObject <TLString>(bytes, ref position); SecureSecretId = GetObject <TLLong>(bytes, ref position); return(this); }
public static TLNonEncryptedMessage CreateTLNonEncryptedMessage(TLLong messageId, TLObject obj) { var message = new TLNonEncryptedMessage(); message.AuthKeyId = new TLLong(0); message.MessageId = messageId; message.Data = obj; return(message); }
public void SetChannelPhoto() { EditChatActions.EditPhoto(photo => { var volumeId = TLLong.Random(); var localId = TLInt.Random(); var secret = TLLong.Random(); var fileLocation = new TLFileLocation { VolumeId = volumeId, LocalId = localId, Secret = secret, DCId = new TLInt(0), //Buffer = p.Bytes }; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.CreateFile(fileName)) { fileStream.Write(photo, 0, photo.Length); } } Photo = new TLChatPhoto { PhotoSmall = new TLFileLocation { DCId = fileLocation.DCId, VolumeId = fileLocation.VolumeId, LocalId = fileLocation.LocalId, Secret = fileLocation.Secret }, PhotoBig = new TLFileLocation { DCId = fileLocation.DCId, VolumeId = fileLocation.VolumeId, LocalId = fileLocation.LocalId, Secret = fileLocation.Secret } }; NotifyOfPropertyChange(() => Photo); _uploadingPhoto = true; var fileId = TLLong.Random(); _uploadManager.UploadFile(fileId, new TLChannel(), photo); }); }
private void SendDocument(string fileName) { //create thumb byte[] bytes; using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, bytes.Length); } } if (!CheckDocumentSize((ulong)bytes.Length)) { MessageBox.Show(string.Format(AppResources.MaximumFileSizeExceeded, MediaSizeConverter.Convert((int)Telegram.Api.Constants.MaximumUploadedFileSize)), AppResources.Error, MessageBoxButton.OK); return; } //create document var document = new TLDocument22 { Buffer = bytes, Id = new TLLong(0), AccessHash = new TLLong(0), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), FileName = new TLString(Path.GetFileName(fileName)), MimeType = new TLString("text/plain"), Size = new TLInt(bytes.Length), Thumb = new TLPhotoSizeEmpty { Type = TLString.Empty }, DCId = new TLInt(0) }; var media = new TLMessageMediaDocument { FileId = TLLong.Random(), Document = document }; var message = GetMessage(TLString.Empty, media); BeginOnUIThread(() => { var previousMessage = InsertSendingMessage(message); IsEmptyDialog = Items.Count == 0 && LazyItems.Count == 0; BeginOnThreadPool(() => CacheService.SyncSendingMessage( message, previousMessage, TLUtils.InputPeerToPeer(Peer, StateService.CurrentUserId), m => SendDocumentInternal(message, null))); }); }
private void SendDocument(Photo p) { var chat = Chat as TLEncryptedChat; if (chat == null) { return; } var dcId = TLInt.Random(); var id = TLLong.Random(); var accessHash = TLLong.Random(); var fileLocation = new TLEncryptedFile { Id = id, AccessHash = accessHash, DCId = dcId, Size = new TLInt(p.Bytes.Length), KeyFingerprint = new TLInt(0), FileName = new TLString(Path.GetFileName(p.FileName)) }; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.Id, fileLocation.DCId, fileLocation.AccessHash); using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fileStream = store.CreateFile(fileName)) { fileStream.Write(p.Bytes, 0, p.Bytes.Length); } } var keyIV = GenerateKeyIV(); int thumbHeight; int thumbWidth; var thumb = ImageUtils.CreateThumb(p.Bytes, Constants.DocumentPreviewMaxSize, Constants.DocumentPreviewQuality, out thumbHeight, out thumbWidth); var decryptedMediaDocument = GetDecryptedMediaDocument(p, chat, TLString.FromBigEndianData(thumb), new TLInt(thumbWidth), new TLInt(thumbHeight), new TLString("image/jpeg"), keyIV, fileLocation); var decryptedTuple = GetDecryptedMessageAndObject(TLString.Empty, decryptedMediaDocument, chat, true); InsertSendingMessage(decryptedTuple.Item1); RaiseScrollToBottom(); NotifyOfPropertyChange(() => DescriptionVisibility); BeginOnThreadPool(() => CacheService.SyncDecryptedMessage(decryptedTuple.Item1, chat, cachedMessage => SendDocumentInternal(p.Bytes, decryptedTuple.Item2))); }
public void UploadFile(TLLong fileId, TLObject owner, StorageFile file) { var item = GetUploadableItem(fileId, owner, file); lock (_itemsSyncRoot) { _items.Add(item); } StartAwaitingWorkers(); }
public override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowExceptionIfIncorrect(ref position, Signature); BadMessageId = GetObject <TLLong>(bytes, ref position); BadMessageSeqNo = GetObject <TLInt>(bytes, ref position); ErrorCode = GetObject <TLInt>(bytes, ref position); NewServerSalt = GetObject <TLLong>(bytes, ref position); return(this); }
public override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowIfIncorrectSignature(ref position, SIGNATURE); ClientID = new TLLong(bytes, ref position); Phone = new TLString(bytes, ref position); FirstName = new TLString(bytes, ref position); LastName = new TLString(bytes, ref position); return this; }
public void SaveFilePartAsync(TLLong fileId, TLInt filePart, TLString bytes, Action <TLBool> callback, Action <TLRPCError> faultCallback = null) { var filePartValue = filePart.Value; var bytesLength = bytes.Data.Length; var obj = new TLSaveFilePart { FileId = fileId, FilePart = filePart, Bytes = bytes }; SendInformativeMessage("upload.saveFilePart" + " " + filePart.Value, obj, callback, faultCallback); }
//~EditCurrentUserViewModel() //{ //} public void SetProfilePhoto() { EditCurrentUserActions.EditPhoto(photo => { var fileId = TLLong.Random(); IsWorking = true; _uploadManager.UploadFile(fileId, new TLUser66 { IsSelf = true }, photo); }); }
private void UploadPhotoInternal(IList <TLMessage> messages) { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); } }
private void PingMainTransportAsync(TLProxyBase item, ITransport transport) { MTProtoService.PingAsync(TLLong.Random(), pong => Execute.BeginOnUIThread(() => { item.Ping = transport.Ping > 0 ? new TLInt((int)transport.Ping) : null; Set(_proxyConfig); })); }
public void UploadFile(TLLong fileId, TLObject owner, StorageFile file, TLString key, TLString iv) { FileUtils.SwitchIdleDetectionMode(false); var item = FileUtils.GetUploadableItem(fileId, owner, file, key, iv); lock (_itemsSyncRoot) { _items.Add(item); } StartAwaitingWorkers(); }
public void UploadFile(TLLong fileId, TLObject owner, byte[] bytes) { FileUtils.SwitchIdleDetectionMode(false); var item = GetUploadableItem(fileId, owner, bytes); lock (_itemsSyncRoot) { _items.Add(item); } StartAwaitingWorkers(); }
private TLTransportMessage CreateTLTransportMessage(TLLong salt, TLLong sessionId, TLInt seqNo, TLLong messageId, TLObject obj) { var message = new TLTransportMessage(); message.Salt = salt; message.SessionId = sessionId; message.MessageId = messageId; message.SeqNo = seqNo; message.MessageData = obj; return(message); }
public void ReplacePhoto() { if (CurrentItem is TLChat || CurrentItem is TLChannel) { EditChatActions.EditPhoto(photo => { var fileId = TLLong.Random(); IsWorking = true; _uploadManager.UploadFile(fileId, CurrentItem, photo); }); } }
public void PingAsync(TLLong pingId, Action <TLPong> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLPing { PingId = pingId }; SendNonInformativeMessage <TLPong>("ping", obj, result => { callback.SafeInvoke(result); }, faultCallback.SafeInvoke); }
public void PingDelayDisconnectAsync(TLLong pingId, TLInt disconnectDelay, Action <TLPong> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLPingDelayDisconnect { PingId = pingId, DisconnectDelay = disconnectDelay }; SendNonInformativeMessage <TLPong>("ping_delay_disconnect", obj, result => { callback.SafeInvoke(result); }, faultCallback.SafeInvoke); }
public void CancelUploadFile(TLLong fileId) { lock (_itemsSyncRoot) { var item = _items.FirstOrDefault(x => x.FileId.Value == fileId.Value); if (item != null) { item.Canceled = true; //_items.Remove(item); } } }
public static UploadableItem GetUploadableItem(TLLong fileId, TLObject owner, StorageFile file, TLString key, TLString iv) { var item = new UploadableItem(fileId, owner, file, key, iv); var task = file.GetBasicPropertiesAsync().AsTask(); task.Wait(); var propertie = task.Result; var size = propertie.Size; item.Parts = GetItemParts(item, (int)size); return(item); }
public void AcceptEncryptionAsync(TLInputEncryptedChat peer, TLString gb, TLLong keyFingerprint, Action <TLEncryptedChatBase> callback, Action <TLRPCError> faultCallback = null) { var obj = new TLAcceptEncryption { Peer = peer, GB = gb, KeyFingerprint = keyFingerprint }; SendInformativeMessage <TLEncryptedChatBase>("messages.acceptEncryption", obj, encryptedChat => { _cacheService.SyncEncryptedChat(encryptedChat, callback.SafeInvoke); }, faultCallback); }
private void SendPhotoInternal(IList <TLMessage> messages) { //if (messages.Count == 3) //{ // SendPhotoInternal((TLMessage25)messages[1]); // SendPhotoInternal((TLMessage25)messages[0]); // SendPhotoInternal((TLMessage25)messages[2]); //} //else { for (var i = 0; i < messages.Count; i++) { var message = messages[i]; //var photo = ((TLMessageMediaPhoto)message.Media).Photo as TLPhoto; //if (photo == null) return; //var photoSize = photo.Sizes[0] as TLPhotoSize; //if (photoSize == null) return; //var fileLocation = photoSize.Location; //if (fileLocation == null) return; //byte[] bytes = null; //var fileName = String.Format("{0}_{1}_{2}.jpg", // fileLocation.VolumeId, // fileLocation.LocalId, // fileLocation.Secret); //using (var store = IsolatedStorageFile.GetUserStoreForApplication()) //{ // using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read)) // { // if (fileStream.Length > 0) // { // bytes = new byte[fileStream.Length]; // fileStream.Read(bytes, 0, bytes.Length); // } // } //} //if (bytes == null) return; var fileId = TLLong.Random(); message.Media.FileId = fileId; message.Media.UploadingProgress = 0.001; UploadFileManager.UploadFile(fileId, message, message.Media.File); //SendPhotoInternal((TLMessage25)messages[i]); } } }
private static async Task <TLPhotoSizeBase> GetFileThumbAsync(StorageFile file) { try { var thumb = await file.GetThumbnailAsync(ThumbnailMode.PicturesView, 190, ThumbnailOptions.ResizeThumbnail); var volumeId = TLLong.Random(); var localId = TLInt.Random(); var secret = TLLong.Random(); var thumbLocation = new TLFileLocation { DCId = new TLInt(0), VolumeId = volumeId, LocalId = localId, Secret = secret, }; var fileName = String.Format("{0}_{1}_{2}.jpg", thumbLocation.VolumeId, thumbLocation.LocalId, thumbLocation.Secret); var thumbFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); var thumbBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumb.Size)); var iBuf = await thumb.ReadAsync(thumbBuffer, thumbBuffer.Capacity, InputStreamOptions.None); using (var thumbStream = await thumbFile.OpenAsync(FileAccessMode.ReadWrite)) { await thumbStream.WriteAsync(iBuf); } var thumbSize = new TLPhotoSize { W = new TLInt((int)thumb.OriginalWidth), H = new TLInt((int)thumb.OriginalHeight), Size = new TLInt((int)thumb.Size), Type = new TLString(""), Location = thumbLocation, }; return(thumbSize); } catch (Exception ex) { Telegram.Api.Helpers.Execute.ShowDebugMessage("GetFileThumbAsync exception " + ex); } return(null); }
private async void EditPhotoExecute(StorageFile file) { var fileLocation = new TLFileLocation { VolumeId = TLLong.Random(), LocalId = TLInt.Random(), Secret = TLLong.Random(), DCId = 0 }; var fileName = string.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); var fileCache = await FileUtils.CreateTempFileAsync(fileName); //var fileScale = await ImageHelper.ScaleJpegAsync(file, fileCache, 640, 0.77); await file.CopyAndReplaceAsync(fileCache); var fileScale = fileCache; var basicProps = await fileScale.GetBasicPropertiesAsync(); var imageProps = await fileScale.Properties.GetImagePropertiesAsync(); var fileId = TLLong.Random(); var upload = await _uploadFileManager.UploadFileAsync(fileId, fileCache.Name); if (upload != null) { var response = await ProtoService.UploadProfilePhotoAsync(upload.ToInputFile() as TLInputFile); if (response.IsSucceeded) { var user = Self as TLUser; if (user == null) { return; } var userFull = CacheService.GetFullUser(user.Id); if (userFull == null) { return; } userFull.HasProfilePhoto = true; userFull.ProfilePhoto = response.Result.Photo; userFull.RaisePropertyChanged(() => userFull.ProfilePhoto); } } }
public void UploadFile(TLLong fileId, bool isGif, TLObject owner, StorageFile file) { FileUtils.SwitchIdleDetectionMode(false); var item = FileUtils.GetUploadableItem(fileId, owner, file); item.IsSmallFile = isGif && item.Parts.Sum(part => part.Count) < Constants.GifMaxSize; lock (_itemsSyncRoot) { _items.Add(item); } StartAwaitingWorkers(); }
public async Task <TLMessage25> GetPhotoMessage(StorageFile file) { var volumeId = TLLong.Random(); var localId = TLInt.Random(); var secret = TLLong.Random(); var fileLocation = new TLFileLocation { VolumeId = volumeId, LocalId = localId, Secret = secret, DCId = new TLInt(0), //TODO: remove from here, replace with FileLocationUnavailable //Buffer = p.Bytes }; var fileName = String.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); var stream = await file.OpenReadAsync(); var resizedPhoto = await ResizeJpeg(stream, Constants.DefaultImageSize, file.DisplayName, fileName); var photoSize = new TLPhotoSize { Type = TLString.Empty, W = new TLInt(resizedPhoto.Width), H = new TLInt(resizedPhoto.Height), Location = fileLocation, Size = new TLInt(resizedPhoto.Bytes.Length) }; var photo = new TLPhoto33 { Id = new TLLong(0), AccessHash = new TLLong(0), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), Sizes = new TLVector <TLPhotoSizeBase> { photoSize }, }; var media = new TLMessageMediaPhoto28 { Photo = photo, Caption = TLString.Empty, File = resizedPhoto.File }; return(GetMessage(TLString.Empty, media)); }
public void AddComments() { var broadcast = With as TLBroadcastChat; if (broadcast == null) { return; } var broadcastPeer = new TLPeerBroadcast { Id = broadcast.Id }; var count = new Random().Next(1, 5); var group = new TLMessageGroup { Count = new TLInt(count), Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), MaxId = new TLInt(int.MaxValue), MinId = new TLInt(0) }; var action = new TLMessageActionMessageGroup { Group = group }; var serviceMessage = new TLMessageService17 { FromId = new TLInt(StateService.CurrentUserId), ToId = broadcastPeer, Status = MessageStatus.Confirmed, Out = new TLBool { Value = true }, Date = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now), RandomId = TLLong.Random(), Action = action }; serviceMessage.SetUnread(TLBool.False); Items.Insert(0, serviceMessage); CacheService.SyncMessage(serviceMessage, broadcastPeer, message => { }); }
private void parse(ref int position, byte[] buffer = null, Stream input = null) { if (buffer == null && input == null) throw new InvalidDataException(); switch (this.SIGNATURE) { case Signature.InputUserEmpty: case Signature.InputUserSelf: break; case Signature.InputUserForeign: UserID = buffer == null ? new TLInt(input, ref position) : new TLInt(buffer, ref position); AccessHash = buffer == null ? new TLLong(input, ref position) : new TLLong(buffer, ref position); break; case Signature.InputUserContact: UserID = buffer == null ? new TLInt(input, ref position) : new TLInt(buffer, ref position); break; } }
public override TLObject FromStream(Stream input, ref int position) { input.ThrowIfIncorrectSignature(ref position, SIGNATURE); ClientID = new TLLong(input, ref position); Phone = new TLString(input, ref position); FirstName = new TLString(input, ref position); LastName = new TLString(input, ref position); return this; }