mirror of
https://github.com/aljazceru/khatru.git
synced 2025-12-17 05:24:22 +01:00
Store and serve delete events
This commit is contained in:
@@ -217,13 +217,17 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
if env.Event.Kind == 5 {
|
||||
// this always returns "blocked: " whenever it returns an error
|
||||
writeErr = srl.handleDeleteRequest(ctx, &env.Event)
|
||||
} else if nostr.IsEphemeralKind(env.Event.Kind) {
|
||||
}
|
||||
|
||||
if writeErr == nil {
|
||||
if nostr.IsEphemeralKind(env.Event.Kind) {
|
||||
// this will also always return a prefixed reason
|
||||
writeErr = srl.handleEphemeral(ctx, &env.Event)
|
||||
} else {
|
||||
// this will also always return a prefixed reason
|
||||
skipBroadcast, writeErr = srl.handleNormal(ctx, &env.Event)
|
||||
}
|
||||
}
|
||||
|
||||
var reason string
|
||||
if writeErr == nil {
|
||||
|
||||
@@ -151,6 +151,7 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
||||
t.Fatalf("failed to publish deletion event: %v", err)
|
||||
}
|
||||
|
||||
{
|
||||
// Try to query the deleted event
|
||||
sub, err := client2.Subscribe(ctx, []nostr.Filter{{
|
||||
IDs: []string{evt3.ID},
|
||||
@@ -162,6 +163,7 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
||||
|
||||
// Should get EOSE without receiving the deleted event
|
||||
gotEvent := false
|
||||
DeletedLoop:
|
||||
for {
|
||||
select {
|
||||
case <-sub.Events:
|
||||
@@ -170,14 +172,43 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
||||
if gotEvent {
|
||||
t.Error("should not have received deleted event")
|
||||
}
|
||||
return
|
||||
break DeletedLoop
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timeout waiting for EOSE")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Try to query the deletion itself
|
||||
sub, err := client2.Subscribe(ctx, []nostr.Filter{{
|
||||
Kinds: []int{5},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to subscribe: %v", err)
|
||||
}
|
||||
defer sub.Unsub()
|
||||
|
||||
// Should get EOSE without receiving the deleted event
|
||||
gotEvent := false
|
||||
DeletionLoop:
|
||||
for {
|
||||
select {
|
||||
case <-sub.Events:
|
||||
gotEvent = true
|
||||
case <-sub.EndOfStoredEvents:
|
||||
if !gotEvent {
|
||||
t.Error("should have received deletion event")
|
||||
}
|
||||
break DeletionLoop
|
||||
case <-ctx.Done():
|
||||
t.Fatal("timeout waiting for EOSE")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// test 4: teplaceable events
|
||||
// test 4: replaceable events
|
||||
t.Run("replaceable events", func(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user