Skip to content

Commit

Permalink
Fix statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Feb 22, 2024
1 parent a844071 commit d5dee96
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
18 changes: 8 additions & 10 deletions ui/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ func (ui *ChatUI) startActor() {
go ui.handleIncomingEnvelopes(ctx, ui.a.Entity, ui.a)
go ui.handleIncomingMessages(ctx, ui.a.Entity)

// Now create a self entity.
// me, err := entity.NewFromDID(ui.a.Entity.DID.Id)

greeting := []byte("Hello, world! " + ui.a.Entity.DID.Fragment + " is here.")
mesg, err := msg.NewBroadcast(ui.a.Entity.DID.Id, greeting, "text/plain", ui.a.Keyset.SigningKey.PrivKey)
if err != nil {
ui.displaySystemMessage("Error creating greeting message: " + err.Error())
if ui.b != nil {
greeting := []byte("Hello, world! " + ui.a.Entity.DID.Id + " is here.")
mesg, err := msg.NewBroadcast(ui.a.Entity.DID.Id, greeting, "text/plain", ui.a.Keyset.SigningKey.PrivKey)
if err != nil {
ui.displaySystemMessage("Error creating greeting message: " + err.Error())
}

mesg.Broadcast(ctx, ui.b)
}

mesg.Broadcast(ctx, ui.a.Entity.Topic)

}
2 changes: 1 addition & 1 deletion ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func (ui *ChatUI) handleHelpQuitCommand(args []string) {
}

func (ui *ChatUI) handleHelpUnknownCommand(args []string) {
ui.displaySystemMessage("Unknown command: " + args[0])
ui.displaySystemMessage("Unknown command: " + args[1])
}
28 changes: 18 additions & 10 deletions ui/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import (
)

func (ui *ChatUI) handleStatusCommand(args []string) {
if len(args) > 1 {

if len(args) == 1 {
ui.displaySystemMessage(ui.getStatusHost())
ui.displaySystemMessage(ui.getStatusTopic())
return
}

if len(args) == 2 {
switch args[1] {
case "sub":
ui.displayStatusMessage(ui.getStatusSub())
Expand All @@ -16,9 +23,10 @@ func (ui *ChatUI) handleStatusCommand(args []string) {
default:
ui.displaySystemMessage("Unknown status type: " + args[1])
}
} else {
ui.handleHelpStatusCommands(args)
return
}

ui.handleHelpStatusCommands(args)
}

// displayStatusMessage writes a status message to the message window.
Expand All @@ -37,24 +45,24 @@ func (ui *ChatUI) getStatusTopic() string {
// peers := ui.keyAgreement.ListPeers()
aConnected := ui.a.Entity.Topic.ListPeers()
eConnected := ui.e.Topic.ListPeers()
return fmt.Sprintf("\nEntity: %s\n%s\nActor: %s\n%s",
bConnected := ui.b.ListPeers()
return fmt.Sprintf("\nEntity: %s\n%s\nActor: %s\n%s\nBroadcast: %s\n%s",
ui.e.Topic.String(), eConnected[:],
ui.a.Entity.Topic.String(), aConnected[:])
ui.a.Entity.Topic.String(), aConnected[:],
ui.b.String(), bConnected[:],
)
}

func (ui *ChatUI) getStatusHost() string {
// Return whatever status you'd like about the host.
// Just an example below:
var result string
result += "Peer ID: " + ui.p.Node.ID().String() + "\n"
result += "Peers:\n"
for _, p := range ui.p.Node.Network().Peers() {
result += p.String() + "\n"
}
result += fmt.Sprintf("Peers no# %d\n", len(ui.p.Node.Network().Peers()))
return result
}

func (ui *ChatUI) handleHelpStatusCommands(args []string) {
ui.displaySystemMessage("Usage: /status")
ui.displaySystemMessage("Usage: /status topics|host")
ui.displaySystemMessage("Displays the current status of the chat client")
}
4 changes: 3 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ func (ui *ChatUI) Run() error {

defer ui.end()

// STart the broadcast subscription first, so
// actors can announce themselves.
go ui.initBroadcast()
// The actor should just run in the background for ever.
// It will handle incoming messages and envelopes.
// It shouldn't change - ever.
go ui.startActor()
go ui.initBroadcast()

// We must wait for this to finish.
err := ui.enterEntity(config.GetHome(), true)
Expand Down

0 comments on commit d5dee96

Please sign in to comment.