mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Stop using Option<bool>
in ReplyMarkup
This commit is contained in:
parent
9876587d93
commit
2a8f550b66
4 changed files with 49 additions and 30 deletions
|
@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
[pr851]: https://github.com/teloxide/teloxide/pull/851
|
[pr851]: https://github.com/teloxide/teloxide/pull/851
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Types of `Option<bool>` fields of `KeyboardMarkup`, `KeyboardRemove` and `ForceReply` to `bool` ([#853][pr853])
|
||||||
|
|
||||||
|
[pr852]: https://github.com/teloxide/teloxide/pull/853
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- `Update::user`, use `Update::from` instead ([#850][pr850])
|
- `Update::user`, use `Update::from` instead ([#850][pr850])
|
||||||
|
|
|
@ -29,13 +29,14 @@ pub struct ForceReply {
|
||||||
/// (has reply_to_message_id), sender of the original message.
|
/// (has reply_to_message_id), sender of the original message.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
pub selective: Option<bool>,
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForceReply {
|
impl ForceReply {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self { force_reply: True, input_field_placeholder: None, selective: None }
|
Self { force_reply: True, input_field_placeholder: None, selective: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
|
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
|
||||||
|
@ -46,9 +47,12 @@ impl ForceReply {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets [`selective`] to `true`.
|
||||||
|
///
|
||||||
|
/// [`selective`]: ForceReply::selective
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn selective(mut self, val: bool) -> Self {
|
pub const fn selective(mut self) -> Self {
|
||||||
self.selective = Some(val);
|
self.selective = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// FIXME: rename module (s/reply_//)
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::KeyboardButton;
|
use crate::types::KeyboardButton;
|
||||||
|
@ -11,7 +12,6 @@ use crate::types::KeyboardButton;
|
||||||
/// [Introduction to bots]: https://core.telegram.org/bots#keyboards
|
/// [Introduction to bots]: https://core.telegram.org/bots#keyboards
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Default)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Default)]
|
||||||
// FIXME: unoption bools?
|
|
||||||
pub struct KeyboardMarkup {
|
pub struct KeyboardMarkup {
|
||||||
/// Array of button rows, each represented by an Array of
|
/// Array of button rows, each represented by an Array of
|
||||||
/// [`KeyboardButton`] objects
|
/// [`KeyboardButton`] objects
|
||||||
|
@ -29,14 +29,16 @@ pub struct KeyboardMarkup {
|
||||||
/// (e.g., make the keyboard smaller if there are just two rows of
|
/// (e.g., make the keyboard smaller if there are just two rows of
|
||||||
/// buttons). Defaults to `false`, in which case the custom keyboard is
|
/// buttons). Defaults to `false`, in which case the custom keyboard is
|
||||||
/// always of the same height as the app's standard keyboard.
|
/// always of the same height as the app's standard keyboard.
|
||||||
pub resize_keyboard: Option<bool>,
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
pub resize_keyboard: bool,
|
||||||
|
|
||||||
/// Requests clients to hide the keyboard as soon as it's been used. The
|
/// Requests clients to hide the keyboard as soon as it's been used. The
|
||||||
/// keyboard will still be available, but clients will automatically
|
/// keyboard will still be available, but clients will automatically
|
||||||
/// display the usual letter-keyboard in the chat – the user can press a
|
/// display the usual letter-keyboard in the chat – the user can press a
|
||||||
/// special button in the input field to see the custom keyboard again.
|
/// special button in the input field to see the custom keyboard again.
|
||||||
/// Defaults to `false`.
|
/// Defaults to `false`.
|
||||||
pub one_time_keyboard: Option<bool>,
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
pub one_time_keyboard: bool,
|
||||||
|
|
||||||
/// The placeholder to be shown in the input field when the keyboard is
|
/// The placeholder to be shown in the input field when the keyboard is
|
||||||
/// active; 1-64 characters.
|
/// active; 1-64 characters.
|
||||||
|
@ -52,10 +54,12 @@ pub struct KeyboardMarkup {
|
||||||
/// in the group don’t see the keyboard.
|
/// in the group don’t see the keyboard.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
pub selective: Option<bool>,
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyboardMarkup {
|
impl KeyboardMarkup {
|
||||||
|
// FIXME: Re-think the interface of building keyboard markups
|
||||||
pub fn new<K>(keyboard: K) -> Self
|
pub fn new<K>(keyboard: K) -> Self
|
||||||
where
|
where
|
||||||
K: IntoIterator,
|
K: IntoIterator,
|
||||||
|
@ -64,10 +68,10 @@ impl KeyboardMarkup {
|
||||||
Self {
|
Self {
|
||||||
keyboard: keyboard.into_iter().map(<_>::into_iter).map(<_>::collect).collect(),
|
keyboard: keyboard.into_iter().map(<_>::into_iter).map(<_>::collect).collect(),
|
||||||
is_persistent: false,
|
is_persistent: false,
|
||||||
resize_keyboard: None,
|
resize_keyboard: false,
|
||||||
one_time_keyboard: None,
|
one_time_keyboard: false,
|
||||||
input_field_placeholder: None,
|
input_field_placeholder: None,
|
||||||
selective: None,
|
selective: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,22 +100,23 @@ impl KeyboardMarkup {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize_keyboard<T>(mut self, val: T) -> Self
|
/// Sets [`resize_keyboard`] to `true`.
|
||||||
where
|
///
|
||||||
T: Into<Option<bool>>,
|
/// [`resize_keyboard`]: KeyboardMarkup::resize_keyboard
|
||||||
{
|
pub fn resize_keyboard(mut self) -> Self {
|
||||||
self.resize_keyboard = val.into();
|
self.resize_keyboard = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn one_time_keyboard<T>(mut self, val: T) -> Self
|
/// Sets [`one_time_keyboard`] to `true`.
|
||||||
where
|
///
|
||||||
T: Into<Option<bool>>,
|
/// [`one_time_keyboard`]: KeyboardMarkup::one_time_keyboard
|
||||||
{
|
pub fn one_time_keyboard(mut self) -> Self {
|
||||||
self.one_time_keyboard = val.into();
|
self.one_time_keyboard = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: document + remove Option from signature.
|
||||||
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
|
pub fn input_field_placeholder<T>(mut self, val: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Option<String>>,
|
T: Into<Option<String>>,
|
||||||
|
@ -120,11 +125,11 @@ impl KeyboardMarkup {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selective<T>(mut self, val: T) -> Self
|
/// Sets [`selective`] to `true`.
|
||||||
where
|
///
|
||||||
T: Into<Option<bool>>,
|
/// [`selective`]: KeyboardMarkup::selective
|
||||||
{
|
pub fn selective<T>(mut self) -> Self {
|
||||||
self.selective = val.into();
|
self.selective = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,18 +34,22 @@ pub struct KeyboardRemove {
|
||||||
/// showing the keyboard with poll options to users who haven't voted yet.
|
/// showing the keyboard with poll options to users who haven't voted yet.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
pub selective: Option<bool>,
|
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||||
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyboardRemove {
|
impl KeyboardRemove {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self { remove_keyboard: True, selective: None }
|
Self { remove_keyboard: True, selective: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets [`selective`] to `true`.
|
||||||
|
///
|
||||||
|
/// [`selective`]: KeyboardRemove::selective
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn selective(mut self, val: bool) -> Self {
|
pub const fn selective(mut self) -> Self {
|
||||||
self.selective = Some(val);
|
self.selective = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue