Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Echo Search (Take Two) #732

Merged
merged 2 commits into from
Jan 30, 2025
Merged

Expand Echo Search (Take Two) #732

merged 2 commits into from
Jan 30, 2025

Conversation

andymandias
Copy link
Collaborator

Increases the search time interval when inserting an echo (message sent by the user received from the server) into message history. Unlike the previous implementation (#714), existing history is properly deserialized.

@andymandias andymandias requested a review from tarkah January 25, 2025 02:45
@andymandias andymandias force-pushed the fix/expanded-echo-search branch from a273fea to ce27d8d Compare January 25, 2025 07:46
Comment on lines 155 to 197
#[derive(Debug, Clone, Copy)]
pub enum Direction {
Sent,
Received,
Received { is_echo: bool },
}

impl Serialize for Direction {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
#[derive(Serialize)]
enum Data {
Sent,
Received,
}

match self {
Direction::Sent => Data::Sent,
Direction::Received { .. } => Data::Received,
}
.serialize(serializer)
}
}

impl<'de> Deserialize<'de> for Direction {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
enum Data {
Sent,
Received,
}

let data = Data::deserialize(deserializer)?;

Ok(match data {
Data::Sent => Direction::Sent,
Data::Received => Direction::Received { is_echo: false },
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that we're discarding this from state, so it's effectively a run-time only variable that's discarded upon restart. There's nothing preventing someone from depending on this field in more complex ways that then breaks due to this.

As much as I'd love to add this to Direction, it doesn't need to be encoded on it. Let's just add a new is_echo field to the message and this is backwards compatible since older clients will just ignore that in the json.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was hoping there would be some serde incantation that would preserve is_echo only when Direction::Received, but I couldn't figure it out. Your rationale for the new field makes sense to me → updated (& tested) the implementation.

@andymandias andymandias force-pushed the fix/expanded-echo-search branch from ce27d8d to 8a029d0 Compare January 30, 2025 04:38
tarkah

This comment was marked as outdated.

Comment on lines 301 to 302
received_at,
server_time,
server_time: Utc::now(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server time is a variable above

@@ -456,6 +472,8 @@ impl<'de> Deserialize<'de> for Message {
Content::Plain("".to_string())
};

let is_echo = is_echo.unwrap_or(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: unwrap or default

@andymandias
Copy link
Collaborator Author

Server time is defined as a variable above

Ah shoot, didn't catch rebase adding that.

Copy link
Member

@tarkah tarkah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@andymandias andymandias merged commit 5cae826 into main Jan 30, 2025
1 check passed
@andymandias andymandias deleted the fix/expanded-echo-search branch January 30, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants