store variants in message info holder

reason: people can go forward with callback and backward and see
defferent message, when they shouldn't
This commit is contained in:
Akulij 2025-05-04 19:10:33 +03:00
parent c371f81008
commit d68c7d688c

View File

@ -103,6 +103,7 @@ pub struct Message {
pub chat_id: i64, pub chat_id: i64,
pub message_id: i64, pub message_id: i64,
pub token: String, pub token: String,
pub variant: Option<String>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -299,6 +300,32 @@ pub trait CallDB {
Ok(()) Ok(())
} }
async fn set_message_literal_variant(
&mut self,
chatid: i64,
messageid: i32,
literal: &str,
variant: &str,
) -> DbResult<()> {
let db = self.get_database().await;
let messages = db.collection::<Message>("messages");
messages
.update_one(
doc! {
"chat_id": chatid,
"message_id": messageid as i64
},
doc! {
"$set": { "token": literal, "variant": variant }
},
)
.upsert(true)
.await?;
Ok(())
}
async fn get_literal(&mut self, literal: &str) -> DbResult<Option<Literal>> { async fn get_literal(&mut self, literal: &str) -> DbResult<Option<Literal>> {
let db = self.get_database().await; let db = self.get_database().await;
let messages = db.collection::<Literal>("literals"); let messages = db.collection::<Literal>("literals");