Skip to content

Commit

Permalink
Make sure nicks are unique.
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Apr 7, 2024
1 parent 0ad6459 commit 52d4979
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions entity/nicks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (e Entity) Nick() string {
// takes new did and nick. If an old did for the alias exists it is removed.
// This makes this the only alias for the DID and the only complex function in this file.
func (e Entity) SetNick(nick string) error {

// Delete the nick if it exist.
DeleteNick(Lookup(nick))

nicks.Store(e.DID.Id, nick)
return db.Save(nicks, config.DBEntities())
}
Expand Down
7 changes: 5 additions & 2 deletions p2p/peer/nicks.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ func Nicks() map[string]string {

// SetNick updates or sets a new nick for a given peer ID.
func SetNick(id, nick string) error {

// Nicks must be unique, so delete any old ones.
DeleteNick(Lookup(nick))

nicks.Store(id, nick)
filename := config.DBPeers()
return db.Save(nicks, filename)
return db.Save(nicks, config.DBPeers())
}

func WatchCSV() error {
Expand Down

0 comments on commit 52d4979

Please sign in to comment.