private async Task SendPhotoAsync(StorageFile file, string caption, bool asFile, int?ttl = null) { var chat = _chat; if (chat == null) { return; } var size = await ImageHelper.GetScaleAsync(file); var generated = await file.ToGeneratedAsync(asFile? "copy" : "compress"); var thumbnail = default(InputThumbnail); if (asFile) { var reply = GetReply(true); var input = new InputMessageDocument(generated, thumbnail, GetFormattedText(caption)); await SendMessageAsync(reply, input); } else { var reply = GetReply(true); var input = new InputMessagePhoto(generated, thumbnail, new int[0], size.Width, size.Height, GetFormattedText(caption), ttl ?? 0); await SendMessageAsync(reply, input); } }
//public Task<bool> SendGeoAsync(TLMessageMediaGeoLive media) //{ // var tsc = new TaskCompletionSource<bool>(); // var date = TLUtils.DateToUniversalTimeTLInt(DateTime.Now); // //var message = TLUtils.GetMessage(SettingsHelper.UserId, Peer.ToPeer(), true, true, date, string.Empty, media, 0L, null); // //var previousMessage = InsertSendingMessage(message); // //CacheService.SyncSendingMessage(message, previousMessage, async (m) => // //{ // // var inputMedia = media.ToInputMedia(); // // var result = await LegacyService.SendMediaAsync(Peer, inputMedia, message); // // if (result.IsSucceeded) // // { // // tsc.SetResult(true); // // await _liveLocationService.TrackAsync(message); // // } // // else // // { // // tsc.SetResult(false); // // } // //}); // return tsc.Task; //} private async Task <BaseObject> SendGroupedAsync(ICollection <StorageMedia> items) { var chat = _chat; if (chat == null) { return(null); } var reply = GetReply(true); var operations = new List <InputMessageContent>(); foreach (var item in items) { if (item is StoragePhoto photo) { var file = await photo.GetFileAsync(); var token = StorageApplicationPermissions.FutureAccessList.Enqueue(file); var props = await file.GetBasicPropertiesAsync(); var size = await ImageHelper.GetScaleAsync(file); var input = new InputMessagePhoto(new InputFileGenerated(file.Path, "compress", (int)props.Size), null, new int[0], size.Width, size.Height, GetFormattedText(photo.Caption), photo.Ttl ?? 0); operations.Add(input); } else if (item is StorageVideo video) { //var op = await PrepareVideoAsync(video.File, video.Caption, false, video.IsMuted, groupedId, await video.GetEncodingAsync(), video.GetTransform()); //if (op.message != null && op.operation != null) //{ // operations.Add(op); //} } } return(await ProtoService.SendAsync(new SendMessageAlbum(chat.Id, reply, false, false, operations))); }
//public Task<bool> SendGeoAsync(TLMessageMediaGeoLive media) //{ // var tsc = new TaskCompletionSource<bool>(); // var date = TLUtils.DateToUniversalTimeTLInt(DateTime.Now); // //var message = TLUtils.GetMessage(SettingsHelper.UserId, Peer.ToPeer(), true, true, date, string.Empty, media, 0L, null); // //var previousMessage = InsertSendingMessage(message); // //CacheService.SyncSendingMessage(message, previousMessage, async (m) => // //{ // // var inputMedia = media.ToInputMedia(); // // var result = await LegacyService.SendMediaAsync(Peer, inputMedia, message); // // if (result.IsSucceeded) // // { // // tsc.SetResult(true); // // await _liveLocationService.TrackAsync(message); // // } // // else // // { // // tsc.SetResult(false); // // } // //}); // return tsc.Task; //} private async Task <BaseObject> SendGroupedAsync(ICollection <StorageMedia> items) { var chat = _chat; if (chat == null) { return(null); } var reply = GetReply(true); var operations = new List <InputMessageContent>(); foreach (var item in items) { if (item is StoragePhoto photo) { var file = await photo.GetFileAsync(); var token = StorageApplicationPermissions.FutureAccessList.Enqueue(file); var props = await file.GetBasicPropertiesAsync(); var size = await ImageHelper.GetScaleAsync(file); var input = new InputMessagePhoto(new InputFileGenerated(file.Path, "compress", (int)props.Size), null, new int[0], size.Width, size.Height, GetFormattedText(photo.Caption), photo.Ttl ?? 0); operations.Add(input); } else if (item is StorageVideo video) { //var op = await PrepareVideoAsync(video.File, video.Caption, false, video.IsMuted, groupedId, await video.GetEncodingAsync(), video.GetTransform()); //if (op.message != null && op.operation != null) //{ // operations.Add(op); //} var file = video.File; var profile = await video.GetEncodingAsync(); var transform = video.GetTransform(); var basicProps = await file.GetBasicPropertiesAsync(); var videoProps = await file.Properties.GetVideoPropertiesAsync(); //var thumbnail = await ImageHelper.GetVideoThumbnailAsync(file, videoProps, transform); var videoWidth = (int)videoProps.GetWidth(); var videoHeight = (int)videoProps.GetHeight(); if (profile != null) { videoWidth = videoProps.Orientation == VideoOrientation.Rotate180 || videoProps.Orientation == VideoOrientation.Normal ? (int)profile.Video.Width : (int)profile.Video.Height; videoHeight = videoProps.Orientation == VideoOrientation.Rotate180 || videoProps.Orientation == VideoOrientation.Normal ? (int)profile.Video.Height : (int)profile.Video.Width; } var conversion = new VideoConversion(); if (profile != null) { conversion.Transcode = true; conversion.Mute = profile.Audio == null; conversion.Width = profile.Video.Width; conversion.Height = profile.Video.Height; conversion.Bitrate = profile.Video.Bitrate; if (transform != null) { conversion.Transform = true; conversion.Rotation = transform.Rotation; conversion.OutputSize = transform.OutputSize; conversion.Mirror = transform.Mirror; conversion.CropRectangle = transform.CropRectangle; } } var generated = await file.ToGeneratedAsync("transcode#" + JsonConvert.SerializeObject(conversion)); var thumbnail = await file.ToThumbnailAsync(conversion, "thumbnail_transcode#" + JsonConvert.SerializeObject(conversion)); if (profile != null && profile.Audio == null) { var input = new InputMessageAnimation(generated, thumbnail, (int)videoProps.Duration.TotalSeconds, videoWidth, videoHeight, GetFormattedText(video.Caption)); operations.Add(input); } else { var input = new InputMessageVideo(generated, thumbnail, new int[0], (int)videoProps.Duration.TotalSeconds, videoWidth, videoHeight, true, GetFormattedText(video.Caption), video.Ttl ?? 0); operations.Add(input); } } } return(await ProtoService.SendAsync(new SendMessageAlbum(chat.Id, reply, false, false, operations))); }