chore: fix crash when failing to parse message (#202)
* clean up * . * fix rich text component * clean up
This commit is contained in:
@@ -42,9 +42,3 @@ pub const METADATA_BATCH_TIMEOUT: u64 = 300;
|
||||
|
||||
/// Default width of the sidebar.
|
||||
pub const DEFAULT_SIDEBAR_WIDTH: f32 = 240.;
|
||||
|
||||
/// Image Resize Service
|
||||
pub const IMAGE_RESIZE_SERVICE: &str = "https://wsrv.nl";
|
||||
|
||||
/// Default NIP96 Media Server.
|
||||
pub const NIP96_SERVER: &str = "https://nostrmedia.com";
|
||||
|
||||
@@ -12,7 +12,7 @@ use nostr_sdk::prelude::*;
|
||||
use smol::lock::RwLock;
|
||||
|
||||
use crate::constants::{
|
||||
BOOTSTRAP_RELAYS, METADATA_BATCH_LIMIT, METADATA_BATCH_TIMEOUT, QUERY_TIMEOUT, SEARCH_RELAYS,
|
||||
BOOTSTRAP_RELAYS, METADATA_BATCH_LIMIT, METADATA_BATCH_TIMEOUT, QUERY_TIMEOUT,
|
||||
};
|
||||
use crate::paths::config_dir;
|
||||
use crate::state::ingester::Ingester;
|
||||
@@ -210,19 +210,6 @@ impl AppState {
|
||||
|
||||
/// Handles events from the nostr client
|
||||
pub async fn handle_notifications(&self) -> Result<(), Error> {
|
||||
// Get all bootstrapping relays
|
||||
let mut urls = vec![];
|
||||
urls.extend(BOOTSTRAP_RELAYS);
|
||||
urls.extend(SEARCH_RELAYS);
|
||||
|
||||
// Add relay to the relay pool
|
||||
for url in urls.into_iter() {
|
||||
self.client.add_relay(url).await?;
|
||||
}
|
||||
|
||||
// Establish connection to relays
|
||||
self.client.connect().await;
|
||||
|
||||
let mut processed_events: HashSet<EventId> = HashSet::new();
|
||||
let mut challenges: HashSet<Cow<'_, str>> = HashSet::new();
|
||||
let mut notifications = self.client.notifications();
|
||||
@@ -345,9 +332,7 @@ impl AppState {
|
||||
self.signal.send(SignalKind::NewProfile(profile)).await;
|
||||
}
|
||||
Kind::GiftWrap => {
|
||||
if let Err(e) = self.extract_rumor(&event).await {
|
||||
log::error!("Failed to extract rumor: {e}");
|
||||
}
|
||||
self.extract_rumor(&event).await.ok();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -997,6 +982,8 @@ impl AppState {
|
||||
.subscribe_with_id_to(&urls, id, filter, None)
|
||||
.await?;
|
||||
|
||||
log::info!("Subscribed to gift wrap events");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1027,15 +1014,15 @@ impl AppState {
|
||||
}
|
||||
|
||||
/// Stores an unwrapped event in local database with reference to original
|
||||
async fn set_rumor(&self, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> {
|
||||
async fn set_rumor(&self, gift_wrap: EventId, rumor: &UnsignedEvent) -> Result<(), Error> {
|
||||
let rumor_id = rumor.id.context("Rumor is missing an event id")?;
|
||||
let author = rumor.pubkey;
|
||||
let conversation = self.conversation_id(rumor).to_string();
|
||||
let conversation = self.conversation_id(rumor);
|
||||
|
||||
let mut tags = rumor.tags.clone().to_vec();
|
||||
|
||||
// Add a unique identifier
|
||||
tags.push(Tag::identifier(id));
|
||||
tags.push(Tag::identifier(gift_wrap));
|
||||
|
||||
// Add a reference to the rumor's author
|
||||
tags.push(Tag::custom(
|
||||
@@ -1046,7 +1033,7 @@ impl AppState {
|
||||
// Add a conversation id
|
||||
tags.push(Tag::custom(
|
||||
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::C)),
|
||||
[conversation],
|
||||
[conversation.to_string()],
|
||||
));
|
||||
|
||||
// Add a reference to the rumor's id
|
||||
@@ -1063,21 +1050,23 @@ impl AppState {
|
||||
// Convert rumor to json
|
||||
let content = rumor.as_json();
|
||||
|
||||
// Construct the event
|
||||
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
||||
.tags(tags)
|
||||
.sign(&Keys::generate())
|
||||
.await?;
|
||||
|
||||
// Save the event to the database
|
||||
self.client.database().save_event(&event).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Retrieves a previously unwrapped event from local database
|
||||
async fn get_rumor(&self, id: EventId) -> Result<UnsignedEvent, Error> {
|
||||
async fn get_rumor(&self, gift_wrap: EventId) -> Result<UnsignedEvent, Error> {
|
||||
let filter = Filter::new()
|
||||
.kind(Kind::ApplicationSpecificData)
|
||||
.identifier(id)
|
||||
.identifier(gift_wrap)
|
||||
.limit(1);
|
||||
|
||||
if let Some(event) = self.client.database().query(filter).await?.first_owned() {
|
||||
@@ -1118,20 +1107,15 @@ impl AppState {
|
||||
|
||||
// Helper method to try unwrapping with different signers
|
||||
async fn try_unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result<UnwrappedGift, Error> {
|
||||
// Try to unwrap with the encryption key first
|
||||
// Try to unwrap with the encryption key if available
|
||||
// NIP-4e: https://github.com/nostr-protocol/nips/blob/per-device-keys/4e.md
|
||||
if let Some(signer) = self.device.read().await.encryption.as_ref() {
|
||||
match UnwrappedGift::from_gift_wrap(signer, gift_wrap).await {
|
||||
Ok(unwrapped) => {
|
||||
return Ok(unwrapped);
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Failed to unwrap with the encryption key: {e}")
|
||||
}
|
||||
if let Ok(unwrapped) = UnwrappedGift::from_gift_wrap(signer, gift_wrap).await {
|
||||
return Ok(unwrapped);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to unwrap with the user's signer
|
||||
// Fallback to unwrap with the user's signer
|
||||
let signer = self.client.signer().await?;
|
||||
let unwrapped = UnwrappedGift::from_gift_wrap(&signer, gift_wrap).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user