DM Chat List: Show avatars on channel entries

This commit is contained in:
Bu5hm4nn 2024-07-12 10:22:32 +02:00
parent d3f4673217
commit 1cfe4db44f

View File

@ -1,11 +1,15 @@
use crate::AVATAR_SIZE_F32;
use super::{widgets, GossipUi, Page};
use eframe::egui;
use eframe::egui::vec2;
use eframe::egui::Rect;
use egui::{Context, Label, RichText, Ui};
use gossip_lib::FeedKind;
use gossip_lib::Person;
use gossip_lib::GLOBALS;
use gossip_lib::{Error, ErrorKind};
use gossip_lib::{PersonTable, Table};
use std::time::{Duration, Instant};
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
@ -59,67 +63,98 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
Some(app.theme.main_content_bgcolor()),
|ui, app| {
ui.set_min_width(ui.available_width());
ui.vertical(|ui| {
ui.horizontal_wrapped(|ui| {
let channel_name = channeldata.dm_channel.name();
ui.add(Label::new(
RichText::new(channel_name).heading().color(color),
));
ui.set_max_height(AVATAR_SIZE_F32);
ui.horizontal(|ui| {
ui.with_layout(
egui::Layout::right_to_left(egui::Align::TOP),
|ui| {
ui.label(crate::date_ago::date_ago(
channeldata.latest_message_created_at,
))
.on_hover_ui(|ui| {
if let Ok(stamp) =
time::OffsetDateTime::from_unix_timestamp(
channeldata.latest_message_created_at.0,
)
{
if let Ok(formatted) = stamp
.format(&time::format_description::well_known::Rfc2822)
{
ui.label(formatted);
}
}
});
ui.label(" - ");
ui.label(
RichText::new(format!(
"{} unread",
channeldata.unread_message_count
))
.color(app.theme.accent_color()),
);
},
);
});
// avatar(s)
if let Some(local) = GLOBALS.identity.public_key() {
for key in channeldata.dm_channel.keys() {
if key != &local {
let person = if let Ok(Some(person)) = PersonTable::read_record(*key, None) {
person
} else {
let mut person = Person::new(*key);
let _ = PersonTable::write_record(&mut person, None);
person
};
ui.horizontal(|ui| {
if is_signer_ready {
if let Some(message) = &channeldata.latest_message_content {
widgets::truncated_label(
ui,
message,
ui.available_width() - 100.0,
);
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &person.pubkey) {
avatar
} else {
app.placeholder_avatar.clone()
};
widgets::paint_avatar(ui, &person, &avatar, widgets::AvatarSize::Feed);
}
}
}
ui.with_layout(
egui::Layout::right_to_left(egui::Align::TOP),
|ui| {
ui.label(
RichText::new(format!(
"{} messages",
channeldata.message_count
ui.add_space(10.0);
ui.vertical(|ui| {
ui.horizontal_wrapped(|ui| {
let channel_name = channeldata.dm_channel.name();
ui.add(Label::new(
RichText::new(channel_name).heading().color(color),
));
ui.with_layout(
egui::Layout::right_to_left(egui::Align::TOP),
|ui| {
ui.label(crate::date_ago::date_ago(
channeldata.latest_message_created_at,
))
.weak(),
.on_hover_ui(|ui| {
if let Ok(stamp) =
time::OffsetDateTime::from_unix_timestamp(
channeldata.latest_message_created_at.0,
)
{
if let Ok(formatted) = stamp
.format(&time::format_description::well_known::Rfc2822)
{
ui.label(formatted);
}
}
});
ui.label(" - ");
ui.label(
RichText::new(format!(
"{} unread",
channeldata.unread_message_count
))
.color(app.theme.accent_color()),
);
},
);
});
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.horizontal(|ui| {
if is_signer_ready {
if let Some(message) = &channeldata.latest_message_content {
widgets::truncated_label(
ui,
message,
ui.available_width() - 100.0,
);
}
}
ui.with_layout(
egui::Layout::right_to_left(egui::Align::TOP),
|ui| {
ui.label(
RichText::new(format!(
"{} messages",
channeldata.message_count
))
.weak(),
);
},
);
},
);
});
});
});
});
},