mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
DM Chat List: Show avatars on channel entries
This commit is contained in:
parent
d3f4673217
commit
1cfe4db44f
@ -1,11 +1,15 @@
|
|||||||
|
use crate::AVATAR_SIZE_F32;
|
||||||
|
|
||||||
use super::{widgets, GossipUi, Page};
|
use super::{widgets, GossipUi, Page};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use eframe::egui::vec2;
|
use eframe::egui::vec2;
|
||||||
use eframe::egui::Rect;
|
use eframe::egui::Rect;
|
||||||
use egui::{Context, Label, RichText, Ui};
|
use egui::{Context, Label, RichText, Ui};
|
||||||
use gossip_lib::FeedKind;
|
use gossip_lib::FeedKind;
|
||||||
|
use gossip_lib::Person;
|
||||||
use gossip_lib::GLOBALS;
|
use gossip_lib::GLOBALS;
|
||||||
use gossip_lib::{Error, ErrorKind};
|
use gossip_lib::{Error, ErrorKind};
|
||||||
|
use gossip_lib::{PersonTable, Table};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
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()),
|
Some(app.theme.main_content_bgcolor()),
|
||||||
|ui, app| {
|
|ui, app| {
|
||||||
ui.set_min_width(ui.available_width());
|
ui.set_min_width(ui.available_width());
|
||||||
ui.vertical(|ui| {
|
ui.set_max_height(AVATAR_SIZE_F32);
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let channel_name = channeldata.dm_channel.name();
|
|
||||||
ui.add(Label::new(
|
|
||||||
RichText::new(channel_name).heading().color(color),
|
|
||||||
));
|
|
||||||
|
|
||||||
ui.with_layout(
|
// avatar(s)
|
||||||
egui::Layout::right_to_left(egui::Align::TOP),
|
if let Some(local) = GLOBALS.identity.public_key() {
|
||||||
|ui| {
|
for key in channeldata.dm_channel.keys() {
|
||||||
ui.label(crate::date_ago::date_ago(
|
if key != &local {
|
||||||
channeldata.latest_message_created_at,
|
let person = if let Ok(Some(person)) = PersonTable::read_record(*key, None) {
|
||||||
))
|
person
|
||||||
.on_hover_ui(|ui| {
|
} else {
|
||||||
if let Ok(stamp) =
|
let mut person = Person::new(*key);
|
||||||
time::OffsetDateTime::from_unix_timestamp(
|
let _ = PersonTable::write_record(&mut person, None);
|
||||||
channeldata.latest_message_created_at.0,
|
person
|
||||||
)
|
};
|
||||||
{
|
|
||||||
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.horizontal(|ui| {
|
let avatar = if let Some(avatar) = app.try_get_avatar(ctx, &person.pubkey) {
|
||||||
if is_signer_ready {
|
avatar
|
||||||
if let Some(message) = &channeldata.latest_message_content {
|
} else {
|
||||||
widgets::truncated_label(
|
app.placeholder_avatar.clone()
|
||||||
ui,
|
};
|
||||||
message,
|
|
||||||
ui.available_width() - 100.0,
|
widgets::paint_avatar(ui, &person, &avatar, widgets::AvatarSize::Feed);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.with_layout(
|
ui.add_space(10.0);
|
||||||
egui::Layout::right_to_left(egui::Align::TOP),
|
|
||||||
|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.label(
|
ui.horizontal_wrapped(|ui| {
|
||||||
RichText::new(format!(
|
let channel_name = channeldata.dm_channel.name();
|
||||||
"{} messages",
|
ui.add(Label::new(
|
||||||
channeldata.message_count
|
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(),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user