nip4e: catch up psstpsst (#70)
Reviewed-on: #70
This commit was merged in pull request #70.
This commit is contained in:
@@ -5,8 +5,8 @@ use gpui::{App, AppContext as _, Task};
|
||||
|
||||
use crate::USER_KEYRING;
|
||||
|
||||
/// The storage key for the NIP-4e app keys
|
||||
const APP_KEYS_KEY: &str = "coop/nip4e/app-keys";
|
||||
/// The storage key for the log of handled NIP-4e key-sync request ids
|
||||
const PROCESSED_REQUESTS_KEY: &str = "coop/nip4e/processed-requests";
|
||||
|
||||
/// Read the stored credential as `(username, secret)`
|
||||
#[allow(clippy::type_complexity)]
|
||||
@@ -94,12 +94,12 @@ fn write_named(cx: &App, key: &str, secret: &[u8]) -> Task<Result<()>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Load the NIP-4e app keys from storage, as raw secret bytes
|
||||
pub fn read_app_keys(cx: &App) -> Task<Result<Option<Vec<u8>>>> {
|
||||
read_named(cx, APP_KEYS_KEY)
|
||||
/// Read the log of handled key-sync request ids, as concatenated hex ids
|
||||
pub fn read_processed_requests(cx: &App) -> Task<Result<Option<Vec<u8>>>> {
|
||||
read_named(cx, PROCESSED_REQUESTS_KEY)
|
||||
}
|
||||
|
||||
/// Persist the NIP-4e app keys, as raw secret bytes
|
||||
pub fn write_app_keys(cx: &App, secret: &[u8]) -> Task<Result<()>> {
|
||||
write_named(cx, APP_KEYS_KEY, secret)
|
||||
/// Persist the log of handled key-sync request ids, as concatenated hex ids
|
||||
pub fn write_processed_requests(cx: &App, ids: &[u8]) -> Task<Result<()>> {
|
||||
write_named(cx, PROCESSED_REQUESTS_KEY, ids)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ use nostr_sdk::prelude::*;
|
||||
pub struct Announcement {
|
||||
/// The public key of the device that created this announcement.
|
||||
public_key: PublicKey,
|
||||
/// The id of the announcement event, for ordering
|
||||
event_id: EventId,
|
||||
/// The creation time of the announcement event
|
||||
created_at: Timestamp,
|
||||
}
|
||||
|
||||
impl Announcement {
|
||||
@@ -16,11 +20,20 @@ impl Announcement {
|
||||
.and_then(|tag| tag.content())
|
||||
.and_then(|c| PublicKey::parse(c).ok())?;
|
||||
|
||||
Some(Self { public_key })
|
||||
Some(Self {
|
||||
public_key,
|
||||
event_id: event.id,
|
||||
created_at: event.created_at,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the public key of the device that created this announcement.
|
||||
pub fn public_key(&self) -> PublicKey {
|
||||
self.public_key
|
||||
}
|
||||
|
||||
pub fn is_newer_than(&self, other: &Self) -> bool {
|
||||
self.created_at > other.created_at
|
||||
|| (self.created_at == other.created_at && self.event_id < other.event_id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user