diff --git a/deltachat-ffi/src/dc_array.rs b/deltachat-ffi/src/dc_array.rs index 4a55cc5db..36ee3fc0f 100644 --- a/deltachat-ffi/src/dc_array.rs +++ b/deltachat-ffi/src/dc_array.rs @@ -19,13 +19,26 @@ impl dc_array_t { Self::Chat(array) => match array[index] { ChatItem::Message { msg_id } => msg_id.to_u32(), ChatItem::Marker1 => DC_MSG_ID_MARKER1, - ChatItem::DayMarker => DC_MSG_ID_DAYMARKER, + ChatItem::DayMarker { .. } => DC_MSG_ID_DAYMARKER, }, Self::Locations(array) => array[index].location_id, Self::Uint(array) => array[index], } } + pub(crate) fn get_timestamp(&self, index: usize) -> Option { + match self { + Self::MsgIds(_) => None, + Self::Chat(array) => array.get(index).and_then(|item| match item { + ChatItem::Message { .. } => None, + ChatItem::Marker1 { .. } => None, + ChatItem::DayMarker { timestamp } => Some(*timestamp), + }), + Self::Locations(array) => array.get(index).map(|location| location.timestamp), + Self::Uint(_) => None, + } + } + pub(crate) fn get_location(&self, index: usize) -> &Location { if let Self::Locations(array) = self { &array[index] diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 9836039ab..7d9156dbc 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2021,7 +2021,7 @@ pub unsafe extern "C" fn dc_array_get_timestamp( return 0; } - (*array).get_location(index).timestamp + (*array).get_timestamp(index).unwrap_or_default() } #[no_mangle] pub unsafe extern "C" fn dc_array_get_chat_id( diff --git a/src/chat.rs b/src/chat.rs index 0278bbe5b..41a32972a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -38,7 +38,10 @@ pub enum ChatItem { /// Day marker, separating messages that correspond to different /// days according to local time. - DayMarker, + DayMarker { + /// Marker timestamp, for day markers + timestamp: i64, + }, } /// Chat ID, including reserved IDs. @@ -1645,7 +1648,9 @@ pub async fn get_chat_msgs( let curr_local_timestamp = ts + cnv_to_local; let curr_day = curr_local_timestamp / 86400; if curr_day != last_day { - ret.push(ChatItem::DayMarker); + ret.push(ChatItem::DayMarker { + timestamp: curr_day, + }); last_day = curr_day; } }