From a2ed058edd387bccba2cbc1efcbd9ff4b469c4ba Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 3 Oct 2018 21:35:30 -0700 Subject: [PATCH] Shortcut for Primary Identity --- app/app.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/app.go b/app/app.go index 054bd40..68332a2 100644 --- a/app/app.go +++ b/app/app.go @@ -19,6 +19,7 @@ type application struct { torManager *tor.Manager directory string mutex sync.Mutex + primaryonion string } // Application is a full cwtch peer application. It allows management, usage and storage of multiple peers @@ -26,6 +27,7 @@ type Application interface { LoadProfiles(password string) error CreatePeer(name string, password string) (peer.CwtchPeer, error) + PrimaryIdentity() peer.CwtchPeer GetPeer(onion string) peer.CwtchPeer ListPeers() map[string]string @@ -100,6 +102,9 @@ func (app *application) LoadProfiles(password string) error { app.startPeer(p) app.mutex.Lock() app.peers[p.GetProfile().Onion] = p + if app.primaryonion == "" { + app.primaryonion = p.GetProfile().Onion + } app.mutex.Unlock() } return nil @@ -148,6 +153,11 @@ func (app *application) ListPeers() map[string]string { return keys } +// PrimaryIdentity returns a Peer for a given onion address +func (app *application) PrimaryIdentity() peer.CwtchPeer { + return app.peers[app.primaryonion] +} + // GetPeer returns a Peer for a given onion address func (app *application) GetPeer(onion string) peer.CwtchPeer { if peer, ok := app.peers[onion]; ok {