add relay logging (#1263)

This PR adds relay logging to the RelayDetailView.

Features:

* list of events, most recent at the top

* shows changes to RelayConnection's state

* shows changes to network state

* RelayDetailView updates live as lines are added to the log

* logs persisted to disk for later investigation

* line limit prevents unbounded file growth

Here's how it looks when resuming after having the app in the background for a while and the relays need to reconnect:

![relay-log](https://github.com/damus-io/damus/assets/445882/fd788aae-ed44-49c5-9dd1-4e6c7398456e)

relays, 5 commits

https://github.com/damus-io/damus/pull/1263

Reply to this note

Please Login to reply.

Discussion

Here’s how that will look:

nostr:npub1qlk0nqupxmlyxravg0aqscxmcc4q4tq898z6x003rykwwh3npj0syvyayc nice! Some comments:

> diff --git a/damus/Views/Relays/RelayDetailView.swift b/damus/Views/Relays/RelayDetailView.swift

> index c53bc123..7606799d 100644

> --- a/damus/Views/Relays/RelayDetailView.swift

> +++ b/damus/Views/Relays/RelayDetailView.swift

> @@ -12,8 +12,18 @@ struct RelayDetailView: View {

> let relay: String

> let nip11: RelayMetadata

>

> + @StateObject var log: RelayLog

I'm not sure this will work as a StateObject. When the view disappears,

RelayLog will get deallocated and the writeToDisk callbacks will be

deallocated as well.

Ideally we would create a RelayModel that would replace the

RelayMetadata in RelayMetadatas. Then the RelayModel would contain

RelayMetadata, RelayLog, etc. Composing multiple ObservableObjects into

one is a bit annoying so perhaps we can move some of the publisher stuff

into the RelayModel instead.

Made the requested changes to this PR. A new object called RelayModel now owns the log and the RelayMetadata. The log is now an ObservedObject of the view rather than a StateObject.

Perfect! Will review again soon