Update teloxide-core 0.4.5 -> 0.5.0

This commit is contained in:
Maybe Waffle 2022-04-13 15:56:54 +04:00
parent ba5dc486ce
commit 2aa59d760a
15 changed files with 91 additions and 61 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Updated `teloxide-core` from version `0.4.5` to version [`0.5.0`](https://github.com/teloxide/teloxide-core/releases/tag/v0.5.0) [**BC**]
- Rename `dispatching2` => `dispatching` [**BC**]. - Rename `dispatching2` => `dispatching` [**BC**].
- Rename `prelude2` => `prelude` [**BC**]. - Rename `prelude2` => `prelude` [**BC**].
- Move `update_listeners`, `stop_token`, `IdleShutdownError`, and `ShutdownToken` from the old `dispatching` to the new `dispatching` (previously `dispatching2`). - Move `update_listeners`, `stop_token`, `IdleShutdownError`, and `ShutdownToken` from the old `dispatching` to the new `dispatching` (previously `dispatching2`).

View file

@ -56,7 +56,7 @@ full = [
] ]
[dependencies] [dependencies]
teloxide-core = { version = "0.4", default-features = false } teloxide-core = { version = "0.5", default-features = false }
teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros.git", rev = "dfba097c7146ba6244a36001d703e04b771baa05", optional = true } teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros.git", rev = "dfba097c7146ba6244a36001d703e04b771baa05", optional = true }
serde_json = "1.0" serde_json = "1.0"

View file

