Skip to content

Commit

Permalink
nostr: deprecate JobRequest, JobResult, Regular, Replaceable
Browse files Browse the repository at this point in the history
…and `Ephemeral` kind variants

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
  • Loading branch information
yukibtc committed Dec 30, 2024
1 parent 8e40621 commit a7101ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
### Deprecated

* nostr: deprecate `PARAMETERIZED_REPLACEABLE_RANGE`, `Kind::ParameterizedReplaceable` and `Kind::is_parameterized_replaceable` ([Yuki Kishimoto])
* nostr: deprecate `JobRequest`, `JobResult`, `Regular`, `Replaceable` and `Ephemeral` kind variants ([Yuki Kishimoto])
* pool: deprecated batch event methods ([Yuki Kishimoto])
* pool: deprecate `FilterOptions` ([Yuki Kishimoto])
* sdk: deprecate `timeout` option ([Yuki Kishimoto])
Expand Down
35 changes: 9 additions & 26 deletions bindings/nostr-sdk-ffi/src/protocol/event/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,7 @@ pub enum KindEnum {
SetProduct,
/// Job Feedback (NIP90)
JobFeedback,
JobRequest {
kind: u16,
},
JobResult {
kind: u16,
},
Regular {
kind: u16,
},
Replaceable {
kind: u16,
},
Ephemeral {
kind: u16,
},
// TODO: remove this variant
Custom {
kind: u16,
},
Expand Down Expand Up @@ -427,19 +413,21 @@ impl From<nostr::Kind> for KindEnum {
nostr::Kind::SetStall => Self::SetStall,
nostr::Kind::SetProduct => Self::SetProduct,
nostr::Kind::JobFeedback => Self::JobFeedback,
nostr::Kind::JobRequest(kind) => Self::JobRequest { kind },
nostr::Kind::JobResult(kind) => Self::JobResult { kind },
nostr::Kind::InboxRelays => Self::InboxRelays,
nostr::Kind::MlsKeyPackageRelays => Self::MlsKeyPackageRelays,
nostr::Kind::MlsKeyPackage => Self::MlsKeyPackage,
nostr::Kind::MlsWelcome => Self::MlsWelcome,
nostr::Kind::MlsGroupMessage => Self::MlsGroupMessage,
nostr::Kind::Torrent => Self::Torrent,
nostr::Kind::TorrentComment => Self::TorrentComment,
nostr::Kind::Regular(u) => Self::Regular { kind: u },
nostr::Kind::Replaceable(u) => Self::Replaceable { kind: u },
nostr::Kind::Ephemeral(u) => Self::Ephemeral { kind: u },
nostr::Kind::Custom(u) => Self::Custom { kind: u },
#[allow(deprecated)]
nostr::Kind::JobRequest(u)
| nostr::Kind::JobResult(u)
| nostr::Kind::Regular(u)
| nostr::Kind::Replaceable(u)
| nostr::Kind::Ephemeral(u)
| nostr::Kind::ParameterizedReplaceable(u)
| nostr::Kind::Custom(u) => Self::Custom { kind: u },
}
}
}
Expand Down Expand Up @@ -520,18 +508,13 @@ impl From<KindEnum> for nostr::Kind {
KindEnum::SetStall => Self::SetStall,
KindEnum::SetProduct => Self::SetProduct,
KindEnum::JobFeedback => Self::JobFeedback,
KindEnum::JobRequest { kind } => Self::JobRequest(kind),
KindEnum::JobResult { kind } => Self::JobResult(kind),
KindEnum::InboxRelays => Self::InboxRelays,
KindEnum::MlsKeyPackageRelays => Self::MlsKeyPackageRelays,
KindEnum::MlsKeyPackage => Self::MlsKeyPackage,
KindEnum::MlsWelcome => Self::MlsWelcome,
KindEnum::MlsGroupMessage => Self::MlsGroupMessage,
KindEnum::Torrent => Self::Torrent,
KindEnum::TorrentComment => Self::TorrentComment,
KindEnum::Regular { kind } => Self::Regular(kind),
KindEnum::Replaceable { kind } => Self::Replaceable(kind),
KindEnum::Ephemeral { kind } => Self::Ephemeral(kind),
KindEnum::Custom { kind } => Self::Custom(kind),
}
}
Expand Down
20 changes: 12 additions & 8 deletions crates/nostr/src/event/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ macro_rules! kind_variants {
$name,
)*
/// Represents a job request event (NIP90).
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_job_request` method instead.")]
JobRequest(u16),
/// Represents a job result event (NIP90).
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_job_result` method instead.")]
JobResult(u16),
/// Represents a regular event.
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_regular` method instead.")]
Regular(u16),
/// Represents a replaceable event.
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_replaceable` method instead.")]
Replaceable(u16),
/// Represents an ephemeral event.
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_ephemeral` method instead.")]
Ephemeral(u16),
/// Represents a parameterized replaceable event.
#[deprecated(since = "0.38.0", note = "Use `Custom` variant or `is_addressable` method instead.")]
Expand All @@ -64,11 +69,6 @@ macro_rules! kind_variants {
$(
$value => Self::$name,
)*
x if (NIP90_JOB_REQUEST_RANGE).contains(&x) => Self::JobRequest(x),
x if (NIP90_JOB_RESULT_RANGE).contains(&x) => Self::JobResult(x),
x if (REGULAR_RANGE).contains(&x) => Self::Regular(x),
x if (REPLACEABLE_RANGE).contains(&x) => Self::Replaceable(x),
x if (EPHEMERAL_RANGE).contains(&x) => Self::Ephemeral(x),
x => Self::Custom(x),
}
}
Expand All @@ -80,10 +80,15 @@ macro_rules! kind_variants {
$(
Kind::$name => $value,
)*
#[allow(deprecated)]
Kind::JobRequest(u) => u,
#[allow(deprecated)]
Kind::JobResult(u) => u,
#[allow(deprecated)]
Kind::Regular(u) => u,
#[allow(deprecated)]
Kind::Replaceable(u) => u,
#[allow(deprecated)]
Kind::Ephemeral(u) => u,
#[allow(deprecated)]
Kind::ParameterizedReplaceable(u) => u,
Expand Down Expand Up @@ -177,7 +182,7 @@ kind_variants! {
TorrentComment => 2004, "Torrent Comment (NIP35)",
}

impl PartialEq<Kind> for Kind {
impl PartialEq for Kind {
fn eq(&self, other: &Kind) -> bool {
self.as_u16() == other.as_u16()
}
Expand Down Expand Up @@ -367,8 +372,7 @@ mod tests {

#[test]
fn test_equal_kind() {
assert_eq!(Kind::Custom(20100), Kind::Custom(20100));
assert_eq!(Kind::Custom(20100), Kind::Ephemeral(20100));
assert_eq!(Kind::Custom(20100), Kind::from_u16(20100));
assert_eq!(Kind::TextNote, Kind::Custom(1));
assert_eq!(Kind::Custom(30017), Kind::SetStall);
assert_eq!(Kind::Custom(30018), Kind::SetProduct);
Expand Down

0 comments on commit a7101ba

Please sign in to comment.