.
This commit is contained in:
@@ -325,6 +325,8 @@ pub struct GroupPanel {
|
||||
speaker: Speaker,
|
||||
/// The message being revealed in step with speech, with its estimated duration
|
||||
speech_reveal: Option<(EventId, Duration)>,
|
||||
/// Fallback reveal end for backends that cannot report utterance end
|
||||
reveal_timeout: Option<Task<Result<()>>>,
|
||||
/// Uploaded, non-encrypted attachments waiting to be sent.
|
||||
attachments: Vec<Url>,
|
||||
/// Whether an upload is in flight.
|
||||
@@ -455,6 +457,7 @@ impl GroupPanel {
|
||||
speech_started: None,
|
||||
speaker,
|
||||
speech_reveal: None,
|
||||
reveal_timeout: None,
|
||||
attachments: Vec::new(),
|
||||
uploading: false,
|
||||
tasks: smallvec![reveal_end_task],
|
||||
@@ -1083,6 +1086,7 @@ impl GroupPanel {
|
||||
panel: cx.weak_entity(),
|
||||
admin,
|
||||
pinned,
|
||||
speaking: self.speech_reveal.is_some(),
|
||||
persons: self.directory.clone(),
|
||||
},
|
||||
cx,
|
||||
|
||||
@@ -14,6 +14,7 @@ use nip29::{Activity, Group, Reaction};
|
||||
use nostr_sdk::prelude::{EventId, Kind};
|
||||
use person::Directory;
|
||||
use settings::AppSettings;
|
||||
use speech::speaker::END_GRACE;
|
||||
use state::NostrRegistry;
|
||||
use ui::{
|
||||
Avatar, MessageActions, MessageMedia, MessageRow, REACTION_EMOJIS, ReactionBar, ReplyPreview,
|
||||
@@ -27,6 +28,8 @@ pub(crate) struct Actions {
|
||||
pub panel: WeakEntity<GroupPanel>,
|
||||
pub admin: bool,
|
||||
pub pinned: bool,
|
||||
/// Whether a message is currently being spoken, disabling the speech buttons
|
||||
pub speaking: bool,
|
||||
pub persons: Entity<Directory>,
|
||||
}
|
||||
|
||||
@@ -92,18 +95,39 @@ pub(crate) fn render(
|
||||
let panel = speech_panel.clone();
|
||||
let speech_text = message.preview();
|
||||
let speech_id = message.id;
|
||||
let speaking = actions.speaking;
|
||||
|
||||
let row = row.overlay(MessageActions::new().speech(move |_event, _window, cx| {
|
||||
_ = speech_panel.update_in(cx, |panel, window, cx| {
|
||||
match panel.speaker.speak(&speech_text) {
|
||||
Ok(duration) => {
|
||||
panel.speech_reveal = Some((speech_id, duration));
|
||||
cx.notify();
|
||||
let row = row.overlay(
|
||||
MessageActions::new().speech(speaking, move |_event, _window, cx| {
|
||||
_ = speech_panel.update_in(cx, |panel, window, cx| {
|
||||
match panel.speaker.speak(&speech_text) {
|
||||
Ok(duration) => {
|
||||
panel.speech_reveal = Some((speech_id, duration));
|
||||
|
||||
let session = (speech_id, duration);
|
||||
let timer = cx.background_executor().timer(duration + END_GRACE);
|
||||
|
||||
panel.reveal_timeout = Some(cx.spawn(async move |this, cx| {
|
||||
timer.await;
|
||||
this.update(cx, |this, cx| {
|
||||
if this.speech_reveal.as_ref() == Some(&session) {
|
||||
this.speech_reveal = None;
|
||||
cx.notify();
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
Err(error) => {
|
||||
window.push_notification(Notification::error(error.to_string()), cx)
|
||||
}
|
||||
}
|
||||
Err(error) => window.push_notification(Notification::error(error.to_string()), cx),
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
let custom = nostr
|
||||
.read(cx)
|
||||
|
||||
Reference in New Issue
Block a user