Private
Public Access
1
0

cargo fmt

This commit is contained in:
2025-06-06 16:39:31 -07:00
parent 8cd72d9417
commit 1d3b2f25ba
44 changed files with 758 additions and 505 deletions

View File

@@ -22,7 +22,7 @@ impl Default for InMemoryAuthenticationStore {
impl InMemoryAuthenticationStore {
pub fn new(credentials: Option<Credentials>) -> Self {
Self {
Self {
credentials,
token: None,
}

View File

@@ -1,6 +1,6 @@
use async_trait::async_trait;
use crate::model::update::UpdateItem;
use crate::model::event::Event;
use crate::model::update::UpdateItem;
use async_trait::async_trait;
use futures_util::stream::Stream;
#[async_trait]
@@ -8,10 +8,10 @@ pub trait EventSocket {
type Error;
type EventStream: Stream<Item = Result<Event, Self::Error>>;
type UpdateStream: Stream<Item = Result<Vec<UpdateItem>, Self::Error>>;
/// Modern event pipeline
/// Modern event pipeline
async fn events(self) -> Self::EventStream;
/// Raw update items from the v1 API.
/// Raw update items from the v1 API.
async fn raw_updates(self) -> Self::UpdateStream;
}
}

View File

@@ -4,4 +4,4 @@ pub mod model;
pub use self::api::APIInterface;
#[cfg(test)]
pub mod tests;
pub mod tests;

View File

@@ -41,7 +41,7 @@ impl Identifiable for Conversation {
fn id(&self) -> &Self::ID {
&self.guid
}
}
}
#[derive(Default)]
@@ -85,7 +85,10 @@ impl ConversationBuilder {
self
}
pub fn display_name<T>(mut self, display_name: T) -> Self where T: Into<String> {
pub fn display_name<T>(mut self, display_name: T) -> Self
where
T: Into<String>,
{
self.display_name = Some(display_name.into());
self
}

View File

@@ -15,13 +15,25 @@ pub enum EventData {
impl From<UpdateItem> for Event {
fn from(update: UpdateItem) -> Self {
match update {
UpdateItem { conversation: Some(conversation), message: None, .. }
=> Event { data: EventData::ConversationChanged(conversation), update_seq: update.seq },
UpdateItem {
conversation: Some(conversation),
message: None,
..
} => Event {
data: EventData::ConversationChanged(conversation),
update_seq: update.seq,
},
UpdateItem {
conversation: Some(conversation),
message: Some(message),
..
} => Event {
data: EventData::MessageReceived(conversation, message),
update_seq: update.seq,
},
UpdateItem { conversation: Some(conversation), message: Some(message), .. }
=> Event { data: EventData::MessageReceived(conversation, message), update_seq: update.seq },
_ => panic!("Invalid update item: {:?}", update),
}
}
}
}

View File

@@ -37,14 +37,14 @@ where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
#[derive(Deserialize)]
#[serde(untagged)]
enum ExpValue {
String(String),
Number(i64),
}
match ExpValue::deserialize(deserializer)? {
ExpValue::String(s) => s.parse().map_err(D::Error::custom),
ExpValue::Number(n) => Ok(n),
@@ -82,7 +82,9 @@ impl JwtToken {
let payload: JwtPayload = serde_json::from_slice(&payload)?;
// Parse jwt expiration date
let timestamp = DateTime::from_timestamp(payload.exp, 0).unwrap().naive_utc();
let timestamp = DateTime::from_timestamp(payload.exp, 0)
.unwrap()
.naive_utc();
let expiration_date = DateTime::from_naive_utc_and_offset(timestamp, Utc);
Ok(JwtToken {
@@ -99,7 +101,7 @@ impl JwtToken {
// try both encodings here.
log::debug!("Attempting to decode JWT token: {}", token);
let result = Self::decode_token_using_engine(token, general_purpose::STANDARD).or(
Self::decode_token_using_engine(token, general_purpose::URL_SAFE_NO_PAD),
);

View File

@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use time::OffsetDateTime;
use time::OffsetDateTime;
use uuid::Uuid;
use super::Identifiable;
@@ -12,7 +12,7 @@ pub struct AttributionInfo {
/// Picture width
#[serde(rename = "pgensh")]
pub width: Option<u32>,
/// Picture height
#[serde(rename = "pgensw")]
pub height: Option<u32>,
@@ -26,7 +26,7 @@ pub struct AttachmentMetadata {
#[derive(Debug, Clone, Deserialize)]
pub struct Message {
pub guid: String,
pub guid: String,
#[serde(rename = "text")]
pub text: String,
@@ -62,9 +62,9 @@ impl Identifiable for Message {
#[derive(Default)]
pub struct MessageBuilder {
guid: Option<String>,
text: Option<String>,
sender: Option<String>,
guid: Option<String>,
text: Option<String>,
sender: Option<String>,
date: Option<OffsetDateTime>,
file_transfer_guids: Option<Vec<String>>,
attachment_metadata: Option<HashMap<String, AttachmentMetadata>>,
@@ -77,17 +77,17 @@ impl MessageBuilder {
pub fn guid(mut self, guid: String) -> Self {
self.guid = Some(guid);
self
self
}
pub fn text(mut self, text: String) -> Self {
self.text = Some(text);
self
self
}
pub fn sender(mut self, sender: String) -> Self {
self.sender = Some(sender);
self
self
}
pub fn date(mut self, date: OffsetDateTime) -> Self {
@@ -100,7 +100,10 @@ impl MessageBuilder {
self
}
pub fn attachment_metadata(mut self, attachment_metadata: HashMap<String, AttachmentMetadata>) -> Self {
pub fn attachment_metadata(
mut self,
attachment_metadata: HashMap<String, AttachmentMetadata>,
) -> Self {
self.attachment_metadata = Some(attachment_metadata);
self
}
@@ -116,4 +119,3 @@ impl MessageBuilder {
}
}
}

View File

@@ -23,4 +23,4 @@ pub use jwt::JwtToken;
pub trait Identifiable {
type ID;
fn id(&self) -> &Self::ID;
}
}

View File

@@ -1,6 +1,6 @@
use serde::Serialize;
use super::conversation::ConversationID;
use chrono::NaiveDateTime;
use serde::Serialize;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize)]
@@ -61,12 +61,12 @@ impl OutgoingMessageBuilder {
}
pub fn build(self) -> OutgoingMessage {
OutgoingMessage {
OutgoingMessage {
guid: self.guid.unwrap_or_else(|| Uuid::new_v4()),
text: self.text.unwrap(),
conversation_id: self.conversation_id.unwrap(),
text: self.text.unwrap(),
conversation_id: self.conversation_id.unwrap(),
file_transfer_guids: self.file_transfer_guids.unwrap_or_default(),
date: chrono::Utc::now().naive_utc(),
}
}
}
}

View File

@@ -1,6 +1,6 @@
use serde::Deserialize;
use super::conversation::Conversation;
use super::message::Message;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct UpdateItem {
@@ -16,6 +16,10 @@ pub struct UpdateItem {
impl Default for UpdateItem {
fn default() -> Self {
Self { seq: 0, conversation: None, message: None }
Self {
seq: 0,
conversation: None,
message: None,
}
}
}
}

View File

@@ -6,7 +6,7 @@ pub mod api_interface {
use crate::model::Conversation;
use super::*;
#[tokio::test]
async fn test_version() {
let mut client = TestClient::new();
@@ -28,4 +28,4 @@ pub mod api_interface {
assert_eq!(conversations.len(), 1);
assert_eq!(conversations[0].display_name, test_convo.display_name);
}
}
}

View File

@@ -14,9 +14,9 @@ use crate::{
},
};
use bytes::Bytes;
use futures_util::stream::BoxStream;
use futures_util::StreamExt;
use bytes::Bytes;
pub struct TestClient {
pub version: &'static str,
@@ -120,7 +120,11 @@ impl APIInterface for TestClient {
Ok(TestEventSocket::new())
}
async fn fetch_attachment_data(&mut self, guid: &String, preview: bool) -> Result<Self::ResponseStream, Self::Error> {
async fn fetch_attachment_data(
&mut self,
guid: &String,
preview: bool,
) -> Result<Self::ResponseStream, Self::Error> {
Ok(futures_util::stream::iter(vec![Ok(Bytes::from_static(b"test"))]).boxed())
}
}