예제 #1
0
        private void UpdateMarkup(TLReplyKeyboardBase replyKeyboardBase)
        {
            ButtonRows.Children.Clear();

            var replyMarkup = replyKeyboardBase as TLReplyKeyboardMarkup;

            if (replyMarkup == null)
            {
                Visibility = Visibility.Collapsed;
                return;
            }

            var height           = EmojiControl.PortraitOrientationHeight;
            var buttonRowsHeight = height - ButtonRows.Margin.Top - ButtonRows.Margin.Bottom;
            var buttonMargin     = 3.0;
            var buttonHeight     = 78.0; // without margin

            if (!replyMarkup.IsResizable &&
                buttonHeight * replyMarkup.Rows.Count < buttonRowsHeight)
            {
                buttonHeight = buttonRowsHeight / replyMarkup.Rows.Count - 2 * buttonMargin;
            }

            foreach (var buttonRow in replyMarkup.Rows)
            {
                var grid = new Grid();

                for (var i = 0; i < buttonRow.Buttons.Count; i++)
                {
                    var button = CreateButton(buttonRow.Buttons[i], buttonHeight, buttonMargin);
                    Grid.SetColumn(button, i);

                    grid.ColumnDefinitions.Add(new ColumnDefinition());
                    grid.Children.Add(button);
                }

                ButtonRows.Children.Add(grid);
            }

            LayoutRoot.MaxHeight = height;
            if (replyMarkup.IsResizable)
            {
                LayoutRoot.ClearValue(HeightProperty);
            }
            else
            {
                LayoutRoot.Height = height;
            }
            Visibility = Visibility.Visible;
            ScrollViewer.VerticalScrollBarVisibility = buttonHeight * replyMarkup.Rows.Count > buttonRowsHeight
                ? ScrollBarVisibility.Auto
                : ScrollBarVisibility.Disabled;
        }
