chore: fix missing message during initial fetch (#110)

* remove fetched flag

* .

* improve
This commit is contained in:
reya
2025-08-06 09:15:00 +07:00
committed by GitHub
parent af74a4ed23
commit 9127696517
6 changed files with 60 additions and 118 deletions

View File

@@ -3,11 +3,8 @@ use std::time::Duration;
use anyhow::{anyhow, Error};
use client_keys::ClientKeys;
use common::handle_auth::CoopAuthUrlHandler;
use global::constants::{
ACCOUNT_D, ALL_MESSAGES_ID, ALL_NEWEST_MESSAGES_ID, NEW_MESSAGE_ID, NIP17_RELAYS, NIP65_RELAYS,
NOSTR_CONNECT_TIMEOUT,
};
use global::{is_gift_wraps_fetch_complete, nostr_client};
use global::constants::{ACCOUNT_D, NIP17_RELAYS, NIP65_RELAYS, NOSTR_CONNECT_TIMEOUT};
use global::{gift_wrap_sub_id, nostr_client};
use gpui::prelude::FluentBuilder;
use gpui::{
div, red, App, AppContext, Context, Entity, Global, ParentElement, SharedString, Styled,
@@ -632,13 +629,15 @@ impl Identity {
}
pub(crate) async fn subscribe(client: &Client, public_key: PublicKey) -> Result<(), Error> {
let all_messages = SubscriptionId::new(ALL_MESSAGES_ID);
let all_newest_messages = SubscriptionId::new(ALL_NEWEST_MESSAGES_ID);
let new_messages = SubscriptionId::new(NEW_MESSAGE_ID);
// Subscription options
let opts = SubscribeAutoCloseOptions::default().exit_policy(ReqExitPolicy::ExitOnEOSE);
// Get the gift wraps fetch status
let is_completed = is_gift_wraps_fetch_complete();
client
.subscribe_with_id(
gift_wrap_sub_id().to_owned(),
Filter::new().kind(Kind::GiftWrap).pubkey(public_key),
None,
)
.await?;
client
.subscribe(
@@ -660,37 +659,6 @@ impl Identity {
)
.await?;
client
.subscribe_with_id(
new_messages,
Filter::new()
.kind(Kind::GiftWrap)
.pubkey(public_key)
.limit(0),
None,
)
.await?;
if is_completed {
let week_ago: u64 = 7 * 24 * 60 * 60;
let since = Timestamp::from_secs(Timestamp::now().as_u64() - week_ago);
let filter = Filter::new()
.pubkey(public_key)
.kind(Kind::GiftWrap)
.since(since);
client
.subscribe_with_id(all_newest_messages, filter, Some(opts))
.await?;
} else {
let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key);
client
.subscribe_with_id(all_messages, filter, Some(opts))
.await?;
};
log::info!("Getting all user's metadata and messages...");
Ok(())