mirror of
https://github.com/aljazceru/khatru.git
synced 2025-12-18 14:04: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 {
|
if env.Event.Kind == 5 {
|
||||||
// this always returns "blocked: " whenever it returns an error
|
// this always returns "blocked: " whenever it returns an error
|
||||||
writeErr = srl.handleDeleteRequest(ctx, &env.Event)
|
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
|
// this will also always return a prefixed reason
|
||||||
writeErr = srl.handleEphemeral(ctx, &env.Event)
|
writeErr = srl.handleEphemeral(ctx, &env.Event)
|
||||||
} else {
|
} else {
|
||||||
// this will also always return a prefixed reason
|
// this will also always return a prefixed reason
|
||||||
skipBroadcast, writeErr = srl.handleNormal(ctx, &env.Event)
|
skipBroadcast, writeErr = srl.handleNormal(ctx, &env.Event)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var reason string
|
var reason string
|
||||||
if writeErr == nil {
|
if writeErr == nil {
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
|||||||
t.Fatalf("failed to publish deletion event: %v", err)
|
t.Fatalf("failed to publish deletion event: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
// Try to query the deleted event
|
// Try to query the deleted event
|
||||||
sub, err := client2.Subscribe(ctx, []nostr.Filter{{
|
sub, err := client2.Subscribe(ctx, []nostr.Filter{{
|
||||||
IDs: []string{evt3.ID},
|
IDs: []string{evt3.ID},
|
||||||
@@ -162,6 +163,7 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
|||||||
|
|
||||||
// Should get EOSE without receiving the deleted event
|
// Should get EOSE without receiving the deleted event
|
||||||
gotEvent := false
|
gotEvent := false
|
||||||
|
DeletedLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-sub.Events:
|
case <-sub.Events:
|
||||||
@@ -170,14 +172,43 @@ func TestBasicRelayFunctionality(t *testing.T) {
|
|||||||
if gotEvent {
|
if gotEvent {
|
||||||
t.Error("should not have received deleted event")
|
t.Error("should not have received deleted event")
|
||||||
}
|
}
|
||||||
return
|
break DeletedLoop
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
t.Fatal("timeout waiting for EOSE")
|
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) {
|
t.Run("replaceable events", func(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user