feat: resend messages after authentication (#137)

* resend failed message

* update settings
This commit is contained in:
reya
2025-09-02 18:19:53 +07:00
committed by GitHub
parent 5a36354cc8
commit d392602ed6
7 changed files with 166 additions and 98 deletions

View File

@@ -1,10 +1,12 @@
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::time::Duration;
use anyhow::Error;
use common::display::ReadableProfile;
use common::event::EventUtils;
use global::nostr_client;
use global::constants::SEND_RETRY;
use global::{css, nostr_client};
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
use itertools::Itertools;
use nostr_sdk::prelude::*;
@@ -472,7 +474,32 @@ impl Room {
.await
{
Ok(output) => {
reports.push(SendReport::output(receiver, output));
if output
.failed
.iter()
.any(|(_, msg)| msg.starts_with("auth-required:"))
{
let id = output.id();
// Wait for authenticated and resent event successfully
for attempt in 0..=SEND_RETRY {
// Check if event was successfully resent
if let Some(output) =
css().resent_ids.read().await.iter().find(|o| o.id() == id)
{
reports.push(SendReport::output(receiver, output.to_owned()));
break;
}
if attempt == SEND_RETRY {
break;
}
smol::Timer::after(Duration::from_secs(1)).await;
}
} else {
reports.push(SendReport::output(receiver, output));
}
}
Err(e) => {
if let nostr_sdk::client::Error::PrivateMsgRelaysNotFound = e {