예제 #2
0
        public override TLObject FromStream(Stream input)
        {
            Flags = GetObject <TLInt>(input);
            Peer  = GetObject <TLInputPeerBase>(input);
            if (IsSet(Flags, (int)SendFlags.Reply))
            {
                ReplyToMsgId = GetObject <TLInt>(input);
            }
            Media    = GetObject <TLInputMediaBase>(input);
            RandomId = GetObject <TLLong>(input);
            if (IsSet(Flags, (int)SendFlags.ReplyMarkup))
            {
                ReplyMarkup = GetObject <TLReplyKeyboardBase>(input);
            }

            return(this);
        }
        private void SetReplyMarkup(TLMessage31 message)
        {
            if (Reply != null && message != null)
            {
                return;
            }

            if (message != null &&
                message.ReplyMarkup != null)
            {
                var replyMarkup = message.ReplyMarkup as TLReplyKeyboardMarkup;
                if (replyMarkup != null &&
                    replyMarkup.IsPersonal &&
                    !message.IsMention)
                {
                    return;
                }

                var keyboardHide = message.ReplyMarkup as TLReplyKeyboardHide;
                if (keyboardHide != null)
                {
                    if (_replyMarkupMessage != null &&
                        _replyMarkupMessage.FromId.Value != message.FromId.Value)
                    {
                        return;
                    }
                }

                var forceReply = message.ReplyMarkup as TLReplyKeyboardForceReply;
                if (forceReply != null &&
                    !forceReply.HasResponse)
                {
                    _replyMarkupMessage = null;
                    ReplyMarkup         = null;
                    Reply = message;

                    return;
                }
            }


            _replyMarkupMessage = message;
            ReplyMarkup         = message != null? message.ReplyMarkup : null;
        }
        private void UpdateMarkup(TLReplyKeyboardBase replyKeyboardBase)
        {
            if (replyKeyboardBase == null)
            {
                Visibility = Visibility.Collapsed;
                return;
            }

#if DEBUG
            _debug.Text = replyKeyboardBase.ToString();
#endif
            var inlineMarkup = replyKeyboardBase as TLReplyInlineMarkup;
            if (Inline && inlineMarkup == null)
            {
                Visibility = Visibility.Collapsed;
                return;
            }

            var replyMarkup = replyKeyboardBase as TLReplyKeyboardMarkup;
            if (!Inline && replyMarkup == null)
            {
                Visibility = Visibility.Collapsed;
                return;
            }

            var replyKeyboardRows = replyKeyboardBase as IReplyKeyboardRows;
            if (replyKeyboardRows == null)
            {
                Visibility = Visibility.Collapsed;
                return;
            }

            if (Inline)
            {
                var inlineButtonMargin = 3.0;
                var inlineButtonHeight = 48.0;    // without margin

                var buttonRows = new StackPanel {
                    Margin = new Thickness(-3.0)
                };
                foreach (var buttonRow in replyKeyboardRows.Rows)
                {
                    var grid = new Grid();

                    for (var i = 0; i < buttonRow.Buttons.Count; i++)
                    {
                        var button = CreateButton(buttonRow.Buttons[i], inlineButtonHeight, new Thickness(inlineButtonMargin), buttonRow.Buttons.Count < 4 ? 6.0 : 0.0, GetMaxTextLength(buttonRow.Buttons.Count));
                        Grid.SetColumn(button, i);

                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.Children.Add(button);
                    }

                    buttonRows.Children.Add(grid);
                }

                Visibility            = Visibility.Visible;
                LayoutRoot.Background = new SolidColorBrush(Colors.Transparent);
                LayoutRoot.Children.Clear();
                LayoutRoot.Children.Add(buttonRows);
#if DEBUG
                LayoutRoot.Children.Add(_debug);
#endif
            }
            else
            {
                var buttonRows = new StackPanel {
                    Margin = new Thickness(3.0, 3.0, 3.0, 0.0)
                };
                var height           = EmojiControl.PortraitOrientationHeight;
                var buttonRowsHeight = height - buttonRows.Margin.Top - buttonRows.Margin.Bottom;
                var buttonMargin     = 3.0;
                var buttonHeight     = 78.0; // without margin
                if (!replyMarkup.IsResizable &&
                    buttonHeight * replyMarkup.Rows.Count < buttonRowsHeight)
                {
                    buttonHeight = buttonRowsHeight / replyKeyboardRows.Rows.Count - 2 * buttonMargin;
                }

                foreach (var buttonRow in replyKeyboardRows.Rows)
                {
                    var grid = new Grid();

                    for (var i = 0; i < buttonRow.Buttons.Count; i++)
                    {
                        var button = CreateButton(buttonRow.Buttons[i], buttonHeight, new Thickness(buttonMargin), buttonRow.Buttons.Count < 4? 6.0 : 0.0, GetMaxTextLength(buttonRow.Buttons.Count));
                        Grid.SetColumn(button, i);

                        grid.ColumnDefinitions.Add(new ColumnDefinition());
                        grid.Children.Add(button);
                    }

                    buttonRows.Children.Add(grid);
                }

                LayoutRoot.MaxHeight = height;
                if (replyMarkup.IsResizable)
                {
                    LayoutRoot.ClearValue(HeightProperty);
                }
                else
                {
                    LayoutRoot.Height = height;
                }
                Visibility = Visibility.Visible;
                var scrollViewer = new ScrollViewer();
                scrollViewer.VerticalScrollBarVisibility = buttonHeight * replyKeyboardRows.Rows.Count > buttonRowsHeight
                    ? ScrollBarVisibility.Auto
                    : ScrollBarVisibility.Disabled;

                scrollViewer.Content = buttonRows;
                LayoutRoot.Children.Clear();
                LayoutRoot.Children.Add(scrollViewer);
#if DEBUG
                LayoutRoot.Children.Add(_debug);
#endif
            }
        }
예제 #5
0
        public void EditMessageAsync(TLInputPeerBase peer, TLInt id, TLString message, TLVector <TLMessageEntityBase> entities, TLInputMediaBase media, TLReplyKeyboardBase replyMarkup, bool noWebPage, bool stopGeoLive, TLInputGeoPointBase geoPoint, Action <TLUpdatesBase> callback, Action <TLRPCError> faultCallback = null)
        {
            var obj = new TLEditMessage {
                Flags = new TLInt(0), Peer = peer, Id = id, Message = message, NoWebPage = noWebPage, Entities = entities, Media = media, ReplyMarkup = replyMarkup, StopGeoLive = stopGeoLive, GeoPoint = geoPoint
            };

            const string caption = "messages.editMessage";

            SendInformativeMessage <TLUpdatesBase>(caption, obj,
                                                   result =>
            {
                var multiPts = result as IMultiPts;
                if (multiPts != null)
                {
                    _updatesService.SetState(multiPts, caption);
                }
                else
                {
                    ProcessUpdates(result, null, true);
                }

                callback.SafeInvoke(result);
            },
                                                   faultCallback);
        }