fix: serve partial redacted results, but reply with "auth-required" if any redactions happened

This commit is contained in:
Mike Dilger 2025-02-21 10:17:59 +13:00
parent f1851e793b
commit e7044ad0db
No known key found for this signature in database
GPG Key ID: 47581A78D4329BA4
2 changed files with 15 additions and 24 deletions

View File

@ -180,19 +180,6 @@ impl WebSocketService {
redacted = redacted || was_redacted;
}
// New policy Feb 2025: Redactions trigger a "CLOSED: auth-required" because
// some clients will not AUTH otherwise.
if redacted {
// They need to AUTH first
let reply = NostrReply::Closed(
subid,
NostrReplyPrefix::AuthRequired,
"At least one matching event requires AUTH".to_owned(),
);
self.send(Message::text(reply.as_json())).await?;
return Ok(());
}
// sort
events.sort_by_key(|e| std::cmp::Reverse(e.created_at()));
@ -219,17 +206,23 @@ impl WebSocketService {
self.send(Message::text(reply.as_json())).await?;
}
// New policy Feb 2025: Redactions trigger a "CLOSED: auth-required" because
// some clients will not AUTH otherwise.
// (But we also already sent partial results, which I think is good)
if redacted {
// They need to AUTH first
let reply = NostrReply::Closed(
subid,
NostrReplyPrefix::AuthRequired,
"At least one matching event requires AUTH".to_owned(),
);
self.send(Message::text(reply.as_json())).await?;
return Ok(());
}
if completes {
// Closed
let reply = if redacted {
NostrReply::Closed(
subid,
NostrReplyPrefix::Redacted,
"Some matching events could not be served to you.".to_owned(),
)
} else {
NostrReply::Closed(subid, NostrReplyPrefix::None, "".to_owned())
};
let reply = NostrReply::Closed(subid, NostrReplyPrefix::None, "".to_owned());
self.send(Message::text(reply.as_json())).await?;
} else {
// EOSE

View File

@ -9,7 +9,6 @@ pub enum NostrReplyPrefix {
Duplicate,
Blocked,
RateLimited,
Redacted,
Restricted,
Invalid,
Error,
@ -24,7 +23,6 @@ impl fmt::Display for NostrReplyPrefix {
NostrReplyPrefix::Duplicate => write!(f, "duplicate: "),
NostrReplyPrefix::Blocked => write!(f, "blocked: "),
NostrReplyPrefix::RateLimited => write!(f, "rate-limited: "),
NostrReplyPrefix::Redacted => write!(f, "redacted: "),
NostrReplyPrefix::Restricted => write!(f, "restricted: "),
NostrReplyPrefix::Invalid => write!(f, "invalid: "),
NostrReplyPrefix::Error => write!(f, "error: "),