@ -5,7 +5,7 @@ use rand::Rng;
use teloxide::{ use teloxide::{
prelude::*, prelude::*,
types::{Dice, Update}, types::{Dice, Update, UserId},
utils::command::BotCommands, utils::command::BotCommands,
}; };
@ -17,7 +17,7 @@ async fn main() {
let bot = Bot::from_env().auto_send(); let bot = Bot::from_env().auto_send();
let parameters = ConfigParameters { let parameters = ConfigParameters {
bot_maintainer: 268486177, // Paste your ID to run this bot. bot_maintainer: UserId(0), // Paste your ID to run this bot.
maintainer_username: None, maintainer_username: None,
}; };
@ -95,7 +95,7 @@ async fn main() {
#[derive(Clone)] #[derive(Clone)]
struct ConfigParameters { struct ConfigParameters {
bot_maintainer: i64, bot_maintainer: UserId,
maintainer_username: Option<String>, maintainer_username: Option<String>,
} }

View file

@ -1,20 +1,20 @@
use crate::types::CallbackQuery; use crate::types::CallbackQuery;
use teloxide_core::types::Message; use teloxide_core::types::{ChatId, Message};
/// Something that may has a chat ID. /// Something that may has a chat ID.
pub trait GetChatId { pub trait GetChatId {
#[must_use] #[must_use]
fn chat_id(&self) -> Option<i64>; fn chat_id(&self) -> Option<ChatId>;
} }
impl GetChatId for Message { impl GetChatId for Message {
fn chat_id(&self) -> Option<i64> { fn chat_id(&self) -> Option<ChatId> {
Some(self.chat.id) Some(self.chat.id)
} }
} }
impl GetChatId for CallbackQuery { impl GetChatId for CallbackQuery {
fn chat_id(&self) -> Option<i64> { fn chat_id(&self) -> Option<ChatId> {
self.message.as_ref().map(|mes| mes.chat.id) self.message.as_ref().map(|mes| mes.chat.id)
} }
} }

View file

@ -85,6 +85,7 @@ pub use crate::dispatching::dialogue::{SqliteStorage, SqliteStorageError};
pub use get_chat_id::GetChatId; pub use get_chat_id::GetChatId;
pub use storage::*; pub use storage::*;
use teloxide_core::types::ChatId;
use std::{marker::PhantomData, sync::Arc}; use std::{marker::PhantomData, sync::Arc};
@ -98,7 +99,7 @@ where
S: ?Sized, S: ?Sized,
{ {
storage: Arc<S>, storage: Arc<S>,
chat_id: i64, chat_id: ChatId,
_phantom: PhantomData<D>, _phantom: PhantomData<D>,
} }
@ -121,13 +122,13 @@ where
/// Constructs a new dialogue with `storage` (where dialogues are stored) /// Constructs a new dialogue with `storage` (where dialogues are stored)
/// and `chat_id` of a current dialogue. /// and `chat_id` of a current dialogue.
#[must_use] #[must_use]
pub fn new(storage: Arc<S>, chat_id: i64) -> Self { pub fn new(storage: Arc<S>, chat_id: ChatId) -> Self {
Self { storage, chat_id, _phantom: PhantomData } Self { storage, chat_id, _phantom: PhantomData }
} }
/// Returns a chat ID associated with this dialogue. /// Returns a chat ID associated with this dialogue.
#[must_use] #[must_use]
pub fn chat_id(&self) -> i64 { pub fn chat_id(&self) -> ChatId {
self.chat_id self.chat_id
} }

View file

@ -1,6 +1,7 @@
use super::Storage; use super::Storage;
use futures::future::BoxFuture; use futures::future::BoxFuture;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use teloxide_core::types::ChatId;
use thiserror::Error; use thiserror::Error;
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -20,7 +21,7 @@ pub enum InMemStorageError {
/// [`super::SqliteStorage`] or implement your own. /// [`super::SqliteStorage`] or implement your own.
#[derive(Debug)] #[derive(Debug)]
pub struct InMemStorage<D> { pub struct InMemStorage<D> {
map: Mutex<HashMap<i64, D>>, map: Mutex<HashMap<ChatId, D>>,
} }
impl<S> InMemStorage<S> { impl<S> InMemStorage<S> {
@ -37,7 +38,10 @@ where
{ {
type Error = InMemStorageError; type Error = InMemStorageError;
fn remove_dialogue(self: Arc<Self>, chat_id: i64) -> BoxFuture<'static, Result<(), Self::Error>> fn remove_dialogue(
self: Arc<Self>,
chat_id: ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>>
where where
D: Send + 'static, D: Send + 'static,
{ {
@ -52,7 +56,7 @@ where
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> ) -> BoxFuture<'static, Result<(), Self::Error>>
where where
@ -66,7 +70,7 @@ where
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> { ) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
Box::pin(async move { Ok(self.map.lock().await.get(&chat_id).map(ToOwned::to_owned)) }) Box::pin(async move { Ok(self.map.lock().await.get(&chat_id).map(ToOwned::to_owned)) })
} }

View file

@ -10,6 +10,7 @@ mod redis_storage;
mod sqlite_storage; mod sqlite_storage;
use futures::future::BoxFuture; use futures::future::BoxFuture;
use teloxide_core::types::ChatId;
pub use self::{ pub use self::{
in_mem_storage::{InMemStorage, InMemStorageError}, in_mem_storage::{InMemStorage, InMemStorageError},
@ -55,7 +56,7 @@ pub trait Storage<D> {
#[must_use = "Futures are lazy and do nothing unless polled with .await"] #[must_use = "Futures are lazy and do nothing unless polled with .await"]
fn remove_dialogue( fn remove_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>> ) -> BoxFuture<'static, Result<(), Self::Error>>
where where
D: Send + 'static; D: Send + 'static;
@ -64,7 +65,7 @@ pub trait Storage<D> {
#[must_use = "Futures are lazy and do nothing unless polled with .await"] #[must_use = "Futures are lazy and do nothing unless polled with .await"]
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> ) -> BoxFuture<'static, Result<(), Self::Error>>
where where
@ -74,7 +75,7 @@ pub trait Storage<D> {
#[must_use = "Futures are lazy and do nothing unless polled with .await"] #[must_use = "Futures are lazy and do nothing unless polled with .await"]
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>>; ) -> BoxFuture<'static, Result<Option<D>, Self::Error>>;
/// Erases [`Self::Error`] to [`std::error::Error`]. /// Erases [`Self::Error`] to [`std::error::Error`].
@ -97,7 +98,10 @@ where
{ {
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
fn remove_dialogue(self: Arc<Self>, chat_id: i64) -> BoxFuture<'static, Result<(), Self::Error>> fn remove_dialogue(
self: Arc<Self>,
chat_id: ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>>
where where
D: Send + 'static, D: Send + 'static,
{ {
@ -108,7 +112,7 @@ where
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> ) -> BoxFuture<'static, Result<(), Self::Error>>
where where
@ -121,7 +125,7 @@ where
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> { ) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
Box::pin( Box::pin(
async move { Arc::clone(&self.0).get_dialogue(chat_id).await.map_err(|e| e.into()) }, async move { Arc::clone(&self.0).get_dialogue(chat_id).await.map_err(|e| e.into()) },
@ -135,7 +139,7 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_erased() { async fn test_erased() {
let chat_id = 123; let chat_id = ChatId(123);
let erased = InMemStorage::new().erase(); let erased = InMemStorage::new().erase();
Arc::clone(&erased).update_dialogue(chat_id, 1).await.unwrap(); Arc::clone(&erased).update_dialogue(chat_id, 1).await.unwrap();

View file

@ -8,6 +8,7 @@ use std::{
ops::DerefMut, ops::DerefMut,
sync::Arc, sync::Arc,
}; };
use teloxide_core::types::ChatId;
use thiserror::Error; use thiserror::Error;
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -56,7 +57,7 @@ where
fn remove_dialogue( fn remove_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, ChatId(chat_id): ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>> { ) -> BoxFuture<'static, Result<(), Self::Error>> {
Box::pin(async move { Box::pin(async move {
let deleted_rows_count = redis::pipe() let deleted_rows_count = redis::pipe()
@ -82,7 +83,7 @@ where
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, ChatId(chat_id): ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> { ) -> BoxFuture<'static, Result<(), Self::Error>> {
Box::pin(async move { Box::pin(async move {
@ -95,7 +96,7 @@ where
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, ChatId(chat_id): ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> { ) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
Box::pin(async move { Box::pin(async move {
self.conn self.conn

View file

@ -8,6 +8,7 @@ use std::{
str, str,
sync::Arc, sync::Arc,
}; };
use teloxide_core::types::ChatId;
use thiserror::Error; use thiserror::Error;
/// A persistent dialogue storage based on [SQLite](https://www.sqlite.org/). /// A persistent dialogue storage based on [SQLite](https://www.sqlite.org/).
@ -66,7 +67,7 @@ where
/// Returns [`sqlx::Error::RowNotFound`] if a dialogue does not exist. /// Returns [`sqlx::Error::RowNotFound`] if a dialogue does not exist.
fn remove_dialogue( fn remove_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, ChatId(chat_id): ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>> { ) -> BoxFuture<'static, Result<(), Self::Error>> {
Box::pin(async move { Box::pin(async move {
let deleted_rows_count = let deleted_rows_count =
@ -86,7 +87,7 @@ where
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, ChatId(chat_id): ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> { ) -> BoxFuture<'static, Result<(), Self::Error>> {
Box::pin(async move { Box::pin(async move {
@ -112,7 +113,7 @@ where
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> { ) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
Box::pin(async move { Box::pin(async move {
get_dialogue(&self.pool, chat_id) get_dialogue(&self.pool, chat_id)
@ -123,7 +124,10 @@ where
} }
} }
async fn get_dialogue(pool: &SqlitePool, chat_id: i64) -> Result<Option<Vec<u8>>, sqlx::Error> { async fn get_dialogue(
pool: &SqlitePool,
ChatId(chat_id): ChatId,
) -> Result<Option<Vec<u8>>, sqlx::Error> {
#[derive(sqlx::FromRow)] #[derive(sqlx::FromRow)]
struct DialogueDbRow { struct DialogueDbRow {
dialogue: Vec<u8>, dialogue: Vec<u8>,

View file

@ -5,6 +5,7 @@ use std::{
}; };
use futures::future::BoxFuture; use futures::future::BoxFuture;
use teloxide_core::types::ChatId;
use crate::dispatching::dialogue::Storage; use crate::dispatching::dialogue::Storage;
@ -34,7 +35,10 @@ where
{ {
type Error = <S as Storage<D>>::Error; type Error = <S as Storage<D>>::Error;
fn remove_dialogue(self: Arc<Self>, chat_id: i64) -> BoxFuture<'static, Result<(), Self::Error>> fn remove_dialogue(
self: Arc<Self>,
chat_id: ChatId,
) -> BoxFuture<'static, Result<(), Self::Error>>
where where
D: Send + 'static, D: Send + 'static,
{ {
@ -44,7 +48,7 @@ where
fn update_dialogue( fn update_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
dialogue: D, dialogue: D,
) -> BoxFuture<'static, Result<(), Self::Error>> ) -> BoxFuture<'static, Result<(), Self::Error>>
where where
@ -60,7 +64,7 @@ where
fn get_dialogue( fn get_dialogue(
self: Arc<Self>, self: Arc<Self>,
chat_id: i64, chat_id: ChatId,
) -> BoxFuture<'static, Result<Option<D>, Self::Error>> { ) -> BoxFuture<'static, Result<Option<D>, Self::Error>> {
log::trace!("Requested a dialogue #{}", chat_id); log::trace!("Requested a dialogue #{}", chat_id);
<S as Storage<D>>::get_dialogue(self.inner.clone(), chat_id) <S as Storage<D>>::get_dialogue(self.inner.clone(), chat_id)

View file

@ -16,7 +16,10 @@ use std::{
ops::{ControlFlow, Deref}, ops::{ControlFlow, Deref},
sync::Arc, sync::Arc,
}; };
use teloxide_core::{requests::Request, types::UpdateKind}; use teloxide_core::{
requests::Request,
types::{ChatId, UpdateKind},
};
use tokio::time::timeout; use tokio::time::timeout;
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
@ -102,7 +105,7 @@ pub struct Dispatcher<R, Err> {
default_handler: DefaultHandler, default_handler: DefaultHandler,
// Tokio TX channel parts associated with chat IDs that consume updates sequentially. // Tokio TX channel parts associated with chat IDs that consume updates sequentially.
workers: HashMap<i64, Worker>, workers: HashMap<ChatId, Worker>,
// The default TX part that consume updates concurrently. // The default TX part that consume updates concurrently.
default_worker: Option<Worker>, default_worker: Option<Worker>,

View file

@ -93,6 +93,8 @@ pub fn user_mention_or_link(user: &User) -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use teloxide_core::types::UserId;
use super::*; use super::*;
#[test] #[test]
@ -183,7 +185,7 @@ mod tests {
#[test] #[test]
fn user_mention_link() { fn user_mention_link() {
let user_with_username = User { let user_with_username = User {
id: 0, id: UserId(0),
is_bot: false, is_bot: false,
first_name: "".to_string(), first_name: "".to_string(),
last_name: None, last_name: None,
@ -192,7 +194,7 @@ mod tests {
}; };
assert_eq!(user_mention_or_link(&user_with_username), "@abcd"); assert_eq!(user_mention_or_link(&user_with_username), "@abcd");
let user_without_username = User { let user_without_username = User {
id: 123_456_789, id: UserId(123_456_789),
is_bot: false, is_bot: false,
first_name: "Name".to_string(), first_name: "Name".to_string(),
last_name: None, last_name: None,

View file

@ -131,7 +131,7 @@ pub fn user_mention_or_link(user: &User) -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use teloxide_core::types::User; use teloxide_core::types::{User, UserId};
#[test] #[test]
fn test_bold() { fn test_bold() {
@ -234,7 +234,7 @@ mod tests {
#[test] #[test]
fn user_mention_link() { fn user_mention_link() {
let user_with_username = User { let user_with_username = User {
id: 0, id: UserId(0),
is_bot: false, is_bot: false,
first_name: "".to_string(), first_name: "".to_string(),
last_name: None, last_name: None,
@ -243,7 +243,7 @@ mod tests {
}; };
assert_eq!(user_mention_or_link(&user_with_username), "@abcd"); assert_eq!(user_mention_or_link(&user_with_username), "@abcd");
let user_without_username = User { let user_without_username = User {
id: 123_456_789, id: UserId(123_456_789),
is_bot: false, is_bot: false,
first_name: "Name".to_string(), first_name: "Name".to_string(),
last_name: None, last_name: None,

View file

@ -2,7 +2,10 @@ use std::{
fmt::{Debug, Display}, fmt::{Debug, Display},
sync::Arc, sync::Arc,
}; };
use teloxide::dispatching::dialogue::{RedisStorage, RedisStorageError, Serializer, Storage}; use teloxide::{
dispatching::dialogue::{RedisStorage, RedisStorageError, Serializer, Storage},
types::ChatId,
};
#[tokio::test] #[tokio::test]
#[cfg_attr(not(CI_REDIS), ignore)] #[cfg_attr(not(CI_REDIS), ignore)]
@ -44,9 +47,9 @@ type Dialogue = String;
macro_rules! test_dialogues { macro_rules! test_dialogues {
($storage:expr, $_0:expr, $_1:expr, $_2:expr) => { ($storage:expr, $_0:expr, $_1:expr, $_2:expr) => {
assert_eq!(Arc::clone(&$storage).get_dialogue(1).await.unwrap(), $_0); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(1)).await.unwrap(), $_0);
assert_eq!(Arc::clone(&$storage).get_dialogue(11).await.unwrap(), $_1); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(11)).await.unwrap(), $_1);
assert_eq!(Arc::clone(&$storage).get_dialogue(256).await.unwrap(), $_2); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(256)).await.unwrap(), $_2);
}; };
} }
@ -57,9 +60,9 @@ where
{ {
test_dialogues!(storage, None, None, None); test_dialogues!(storage, None, None, None);
Arc::clone(&storage).update_dialogue(1, "ABC".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(1), "ABC".to_owned()).await.unwrap();
Arc::clone(&storage).update_dialogue(11, "DEF".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(11), "DEF".to_owned()).await.unwrap();
Arc::clone(&storage).update_dialogue(256, "GHI".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(256), "GHI".to_owned()).await.unwrap();
test_dialogues!( test_dialogues!(
storage, storage,
@ -68,15 +71,15 @@ where
Some("GHI".to_owned()) Some("GHI".to_owned())
); );
Arc::clone(&storage).remove_dialogue(1).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(1)).await.unwrap();
Arc::clone(&storage).remove_dialogue(11).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(11)).await.unwrap();
Arc::clone(&storage).remove_dialogue(256).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(256)).await.unwrap();
test_dialogues!(storage, None, None, None); test_dialogues!(storage, None, None, None);
// Check that a try to remove a non-existing dialogue results in an error. // Check that a try to remove a non-existing dialogue results in an error.
assert!(matches!( assert!(matches!(
Arc::clone(&storage).remove_dialogue(1).await.unwrap_err(), Arc::clone(&storage).remove_dialogue(ChatId(1)).await.unwrap_err(),
RedisStorageError::DialogueNotFound RedisStorageError::DialogueNotFound
)); ));
} }

View file

@ -3,7 +3,10 @@ use std::{
fs, fs,
sync::Arc, sync::Arc,
}; };
use teloxide::dispatching::dialogue::{Serializer, SqliteStorage, SqliteStorageError, Storage}; use teloxide::{
dispatching::dialogue::{Serializer, SqliteStorage, SqliteStorageError, Storage},
types::ChatId,
};
#[tokio::test(flavor = "multi_thread")] #[tokio::test(flavor = "multi_thread")]
async fn test_sqlite_json() { async fn test_sqlite_json() {
@ -48,9 +51,9 @@ type Dialogue = String;
macro_rules! test_dialogues { macro_rules! test_dialogues {
($storage:expr, $_0:expr, $_1:expr, $_2:expr) => { ($storage:expr, $_0:expr, $_1:expr, $_2:expr) => {
assert_eq!(Arc::clone(&$storage).get_dialogue(1).await.unwrap(), $_0); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(1)).await.unwrap(), $_0);
assert_eq!(Arc::clone(&$storage).get_dialogue(11).await.unwrap(), $_1); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(11)).await.unwrap(), $_1);
assert_eq!(Arc::clone(&$storage).get_dialogue(256).await.unwrap(), $_2); assert_eq!(Arc::clone(&$storage).get_dialogue(ChatId(256)).await.unwrap(), $_2);
}; };
} }
@ -61,9 +64,9 @@ where
{ {
test_dialogues!(storage, None, None, None); test_dialogues!(storage, None, None, None);
Arc::clone(&storage).update_dialogue(1, "ABC".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(1), "ABC".to_owned()).await.unwrap();
Arc::clone(&storage).update_dialogue(11, "DEF".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(11), "DEF".to_owned()).await.unwrap();
Arc::clone(&storage).update_dialogue(256, "GHI".to_owned()).await.unwrap(); Arc::clone(&storage).update_dialogue(ChatId(256), "GHI".to_owned()).await.unwrap();
test_dialogues!( test_dialogues!(
storage, storage,
@ -72,15 +75,15 @@ where
Some("GHI".to_owned()) Some("GHI".to_owned())
); );
Arc::clone(&storage).remove_dialogue(1).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(1)).await.unwrap();
Arc::clone(&storage).remove_dialogue(11).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(11)).await.unwrap();
Arc::clone(&storage).remove_dialogue(256).await.unwrap(); Arc::clone(&storage).remove_dialogue(ChatId(256)).await.unwrap();
test_dialogues!(storage, None, None, None); test_dialogues!(storage, None, None, None);
// Check that a try to remove a non-existing dialogue results in an error. // Check that a try to remove a non-existing dialogue results in an error.
assert!(matches!( assert!(matches!(
Arc::clone(&storage).remove_dialogue(1).await.unwrap_err(), Arc::clone(&storage).remove_dialogue(ChatId(1)).await.unwrap_err(),
SqliteStorageError::DialogueNotFound SqliteStorageError::DialogueNotFound
)); ));
} }