Skip to content

Commit

Permalink
Fix entity delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 17, 2024
1 parent d12a91d commit 590f000
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 2 additions & 4 deletions entity/nicks.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ func Lookup(name string) string {
return id
}

// Removes a node from the database if it exists
func RemoveNick(id string) error {

id = GetDID(id) // Check if the reuested ID is a nick
// Removes a node from the database if it exists. Must be a DID
func Delete(id string) error {

d, err := db.Get()
if err != nil {
Expand Down
9 changes: 3 additions & 6 deletions p2p/pubsub/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ package pubsub

import (
p2pubsub "github.com/libp2p/go-libp2p-pubsub"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
)

const PUBSUB_PROTOCOL = "/meshsub/1.1.0"

var r *pubsub.GossipSubRouter
var r *p2pubsub.GossipSubRouter

func newRouter(h host.Host) *pubsub.GossipSubRouter {
func newRouter(h host.Host) *p2pubsub.GossipSubRouter {

r = p2pubsub.DefaultGossipSubRouter(h)

return r
return p2pubsub.DefaultGossipSubRouter(h)
}

// Adds a peer ID to the GossipSubRouter
Expand Down
20 changes: 10 additions & 10 deletions ui/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
entityUsage = "/entity list|nick|resolve|show"
entityUsage = "/entity delete|list|nick|resolve|show"
entityHelp = "Manages info on seen entities"
entityConnectUsage = "/entity connect <id|nick>"
entityConnectHelp = "Connects to an entity's libp2p node"
Expand All @@ -21,8 +21,8 @@ const (
The entity to set nick for *MUST* be quoted if it contains spaces.
The nick after the entity to set nick for doesn't need to be quoted.
`
entityRemoveUsage = "/entity remove <id|nick>"
entityRemoveHelp = "Removes an entity from the database"
entityDeleteUsage = "/entity delete <id|nick>"
entityDeleteHelp = "Deletes an entity from the database"
entityResolveUsage = "/entity resolve <DID|NICK>"
entityResolveHelp = "Tries to resolve the most recent version of the DID Document for the given DID or NICK."
entityShowUsage = "/entity show <id|nick>"
Expand All @@ -38,6 +38,9 @@ func (ui *ChatUI) handleEntityCommand(args []string) {
case "connect":
ui.handleEntityConnectCommand(args)
return
case "delete":
ui.handleEntityDeleteCommand(args)
return
case "list":
ui.handleEntityListCommand(args)
return
Expand All @@ -47,9 +50,6 @@ func (ui *ChatUI) handleEntityCommand(args []string) {
case "resolve":
go ui.handleEntityResolveCommand(args) // This make take some time. No need to block the UI
return
case "remove":
ui.handleEntityRemoveCommand(args)
return
case "show":
ui.handleEntityShowCommand(args)
return
Expand Down Expand Up @@ -128,16 +128,16 @@ func (ui *ChatUI) handleEntityShowCommand(args []string) {
}

// REMOVE
func (ui *ChatUI) handleEntityRemoveCommand(args []string) {
func (ui *ChatUI) handleEntityDeleteCommand(args []string) {

if len(args) >= 3 {
id := strings.Join(args[2:], separator)
id = entity.Lookup(id)
entity.RemoveNick(id)
ui.displaySystemMessage("Nick removed for " + id + " if it existed")
entity.Delete(id)
ui.displaySystemMessage("Nick deleted for " + id + " if it existed")
return
}
ui.handleHelpCommand(entityRemoveUsage, entityRemoveHelp)
ui.handleHelpCommand(entityDeleteUsage, entityDeleteHelp)

}

Expand Down

0 comments on commit 590f000

Please sign in to comment.