wip: update nostr sdk
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m35s
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m35s
This commit is contained in:
@@ -136,7 +136,7 @@ impl AppSettings {
|
||||
}
|
||||
|
||||
fn new(cx: &mut Context<Self>) -> Self {
|
||||
let load_settings = Self::get_from_database(false, cx);
|
||||
let load_settings = Self::get_from_database(cx);
|
||||
|
||||
let mut tasks = smallvec![];
|
||||
let mut subscriptions = smallvec![];
|
||||
@@ -169,12 +169,10 @@ impl AppSettings {
|
||||
}
|
||||
|
||||
/// Get settings from the database
|
||||
///
|
||||
/// If `current_user` is true, the settings will be retrieved for current user.
|
||||
/// Otherwise, Coop will load the latest settings from the database.
|
||||
fn get_from_database(current_user: bool, cx: &App) -> Task<Result<Settings, Error>> {
|
||||
fn get_from_database(cx: &App) -> Task<Result<Settings, Error>> {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
let current_user = nostr.read(cx).identity().read(cx).public_key;
|
||||
|
||||
cx.background_spawn(async move {
|
||||
// Construct a filter to get the latest settings
|
||||
@@ -183,10 +181,7 @@ impl AppSettings {
|
||||
.identifier(SETTINGS_IDENTIFIER)
|
||||
.limit(1);
|
||||
|
||||
if current_user {
|
||||
let signer = client.signer().await?;
|
||||
let public_key = signer.get_public_key().await?;
|
||||
|
||||
if let Some(public_key) = current_user {
|
||||
// Push author to the filter
|
||||
filter = filter.author(public_key);
|
||||
}
|
||||
@@ -201,7 +196,7 @@ impl AppSettings {
|
||||
|
||||
/// Load settings
|
||||
pub fn load(&mut self, cx: &mut Context<Self>) {
|
||||
let task = Self::get_from_database(true, cx);
|
||||
let task = Self::get_from_database(cx);
|
||||
|
||||
self._tasks.push(
|
||||
// Run task in the background
|
||||
@@ -221,18 +216,17 @@ impl AppSettings {
|
||||
pub fn save(&mut self, cx: &mut Context<Self>) {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
let public_key = nostr.read(cx).identity().read(cx).public_key();
|
||||
|
||||
if let Ok(content) = serde_json::to_string(&self.values) {
|
||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||
let signer = client.signer().await?;
|
||||
let public_key = signer.get_public_key().await?;
|
||||
|
||||
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
||||
.tag(Tag::identifier(SETTINGS_IDENTIFIER))
|
||||
.build(public_key)
|
||||
.sign(&Keys::generate())
|
||||
.await?;
|
||||
|
||||
// Save event to the local database without sending to relays
|
||||
client.database().save_event(&event).await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user