Skip to content

Commit 1e85297

Browse files
committed
Added timestamp display to image_viewer
1 parent 56b6caf commit 1e85297

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/home/room_screen.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ impl Widget for RoomScreen {
667667
let texture = content_message.get_texture(cx);
668668
let mut avatar_ref = wr.avatar(ids!(profile.avatar));
669669
let mut display_name = wr.label(ids!(content.username_view.username)).text();
670-
let timestamp = wr.label(ids!(profile.timestamp)).text();
671670

672671
// If display_name is empty, look for a non-empty display_name and its avatar in previous items
673672
if display_name.is_empty() {
@@ -680,7 +679,6 @@ impl Widget for RoomScreen {
680679
std::rc::Rc::new(texture),
681680
avatar_ref,
682681
display_name,
683-
timestamp,
684682
index,
685683
);
686684
continue;
@@ -1597,21 +1595,20 @@ impl RoomScreen {
15971595
texture: std::rc::Rc<Option<Texture>>,
15981596
avatar_ref: AvatarRef,
15991597
display_name: String,
1600-
timestamp: String,
16011598
index: usize,
16021599
) {
16031600
let Some(mxc_uri_string) = mxc_uri else { return; };
16041601
let Some(tl_state) = &mut self.tl_state else { return; };
16051602
let Some(item) = tl_state.items.get(index) else { return; };
16061603
let Some(event_tl_item) = item.as_event() else { return; };
1607-
1604+
let timestamp_millis = event_tl_item.timestamp();
16081605
let (image_name, image_size) = extract_image_info(event_tl_item);
16091606

16101607
cx.action(ImageViewerAction::Show(LoadState::Loading(texture.clone(), Some(MetaData{
16111608
sender: display_name,
16121609
image_name,
16131610
image_size,
1614-
timestamp,
1611+
timestamp: unix_time_millis_to_datetime(timestamp_millis),
16151612
avatar_ref
16161613
}))));
16171614

src/shared/image_viewer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
//! ImageViewerRef has 4 public methods, `configure_zoom`, `display_using_background_thread`, `display_using_texture` and `reset`.
55
use std::sync::{mpsc::Receiver, Arc};
66

7+
use chrono::{DateTime, Local};
78
use makepad_widgets::{
89
event::TouchUpdateEvent,
910
image_cache::{ImageBuffer, ImageError},
1011
rotated_image::RotatedImageWidgetExt,
1112
*,
1213
};
1314

14-
use crate::shared::avatar::{AvatarRef, AvatarWidgetRefExt};
15+
use crate::shared::{avatar::{AvatarRef, AvatarWidgetRefExt}, timestamp::TimestampWidgetRefExt};
1516

1617
/// Loads the given image `data` into an `ImageBuffer` as either a PNG or JPEG, using the `imghdr` library to determine which format it is.
1718
///
@@ -925,7 +926,13 @@ impl ImageViewer {
925926
let display_text = format!("{} ({})", truncated_name, human_readable_size);
926927
meta_view.label(ids!(image_name_and_size))
927928
.set_text(cx, &display_text);
929+
if let Some(timestamp) = metadata.timestamp {
930+
meta_view.view(ids!(top_left_container.content.timestamp_view)).set_visible(cx, true);
931+
meta_view.timestamp(ids!(top_left_container.content.timestamp_view.timestamp)).set_date_time(cx, timestamp);
932+
}
933+
928934
meta_view.label(ids!(top_left_container.content.username)).set_text(cx, &metadata.sender);
935+
929936
metadata.avatar_ref.copy_content_to(cx, &mut meta_view.avatar(ids!(top_left_container.avatar)));
930937
}
931938
}
@@ -1013,7 +1020,7 @@ pub enum LoadState {
10131020
pub struct MetaData {
10141021
pub avatar_ref: AvatarRef,
10151022
pub sender: String,
1016-
pub timestamp: String,
1023+
pub timestamp: Option<DateTime<Local>>,
10171024
pub image_name: String,
10181025
pub image_size: i32,
10191026
}

0 commit comments

Comments
 (0)