add 'created' field to newPeer message for when it's a newly created peer for ui to trigger new peer actions on

pull/329/head
Dan Ballard 2 years ago
parent ca7b5aa677
commit 8d59b3b2e3
  1. 4
      app/app.go
  2. 9
      app/appClient.go
  3. 3
      app/appService.go
  4. 12
      event/common.go

@ -133,7 +133,7 @@ func (app *application) CreateTaggedPeer(name string, password string, tag strin
p.SetAttribute(AttributeTag, tag)
}
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion}))
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: event.True}))
}
// CreatePeer creates a new Peer with the given name and required accessories (eventbus, storage, protocol engine)
@ -221,7 +221,7 @@ func (app *application) LoadProfiles(password string) {
app.storage[profile.Onion] = profileStore
app.engines[profile.Onion] = engine
app.appmutex.Unlock()
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion}))
app.appBus.Publish(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: event.False}))
count++
})
if count == 0 {

@ -45,7 +45,8 @@ func (ac *applicationClient) handleEvent(ev *event.Event) {
key := ev.Data[event.Key]
salt := ev.Data[event.Salt]
reload := ev.Data[event.Status] == event.StorageRunning
ac.newPeer(localID, key, salt, reload)
created := ev.Data[event.Created]
ac.newPeer(localID, key, salt, reload, created)
case event.DeletePeer:
onion := ev.Data[event.Identity]
ac.handleDeletedPeer(onion)
@ -60,7 +61,7 @@ func (ac *applicationClient) handleEvent(ev *event.Event) {
}
}
func (ac *applicationClient) newPeer(localID, key, salt string, reload bool) {
func (ac *applicationClient) newPeer(localID, key, salt string, reload bool, created string) {
var keyBytes [32]byte
var saltBytes [128]byte
copy(keyBytes[:], key)
@ -87,9 +88,9 @@ func (ac *applicationClient) newPeer(localID, key, salt string, reload bool) {
defer ac.peerLock.Unlock()
ac.peers[profile.Onion] = peer
ac.eventBuses[profile.Onion] = eventBus
npEvent := event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion})
npEvent := event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: profile.Onion, event.Created: created})
if reload {
npEvent.Data[event.Status] = "running"
npEvent.Data[event.Status] = event.StorageRunning
}
ac.appBus.Publish(npEvent)

@ -67,6 +67,7 @@ func (as *applicationService) handleEvent(ev *event.Event) {
for _, storage := range as.storage {
peerMsg := *storage.GetNewPeerMessage()
peerMsg.Data[event.Status] = event.StorageRunning
peerMsg.Data[event.Created] = event.False
message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message)
}
@ -116,6 +117,7 @@ func (as *applicationService) createPeer(name, password, tag string) {
as.engines[profile.Onion] = engine
peerMsg := *profileStore.GetNewPeerMessage()
peerMsg.Data[event.Created] = event.True
peerMsg.Data[event.Status] = event.StorageNew
message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message)
@ -135,6 +137,7 @@ func (as *applicationService) loadProfiles(password string) {
as.asmutex.Unlock()
peerMsg := *profileStore.GetNewPeerMessage()
peerMsg.Data[event.Created] = event.False
peerMsg.Data[event.Status] = event.StorageNew
message := event.IPCMessage{Dest: DestApp, Message: peerMsg}
as.bridge.Write(&message)

@ -156,8 +156,8 @@ const (
// ProfileName, Password, Data(tag)
CreatePeer = Type("CreatePeer")
// service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')]
// app -> Key, Salt
// app: Identity(onion), Created(bool)
// service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')], Created(bool)
NewPeer = Type("NewPeer")
// Identity(onion)
@ -233,6 +233,8 @@ const (
Password = Field("Password")
NewPassword = Field("NewPassword")
Created = Field("Created")
ConnectionState = Field("ConnectionState")
Key = Field("Key")
@ -292,3 +294,9 @@ const (
SaveHistoryConfirmed = "SaveHistory"
DeleteHistoryConfirmed = "DeleteHistoryConfirmed"
)
// Bool strings
const (
True = "true"
False = "false"
)
Loading…
Cancel
Save