Skip to content

Commit

Permalink
Use local timezone. Fix inline code formatting. (#65)
Browse files Browse the repository at this point in the history
Improve other message formatting, such as block quotes and code.
  • Loading branch information
kevinaboos authored Apr 10, 2024
1 parent ca86d3f commit bbc81be
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl Widget for Timeline {
let item = list.item(cx, item_id, live_id!(DayDivider)).unwrap();
let text = unix_time_millis_to_datetime(millis)
// format the time as a shortened date (Sat, Sept 5, 2021)
.map(|dt| format!("{}", dt.date().format("%a %b %-d, %Y")))
.map(|dt| format!("{}", dt.date_naive().format("%a %b %-d, %Y")))
.unwrap_or_else(|| format!("{:?}", millis));
item.label(id!(date)).set_text(&text);
(item, ItemDrawnStatus::both_drawn())
Expand Down Expand Up @@ -1184,7 +1184,7 @@ fn populate_message_view(
&format!("{}", dt.time().format("%l:%M %P"))
);
item.label(id!(profile.datestamp)).set_text(
&format!("{}", dt.date())
&format!("{}", dt.date_naive())
);
} else {
item.label(id!(profile.timestamp)).set_text(
Expand Down
2 changes: 1 addition & 1 deletion src/home/rooms_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Widget for RoomsList {
}
if let Some((ts, msg)) = room_info.latest.as_ref() {
if let Some(dt) = unix_time_millis_to_datetime(ts) {
let text = format!("{} {}", dt.date(), dt.time().format("%l:%M %P"));
let text = format!("{} {}", dt.date_naive(), dt.time().format("%l:%M %P"));
item.label(id!(timestamp)).set_text(&text);
}
item.label(id!(preview.latest_message)).set_text(msg);
Expand Down
7 changes: 5 additions & 2 deletions src/shared/html_or_plaintext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ live_design! {
// For some reason, they're not the same. That's TBD.
HTML_LINE_SPACING = 8.0
HTML_TEXT_HEIGHT_FACTOR = 1.3
HTML_BLOCK_LINE_SPACING = 5.0


// This is an HTML subwidget used to handle `<font>` and `<span>` tags,
Expand Down Expand Up @@ -42,15 +43,17 @@ live_design! {
draw_bold: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } }
draw_bold_italic: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } }
draw_fixed: { color: (MESSAGE_TEXT_COLOR), text_style: { height_factor: (HTML_TEXT_HEIGHT_FACTOR), line_spacing: (HTML_LINE_SPACING) } }
draw_block:{
draw_block: {
line_color: (MESSAGE_TEXT_COLOR)
sep_color: (MESSAGE_TEXT_COLOR)
quote_bg_color: (#EDEDED)
quote_fg_color: (MESSAGE_TEXT_COLOR)
block_color: (#EDEDED)
code_color: (#EDEDED)
}
list_item_layout: { line_spacing: 5.0, padding: {top: 1.0, bottom: 1.0}, }
list_item_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {left: 5.0, top: 1.0, bottom: 1.0}, }
code_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {top: 4.0, bottom: 4.0}, }
quote_layout: { line_spacing: (HTML_BLOCK_LINE_SPACING), padding: {top: 0.0, bottom: 8.0}, }

font = <MatrixHtmlSpan> { }
span = <MatrixHtmlSpan> { }
Expand Down
2 changes: 1 addition & 1 deletion src/shared/styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ live_design! {


MESSAGE_FONT_SIZE = 12.0
MESSAGE_TEXT_COLOR = #x777
MESSAGE_TEXT_COLOR = #x555
MESSAGE_TEXT_LINE_SPACING = 1.35
MESSAGE_TEXT_HEIGHT_FACTOR = 1.5
// This font should only be used for plaintext labels. Don't use this for Html content,
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::SystemTime;

use chrono::NaiveDateTime;
use chrono::{DateTime, Local, TimeZone};
use makepad_widgets::{error, image_cache::ImageError, Cx, ImageRef};
use matrix_sdk::{ruma::{MilliSecondsSinceUnixEpoch, api::client::media::get_content_thumbnail::v3::Method}, media::{MediaThumbnailSize, MediaFormat}};

Expand Down Expand Up @@ -52,9 +52,9 @@ pub fn load_png_or_jpg(img: &ImageRef, cx: &mut Cx, data: &[u8]) -> Result<(), I
}


pub fn unix_time_millis_to_datetime(millis: &MilliSecondsSinceUnixEpoch) -> Option<NaiveDateTime> {
pub fn unix_time_millis_to_datetime(millis: &MilliSecondsSinceUnixEpoch) -> Option<DateTime<Local>> {
let millis: i64 = millis.get().into();
NaiveDateTime::from_timestamp_millis(millis)
Local.timestamp_millis_opt(millis).single()
}


Expand Down

0 comments on commit bbc81be

Please sign in to comment.