threadv2: refactor handle_event logic
This commit is contained in:
@@ -84,22 +84,12 @@ struct BuildThreadV2View: View {
|
|||||||
return sub_id
|
return sub_id
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle_event(relay_id: String, ev: NostrConnectionEvent) {
|
func handle_current_events(ev: NostrEvent) {
|
||||||
guard case .nostr_event(let nostr_response) = ev else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard case .event(let id, let nostr_event) = nostr_response else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is current event
|
|
||||||
if id == current_events_uuid {
|
|
||||||
if current_event != nil {
|
if current_event != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
current_event = nostr_event
|
current_event = ev
|
||||||
|
|
||||||
thread = ThreadV2(
|
thread = ThreadV2(
|
||||||
parentEvents: [],
|
parentEvents: [],
|
||||||
@@ -136,11 +126,10 @@ struct BuildThreadV2View: View {
|
|||||||
)
|
)
|
||||||
childs_events_uuid = subscribe(filters: [childs_events])
|
childs_events_uuid = subscribe(filters: [childs_events])
|
||||||
print("ThreadV2View: Ask for children (\(childs_events) (\(childs_events_uuid))")
|
print("ThreadV2View: Ask for children (\(childs_events) (\(childs_events_uuid))")
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if parents_events_uuids.contains(id) {
|
func handle_parent_events(sub_id: String, nostr_event: NostrEvent) {
|
||||||
|
|
||||||
// We are filtering this later
|
// We are filtering this later
|
||||||
thread!.parentEvents.append(nostr_event)
|
thread!.parentEvents.append(nostr_event)
|
||||||
|
|
||||||
@@ -170,7 +159,28 @@ struct BuildThreadV2View: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
thread!.clean()
|
thread!.clean()
|
||||||
unsubscribe(id)
|
unsubscribe(sub_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle_event(relay_id: String, ev: NostrConnectionEvent) {
|
||||||
|
guard case .nostr_event(let nostr_response) = ev else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard case .event(let id, let nostr_event) = nostr_response else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is current event
|
||||||
|
if id == current_events_uuid {
|
||||||
|
handle_current_events(ev: nostr_event)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if parents_events_uuids.contains(id) {
|
||||||
|
handle_parent_events(sub_id: id, nostr_event: nostr_event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user