Skip to content

Commit

Permalink
Revert "Merge pull request #714 from squidowl/expand-echo-search"
Browse files Browse the repository at this point in the history
This reverts commit 6f50724, reversing
changes made to 49b491e.
  • Loading branch information
tarkah committed Jan 24, 2025
1 parent bb806a8 commit ab2c1a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
12 changes: 4 additions & 8 deletions data/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,16 @@ impl History {
/// of the incoming message. Either message IDs match, or server times
/// have an exact match + target & content.
pub fn insert_message(messages: &mut Vec<Message>, message: Message) {
let fuzz_seconds = if matches!(message.direction, message::Direction::Received(true)) {
chrono::Duration::seconds(120)
} else {
chrono::Duration::seconds(1)
};
const FUZZ_SECONDS: chrono::Duration = chrono::Duration::seconds(1);

if messages.is_empty() {
messages.push(message);

return;
}

let start = message.server_time - fuzz_seconds;
let end = message.server_time + fuzz_seconds;
let start = message.server_time - FUZZ_SECONDS;
let end = message.server_time + FUZZ_SECONDS;

let start_index = match messages.binary_search_by(|stored| stored.server_time.cmp(&start)) {
Ok(match_index) => match_index,
Expand All @@ -523,7 +519,7 @@ pub fn insert_message(messages: &mut Vec<Message>, message: Message) {
if (message.id.is_some() && stored.id == message.id)
|| ((stored.server_time == message.server_time
|| (matches!(stored.direction, message::Direction::Sent)
&& matches!(message.direction, message::Direction::Received(true))))
&& matches!(message.direction, message::Direction::Received)))
&& has_matching_content(stored, &message))
{
replace_at = Some(current_index);
Expand Down
16 changes: 5 additions & 11 deletions data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ impl Target {
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Direction {
Sent,
/// is_echo
Received(bool),
Received,
}

#[derive(Debug, Clone)]
Expand All @@ -172,7 +171,7 @@ pub struct Message {

impl Message {
pub fn triggers_unread(&self) -> bool {
matches!(self.direction, Direction::Received(false))
matches!(self.direction, Direction::Received)
&& match self.target.source() {
Source::User(_) => true,
Source::Action(_) => true,
Expand Down Expand Up @@ -227,11 +226,6 @@ impl Message {
) -> Option<Message> {
let server_time = server_time(&encoded);
let id = message_id(&encoded);
let direction = Direction::Received(
encoded
.user()
.is_some_and(|user| user.nickname() == our_nick),
);
let content = content(
&encoded,
&our_nick,
Expand All @@ -256,7 +250,7 @@ impl Message {
Some(Message {
received_at,
server_time,
direction,
direction: Direction::Received,
target,
content,
id,
Expand Down Expand Up @@ -291,7 +285,7 @@ impl Message {
Message {
received_at,
server_time: Utc::now(),
direction: Direction::Received(false),
direction: Direction::Received,
target: Target::Query {
query: query.clone(),
source: Source::Action(None),
Expand Down Expand Up @@ -342,7 +336,7 @@ impl Message {
Self {
received_at,
server_time,
direction: Direction::Received(false),
direction: Direction::Received,
target: Target::Logs,
content,
id: None,
Expand Down
2 changes: 1 addition & 1 deletion data/src/message/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn expand(
Message {
received_at,
server_time: sent_time,
direction: Direction::Received(false),
direction: Direction::Received,
target,
content,
id: None,
Expand Down

0 comments on commit ab2c1a7

Please sign in to comment.