pub trait MessageLike {
fn sender_user_id(&self) -> Option<i64>;
fn chat_id(&self) -> i64;
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StateKey {
pub user_id: Option<i64>,
pub chat_id: i64,
}
impl StateKey {
pub fn from_message(msg: &impl MessageLike, strategy: StateKeyStrategy) -> Self {
match strategy {
StateKeyStrategy::PerUserPerChat => Self {
user_id: msg.sender_user_id(),
chat_id: msg.chat_id(),
},
StateKeyStrategy::PerUser => Self {
user_id: msg.sender_user_id(),
chat_id: 0,
},
StateKeyStrategy::PerChat => Self {
user_id: None,
chat_id: msg.chat_id(),
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StateKeyStrategy {
#[default]
PerUserPerChat,
PerUser,
PerChat,
}