mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
fix(receive): improve message sorting
This commit is contained in:
committed by
GitHub
parent
6d2d31928d
commit
d208905473
@@ -313,8 +313,6 @@ async fn add_parts(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut state: MessageState;
|
let mut state: MessageState;
|
||||||
let mut chat_id_blocked = Blocked::Not;
|
let mut chat_id_blocked = Blocked::Not;
|
||||||
let mut sort_timestamp = 0;
|
|
||||||
let mut rcvd_timestamp = 0;
|
|
||||||
let mut mime_in_reply_to = String::new();
|
let mut mime_in_reply_to = String::new();
|
||||||
let mut mime_references = String::new();
|
let mut mime_references = String::new();
|
||||||
let mut incoming_origin = incoming_origin;
|
let mut incoming_origin = incoming_origin;
|
||||||
@@ -601,17 +599,9 @@ async fn add_parts(
|
|||||||
}
|
}
|
||||||
// correct message_timestamp, it should not be used before,
|
// correct message_timestamp, it should not be used before,
|
||||||
// however, we cannot do this earlier as we need from_id to be set
|
// however, we cannot do this earlier as we need from_id to be set
|
||||||
calc_timestamps(
|
let (sort_timestamp, new_sent_timestamp, rcvd_timestamp) =
|
||||||
context,
|
calc_timestamps(context, *sent_timestamp, *chat_id, !seen).await;
|
||||||
*chat_id,
|
*sent_timestamp = new_sent_timestamp;
|
||||||
from_id,
|
|
||||||
*sent_timestamp,
|
|
||||||
!seen,
|
|
||||||
&mut sort_timestamp,
|
|
||||||
sent_timestamp,
|
|
||||||
&mut rcvd_timestamp,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// unarchive chat
|
// unarchive chat
|
||||||
chat_id.unarchive(context).await?;
|
chat_id.unarchive(context).await?;
|
||||||
@@ -837,41 +827,43 @@ async fn save_locations(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
async fn calc_timestamps(
|
async fn calc_timestamps(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: ChatId,
|
|
||||||
from_id: u32,
|
|
||||||
message_timestamp: i64,
|
message_timestamp: i64,
|
||||||
|
chat_id: ChatId,
|
||||||
is_fresh_msg: bool,
|
is_fresh_msg: bool,
|
||||||
sort_timestamp: &mut i64,
|
) -> (i64, i64, i64) {
|
||||||
sent_timestamp: &mut i64,
|
let rcvd_timestamp = time();
|
||||||
rcvd_timestamp: &mut i64,
|
let mut sent_timestamp = message_timestamp;
|
||||||
) {
|
if sent_timestamp > rcvd_timestamp {
|
||||||
*rcvd_timestamp = time();
|
sent_timestamp = rcvd_timestamp
|
||||||
*sent_timestamp = message_timestamp;
|
|
||||||
if *sent_timestamp > *rcvd_timestamp {
|
|
||||||
*sent_timestamp = *rcvd_timestamp
|
|
||||||
}
|
}
|
||||||
*sort_timestamp = message_timestamp;
|
let mut sort_timestamp = message_timestamp;
|
||||||
|
|
||||||
|
// get newest non fresh message for this chat
|
||||||
|
// update sort_timestamp if less than that
|
||||||
if is_fresh_msg {
|
if is_fresh_msg {
|
||||||
let last_msg_time: Option<i64> = context
|
let last_msg_time: Option<i64> = context
|
||||||
.sql
|
.sql
|
||||||
.query_get_value(
|
.query_get_value(
|
||||||
context,
|
context,
|
||||||
"SELECT MAX(timestamp) FROM msgs WHERE chat_id=? and from_id!=? AND timestamp>=?",
|
"SELECT MAX(timestamp) FROM msgs WHERE chat_id=? AND state>?",
|
||||||
paramsv![chat_id, from_id as i32, *sort_timestamp],
|
paramsv![chat_id, MessageState::InFresh],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Some(last_msg_time) = last_msg_time {
|
if let Some(last_msg_time) = last_msg_time {
|
||||||
if last_msg_time > 0 && *sort_timestamp <= last_msg_time {
|
if last_msg_time > sort_timestamp {
|
||||||
*sort_timestamp = last_msg_time + 1;
|
sort_timestamp = last_msg_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if *sort_timestamp >= dc_smeared_time(context).await {
|
|
||||||
*sort_timestamp = dc_create_smeared_timestamp(context).await;
|
if sort_timestamp >= dc_smeared_time(context).await {
|
||||||
|
sort_timestamp = dc_create_smeared_timestamp(context).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(sort_timestamp, sent_timestamp, rcvd_timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function tries extracts the group-id from the message and returns the
|
/// This function tries extracts the group-id from the message and returns the
|
||||||
|
|||||||
Reference in New Issue
Block a user