Skip to content

Commit ff456bf

Browse files
committed
pool: refine notification sending depending on event database saving status
Send the event notification depending on the `SaveEventStatus` output. Ref #909 (comment) Pull-Request: #911 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent 5f7cba4 commit ff456bf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
### Changed
3737

3838
- nostr: rework `NostrParser` ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/899)
39+
- pool: refine notification sending depending on event database saving status ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/911)
3940

4041
### Added
4142

crates/nostr-relay-pool/src/relay/inner.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ impl InnerRelay {
10931093
}
10941094

10951095
// Check if coordinate has been deleted
1096+
// TODO: remove this since it's checked also later?
10961097
if let Some(coordinate) = event.coordinate() {
10971098
if self
10981099
.state
@@ -1106,7 +1107,7 @@ impl InnerRelay {
11061107

11071108
// TODO: check if filter match
11081109

1109-
// Check if event exists
1110+
// Check if the event exists
11101111
if let DatabaseEventStatus::NotExistent = status {
11111112
// Check if the event was already verified.
11121113
//
@@ -1121,7 +1122,23 @@ impl InnerRelay {
11211122
}
11221123

11231124
// Save into the database
1124-
self.state.database().save_event(&event).await?;
1125+
let send_notification: bool = match self.state.database().save_event(&event).await? {
1126+
SaveEventStatus::Success => true,
1127+
SaveEventStatus::Rejected(reason) => match reason {
1128+
RejectedReason::Ephemeral => true,
1129+
RejectedReason::Duplicate => true,
1130+
RejectedReason::Deleted => false,
1131+
RejectedReason::Expired => false,
1132+
RejectedReason::Replaced => false,
1133+
RejectedReason::InvalidDelete => false,
1134+
RejectedReason::Other => true,
1135+
},
1136+
};
1137+
1138+
// If the notification should NOT be sent, immediately return.
1139+
if !send_notification {
1140+
return Ok(None);
1141+
}
11251142

11261143
// Send notification
11271144
self.send_notification(

0 commit comments

Comments
 (0)