Launch Peers on NewPeer + Set Name
This commit is contained in:
parent
e1d4eed7ac
commit
8072496afe
11
lib.go
11
lib.go
|
@ -40,6 +40,8 @@ func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) {
|
|||
|
||||
func StartCwtch(appDir string, torPath string) {
|
||||
log.SetLevel(log.LevelInfo)
|
||||
|
||||
// Exclude Tapir wire Messages (We need a TRACE level)
|
||||
log.ExcludeFromPattern("service.go")
|
||||
|
||||
utils.InitGlobalSettingsFile(appDir, "be gay do crime")
|
||||
|
@ -93,8 +95,10 @@ func StartCwtch(appDir string, torPath string) {
|
|||
newApp.LoadProfiles("be gay do crime")
|
||||
newApp.LaunchPeers()
|
||||
application = newApp
|
||||
|
||||
// Send global settings to the UI...
|
||||
application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
||||
log.Infof("libcwtch-go application SET\n")
|
||||
log.Infof("libcwtch-go application launched")
|
||||
}
|
||||
|
||||
//export c_ACNEvents
|
||||
|
@ -188,6 +192,11 @@ func SendProfileEvent(onion string, eventJson string) {
|
|||
peer.SetContactAttribute(new_event.Data[event.RemotePeer], new_event.Data[event.Key], new_event.Data[event.Data])
|
||||
case event.SetPeerAuthorization:
|
||||
peer.SetContactAuthorization(new_event.Data[event.RemotePeer], model.Authorization(new_event.Data[event.Authorization]))
|
||||
|
||||
// If approved (e.g. after an unblock) we want to kick off peering again...
|
||||
if model.Authorization(new_event.Data[event.Authorization]) == model.AuthApproved {
|
||||
peer.PeerWithOnion(new_event.Data[event.RemotePeer])
|
||||
}
|
||||
case event.SendMessageToGroup:
|
||||
// TODO Uncomment and integrate once contacts/messages are loaded.
|
||||
//groupHandler,err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"cwtch.im/cwtch/protocol/connections"
|
||||
"encoding/json"
|
||||
"git.openprivacy.ca/flutter/libcwtch-go/constants"
|
||||
"git.openprivacy.ca/flutter/libcwtch-go/features/groups"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
)
|
||||
import "cwtch.im/cwtch/event"
|
||||
|
@ -50,12 +51,14 @@ func (eh *EventHandler) GetNextEvent() string {
|
|||
|
||||
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
||||
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||
log.Debugf("New Profile Event: %v", e)
|
||||
switch e.EventType {
|
||||
case event.NewPeer:
|
||||
onion := e.Data[event.Identity]
|
||||
profile := eh.app.GetPeer(e.Data[event.Identity])
|
||||
|
||||
log.Debug("New Peer Event: %v", e)
|
||||
eh.startHandlingPeer(onion)
|
||||
profile.StartPeersConnections()
|
||||
|
||||
if e.Data[event.Created] == event.True {
|
||||
profile.SetAttribute(attr.GetPublicScope(constants.Name), profile.GetName())
|
||||
|
@ -65,6 +68,13 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
profile.SetAttribute(attr.GetLocalScope(constants.PeerOnline), event.False)
|
||||
eh.app.AddPeerPlugin(onion, plugins.CONNECTIONRETRY)
|
||||
eh.app.AddPeerPlugin(onion, plugins.NETWORKCHECK)
|
||||
|
||||
// Start up the Profile
|
||||
profile.Listen()
|
||||
profile.StartPeersConnections()
|
||||
if _, err := groups.ExperimentGate(ReadGlobalSettings().Experiments); err == nil {
|
||||
profile.StartServerConnections()
|
||||
}
|
||||
}
|
||||
|
||||
nick, exists := profile.GetAttribute(attr.GetPublicScope(constants.Name))
|
||||
|
@ -106,12 +116,15 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
}
|
||||
cpicPath := GetPicturePath(cpic)
|
||||
contactInfo := profile.GetContact(contact)
|
||||
name, _ := contactInfo.GetAttribute(attr.GetLocalScope(constants.Name))
|
||||
name, hasName := contactInfo.GetAttribute(attr.GetLocalScope(constants.Name))
|
||||
if !hasName {
|
||||
name = contactInfo.Name
|
||||
}
|
||||
saveHistory, set := contactInfo.GetAttribute(event.SaveHistoryKey)
|
||||
if !set {
|
||||
saveHistory = event.DeleteHistoryDefault
|
||||
}
|
||||
contacts = append(contacts, Contact{Name: name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath, Authorization: string(contactInfo.Authorization), SaveHistory: saveHistory, Messages: contactInfo.Timeline.Len(), Unread: 0,})
|
||||
contacts = append(contacts, Contact{Name: name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath, Authorization: string(contactInfo.Authorization), SaveHistory: saveHistory, Messages: contactInfo.Timeline.Len(), Unread: 0})
|
||||
}
|
||||
|
||||
bytes, _ := json.Marshal(contacts)
|
||||
|
@ -128,7 +141,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
|
||||
peer := eh.app.GetPeer(ev.Profile)
|
||||
ph := NewPeerHelper(peer)
|
||||
|
||||
log.Debugf("New Profile Event: %v", ev)
|
||||
switch ev.Event.EventType {
|
||||
|
||||
/*case event.NetworkStatus:
|
||||
|
|
Loading…
Reference in New Issue