client: Started working on ability to sync messages after last known message
This commit is contained in:
@@ -10,7 +10,7 @@ use async_trait::async_trait;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
model::{Conversation, ConversationID, JwtToken, Message},
|
||||
model::{Conversation, ConversationID, JwtToken, Message, MessageID},
|
||||
APIInterface
|
||||
};
|
||||
|
||||
@@ -118,8 +118,27 @@ impl<K: TokenStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
async fn get_messages(&mut self, conversation_id: &ConversationID) -> Result<Vec<Message>, Self::Error> {
|
||||
let endpoint = format!("messages?guid={}", conversation_id);
|
||||
async fn get_messages(
|
||||
&mut self,
|
||||
conversation_id: &ConversationID,
|
||||
limit: Option<u32>,
|
||||
before: Option<MessageID>,
|
||||
after: Option<MessageID>,
|
||||
) -> Result<Vec<Message>, Self::Error> {
|
||||
let mut endpoint = format!("messages?guid={}", conversation_id);
|
||||
|
||||
if let Some(limit_val) = limit {
|
||||
endpoint.push_str(&format!("&limit={}", limit_val));
|
||||
}
|
||||
|
||||
if let Some(before_id) = before {
|
||||
endpoint.push_str(&format!("&beforeMessageGUID={}", before_id));
|
||||
}
|
||||
|
||||
if let Some(after_id) = after {
|
||||
endpoint.push_str(&format!("&afterMessageGUID={}", after_id));
|
||||
}
|
||||
|
||||
let messages: Vec<Message> = self.request(&endpoint, Method::GET).await?;
|
||||
Ok(messages)
|
||||
}
|
||||
@@ -288,7 +307,7 @@ mod test {
|
||||
let mut client = local_mock_client();
|
||||
let conversations = client.get_conversations().await.unwrap();
|
||||
let conversation = conversations.first().unwrap();
|
||||
let messages = client.get_messages(&conversation.guid).await.unwrap();
|
||||
let messages = client.get_messages(&conversation.guid, None, None, None).await.unwrap();
|
||||
assert!(!messages.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user