createProfile return onion if possible; add attribute for private name

This commit is contained in:
Dan Ballard 2024-06-14 12:41:42 -07:00 committed by Dan Ballard
parent 3e09a25b2d
commit d5145c631d
2 changed files with 12 additions and 5 deletions

View File

@ -53,7 +53,7 @@ func (app *application) IsFeatureEnabled(experiment string) bool {
// Application is a full cwtch peer application. It allows management, usage and storage of multiple peers
type Application interface {
LoadProfiles(password string)
CreateProfile(name string, password string, autostart bool)
CreateProfile(name string, password string, autostart bool) string
InstallEngineHooks(engineHooks connections.EngineHooks)
ImportProfile(exportedCwtchFile string, password string) (peer.CwtchPeer, error)
EnhancedImportProfile(exportedCwtchFile string, password string) string
@ -197,7 +197,7 @@ func (app *application) AddPlugin(peerid string, id plugins.PluginID, bus event.
}
}
func (app *application) CreateProfile(name string, password string, autostart bool) {
func (app *application) CreateProfile(name string, password string, autostart bool) string {
autostartVal := constants.True
if !autostart {
autostartVal = constants.False
@ -207,10 +207,15 @@ func (app *application) CreateProfile(name string, password string, autostart bo
tagVal = constants.ProfileTypeV1DefaultPassword
}
app.CreatePeer(name, password, map[attr.ZonedPath]string{
profile_id, err := app.CreatePeer(name, password, map[attr.ZonedPath]string{
attr.ProfileZone.ConstructZonedPath(constants.Tag): tagVal,
attr.ProfileZone.ConstructZonedPath(constants.PeerAutostart): autostartVal,
})
if err == nil {
return profile_id
}
return ""
}
func (app *application) setupPeer(profile peer.CwtchPeer) {
@ -232,7 +237,7 @@ func (app *application) setupPeer(profile peer.CwtchPeer) {
}
func (app *application) CreatePeer(name string, password string, attributes map[attr.ZonedPath]string) {
func (app *application) CreatePeer(name string, password string, attributes map[attr.ZonedPath]string) (string, error) {
app.appmutex.Lock()
defer app.appmutex.Unlock()
@ -242,7 +247,7 @@ func (app *application) CreatePeer(name string, password string, attributes map[
if err != nil {
log.Errorf("Error Creating Peer: %v", err)
app.appBus.Publish(event.NewEventList(event.PeerError, event.Error, err.Error()))
return
return "", err
}
app.setupPeer(profile)
@ -253,6 +258,7 @@ func (app *application) CreatePeer(name string, password string, attributes map[
}
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.GetOnion(), event.Created: event.True}))
return profile.GetOnion(), nil
}
func (app *application) DeleteProfile(onion string, password string) {

View File

@ -58,6 +58,7 @@ const SyncMostRecentMessageTime = "SyncMostRecentMessageTime"
const AttrLastConnectionTime = "last-connection-time"
const PeerAutostart = "autostart"
const PeerAppearOffline = "appear-offline"
const PrivateName = "private-name"
const Archived = "archived"
const ProfileStatus = "profile-status"