This commit is contained in:
2026-10-30 10:37:29 +07:00
parent af2a276b1b
commit 6ce20927ee
9 changed files with 205 additions and 32 deletions
+8 -6
View File
@@ -26,6 +26,7 @@ use person::Directory;
use serde::Deserialize;
use settings::AppSettings;
use smallvec::{SmallVec, smallvec};
use speech::speaker::Speaker;
use state::{NostrRegistry, pick_file, upload_file};
use ui::{Avatar, RenderedText, WelcomeMessage, rendered_text};
use util::{attachment_name, display_name, opens_run, pin_label, report};
@@ -320,6 +321,8 @@ pub struct GroupPanel {
speech: Entity<SpeechState>,
/// When the running dictation started, for the elapsed counter
speech_started: Option<instant::Instant>,
/// Reads messages aloud
speaker: Speaker,
/// Uploaded, non-encrypted attachments waiting to be sent.
attachments: Vec<Url>,
/// Whether an upload is in flight.
@@ -419,9 +422,10 @@ impl GroupPanel {
}
},
));
this.track_participants(cx);
});
let mut this = Self {
Self {
focus_handle: cx.focus_handle(),
group: group.downgrade(),
directory: Directory::new(cx),
@@ -433,15 +437,12 @@ impl GroupPanel {
input,
speech,
speech_started: None,
speaker: Speaker::new(),
attachments: Vec::new(),
uploading: false,
tasks: smallvec![],
_subscriptions: subscriptions,
};
this.track_participants(cx);
this
}
}
/// Track the keys rendered by this panel: members, message authors, and
@@ -1059,6 +1060,7 @@ impl GroupPanel {
panel: cx.weak_entity(),
admin,
pinned,
speaking: self.speaker.speaking(),
persons: self.directory.clone(),
},
cx,
+40 -3
View File
@@ -8,7 +8,8 @@ use gpui::{
use gpui_kit::assets::IconName;
use gpui_kit::base::StyledExt as _;
use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
use gpui_kit::component::{ActiveTheme, Icon, Sizable, h_flex};
use gpui_kit::component::notification::Notification;
use gpui_kit::component::{ActiveTheme, Icon, Sizable, WindowExt, h_flex};
use nip29::{Activity, Group, Reaction};
use nostr_sdk::prelude::{EventId, Kind};
use person::Directory;
@@ -26,6 +27,8 @@ pub(crate) struct Actions {
pub panel: WeakEntity<GroupPanel>,
pub admin: bool,
pub pinned: bool,
/// Whether the panel's speaker is currently saying something
pub speaking: bool,
pub persons: Entity<Directory>,
}
@@ -88,9 +91,9 @@ pub(crate) fn render(
let pinned = actions.pinned;
let group = actions.group;
let panel = actions.panel;
let speaking = actions.speaking;
let text = message.preview();
// Reading the panel here would re-enter its ongoing update, so resolve
// the current user's custom emojis through the shared person directory.
let custom = nostr
.read(cx)
.current_user()
@@ -139,6 +142,40 @@ pub(crate) fn render(
}
});
let menu = menu.separator().item({
let panel = panel.clone();
let text = text.clone();
PopupMenuItem::new("Read aloud").on_click(move |_event, _window, cx| {
if let Err(error) = panel.update_in(cx, |panel, window, cx| {
if let Err(error) = panel.speaker.speak(&text) {
window.push_notification(Notification::error(error.to_string()), cx);
}
}) {
log::warn!("nip29: reading a message aloud failed: {error}");
}
})
});
let menu = if speaking {
menu.item({
let panel = panel.clone();
PopupMenuItem::new("Stop speaking").on_click(move |_event, _window, cx| {
if let Err(error) = panel.update_in(cx, |panel, window, cx| {
if let Err(error) = panel.speaker.stop() {
window
.push_notification(Notification::error(error.to_string()), cx);
}
}) {
log::warn!("nip29: stopping the speaker failed: {error}");
}
})
})
} else {
menu
};
if !admin {
return menu;
}