示例#1
0
        public async void AnimationSendExecute(Animation animation, bool?schedule, bool?silent)
        {
            Delegate?.HideStickers();

            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            var restricted = await VerifyRightsAsync(chat, x => x.CanSendOtherMessages, Strings.Resources.GlobalAttachGifRestricted, Strings.Resources.AttachGifRestrictedForever, Strings.Resources.AttachGifRestricted);

            if (restricted)
            {
                return;
            }

            var options = await PickSendMessageOptionsAsync(schedule, silent);

            if (options == null)
            {
                return;
            }

            var reply = GetReply(true);
            var input = new InputMessageAnimation(new InputFileId(animation.AnimationValue.Id), animation.Thumbnail?.ToInput(), new int[0], animation.Duration, animation.Width, animation.Height, null);

            await SendMessageAsync(reply, input, options);
        }
        public async Task SendVideoAsync(StorageFile file, string caption, bool animated, bool asFile, int?ttl = null, MediaEncodingProfile profile = null, VideoTransformEffectDefinition transform = null)
        {
            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 (asFile)
            {
                var reply = GetReply(true);
                var input = new InputMessageDocument(generated, thumbnail, GetFormattedText(caption));

                await SendMessageAsync(reply, input);
            }
            else
            {
                if (profile != null && profile.Audio == null)
                {
                    var reply = GetReply(true);
                    var input = new InputMessageAnimation(generated, thumbnail, (int)videoProps.Duration.TotalSeconds, videoWidth, videoHeight, GetFormattedText(caption));

                    await SendMessageAsync(reply, input);
                }
                else
                {
                    var reply = GetReply(true);
                    var input = new InputMessageVideo(generated, thumbnail, new int[0], (int)videoProps.Duration.TotalSeconds, videoWidth, videoHeight, true, GetFormattedText(caption), ttl ?? 0);

                    await SendMessageAsync(reply, input);
                }
            }
        }
示例#3
0
        //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)));
        }