Minor updates to take avantage of additional events from the cwtch app and API changes
This commit is contained in:
parent
007e485e76
commit
18b9cc41e0
|
@ -0,0 +1,98 @@
|
||||||
|
package characters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cwtch.im/cwtch/event"
|
||||||
|
"cwtch.im/ui/go/cwutil"
|
||||||
|
"cwtch.im/ui/go/gobjects"
|
||||||
|
"cwtch.im/ui/go/gothings"
|
||||||
|
"cwtch.im/ui/go/the"
|
||||||
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
|
q := event.NewEventQueue(1000)
|
||||||
|
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
|
||||||
|
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
|
||||||
|
the.AppBus.Subscribe(event.AppError, q.EventChannel)
|
||||||
|
|
||||||
|
for {
|
||||||
|
e := q.Next()
|
||||||
|
|
||||||
|
switch e.EventType {
|
||||||
|
case event.PeerError:
|
||||||
|
// current only case
|
||||||
|
log.Errorf("couldn't load profiles: %v", e.Data[event.Error])
|
||||||
|
os.Exit(1)
|
||||||
|
|
||||||
|
case event.AppError:
|
||||||
|
|
||||||
|
if e.Data[event.Error] == event.AppErrLoaded0 {
|
||||||
|
log.Infoln("couldn't load your config file. attempting to create one now")
|
||||||
|
|
||||||
|
the.CwtchApp.CreatePeer("alice", "be gay do crime")
|
||||||
|
}
|
||||||
|
|
||||||
|
case event.NewPeer:
|
||||||
|
if the.Peer != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
onion := e.Data[event.Identity]
|
||||||
|
|
||||||
|
the.Peer = the.CwtchApp.GetPeer(onion)
|
||||||
|
the.EventBus = the.CwtchApp.GetEventBus(onion)
|
||||||
|
|
||||||
|
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))
|
||||||
|
the.CwtchApp.LaunchPeers()
|
||||||
|
|
||||||
|
contacts := the.Peer.GetContacts()
|
||||||
|
for i := range contacts {
|
||||||
|
contact, _ := the.Peer.GetProfile().GetContact(contacts[i])
|
||||||
|
displayName, _ := contact.GetAttribute("nick")
|
||||||
|
deleted, _ := contact.GetAttribute("deleted")
|
||||||
|
if deleted != "deleted" {
|
||||||
|
gcd.UIState.AddContact(&gobjects.Contact{
|
||||||
|
Handle: contacts[i],
|
||||||
|
DisplayName: displayName,
|
||||||
|
Image: cwutil.RandomProfileImage(contacts[i]),
|
||||||
|
Trusted: contact.Trusted,
|
||||||
|
Loading: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groups := the.Peer.GetGroups()
|
||||||
|
for i := range groups {
|
||||||
|
group := the.Peer.GetGroup(groups[i])
|
||||||
|
nick, exists := group.GetAttribute("nick")
|
||||||
|
if !exists {
|
||||||
|
nick = group.GroupID[:12]
|
||||||
|
}
|
||||||
|
deleted, _ := group.GetAttribute("deleted")
|
||||||
|
// Only join servers for active and explicitly accepted groups.
|
||||||
|
if deleted != "deleted" {
|
||||||
|
|
||||||
|
gcd.UIState.AddContact(&gobjects.Contact{
|
||||||
|
Handle: group.GroupID,
|
||||||
|
DisplayName: nick,
|
||||||
|
Image: cwutil.RandomGroupImage(group.GroupID),
|
||||||
|
Server: group.GroupServer,
|
||||||
|
Trusted: group.Accepted,
|
||||||
|
Loading: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go IncomingListener(&gcd.UIState)
|
||||||
|
go TorStatusPoller(gcd.TorStatus, the.ACN)
|
||||||
|
go PresencePoller(&gcd.UIState)
|
||||||
|
|
||||||
|
// load ui preferences
|
||||||
|
gcd.RequestSettings()
|
||||||
|
locale, exists := the.Peer.GetProfile().GetAttribute("settings.locale")
|
||||||
|
if exists {
|
||||||
|
gcd.SetLocale_helper(locale)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,7 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var CwtchApp app.Application
|
var CwtchApp app.Application
|
||||||
var EventBus *event.Manager
|
var EventBus event.Manager
|
||||||
|
var AppBus event.Manager
|
||||||
var ACN connectivity.ACN
|
var ACN connectivity.ACN
|
||||||
var Peer libPeer.CwtchPeer
|
var Peer libPeer.CwtchPeer
|
||||||
var CwtchDir string
|
var CwtchDir string
|
||||||
|
|
92
main.go
92
main.go
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
libapp "cwtch.im/cwtch/app"
|
libapp "cwtch.im/cwtch/app"
|
||||||
"cwtch.im/ui/go/characters"
|
"cwtch.im/ui/go/characters"
|
||||||
"cwtch.im/ui/go/cwutil"
|
|
||||||
"cwtch.im/ui/go/gobjects"
|
"cwtch.im/ui/go/gobjects"
|
||||||
"cwtch.im/ui/go/gothings"
|
"cwtch.im/ui/go/gothings"
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
|
@ -165,92 +164,11 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are long-lived pollers/listeners for incoming messages and status changes
|
the.Peer = nil
|
||||||
loadCwtchData(gcd, the.ACN)
|
|
||||||
go characters.IncomingListener(&gcd.UIState)
|
|
||||||
go characters.TorStatusPoller(gcd.TorStatus, the.ACN)
|
|
||||||
go characters.PresencePoller(&gcd.UIState)
|
|
||||||
|
|
||||||
// load ui preferences
|
|
||||||
gcd.RequestSettings()
|
|
||||||
locale, exists := the.Peer.GetProfile().GetAttribute("settings.locale")
|
|
||||||
if exists {
|
|
||||||
gcd.SetLocale_helper(locale)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is mostly going to get factored out when we add profile support
|
|
||||||
// for now, it loads a single peer and fills the ui with its data
|
|
||||||
func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
/*_, err := app2.NewApp(dirname, "/data/data/org.qtproject.example.go/lib/libtor.so")
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("ERROR CREATING CWTCH APP: %v", err)
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second * 10)
|
|
||||||
*/
|
|
||||||
os.MkdirAll(the.CwtchDir, 0700)
|
os.MkdirAll(the.CwtchDir, 0700)
|
||||||
|
|
||||||
the.CwtchApp = libapp.NewApp(acn, the.CwtchDir)
|
the.CwtchApp = libapp.NewApp(the.ACN, the.CwtchDir)
|
||||||
|
the.AppBus = the.CwtchApp.GetPrimaryBus()
|
||||||
err = the.CwtchApp.LoadProfiles("be gay do crime")
|
go characters.AppEventListener(gcd)
|
||||||
if err != nil {
|
the.CwtchApp.LoadProfiles("be gay do crime")
|
||||||
//TODO no more fatalfs
|
|
||||||
log.Errorf("couldn't load profiles: %v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(the.CwtchApp.ListPeers()) == 0 {
|
|
||||||
log.Infoln("couldn't load your config file. attempting to create one now")
|
|
||||||
the.Peer, err = the.CwtchApp.CreatePeer("alice", "be gay do crime")
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("couldn't create one. is your cwtch folder writable?")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
the.Peer = the.CwtchApp.PrimaryIdentity()
|
|
||||||
}
|
|
||||||
the.EventBus = the.CwtchApp.GetEventBus(the.Peer.GetProfile().Onion)
|
|
||||||
|
|
||||||
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))
|
|
||||||
the.CwtchApp.LaunchPeers()
|
|
||||||
|
|
||||||
contacts := the.Peer.GetContacts()
|
|
||||||
for i := range contacts {
|
|
||||||
contact, _ := the.Peer.GetProfile().GetContact(contacts[i])
|
|
||||||
displayName, _ := contact.GetAttribute("nick")
|
|
||||||
deleted, _ := contact.GetAttribute("deleted")
|
|
||||||
if deleted != "deleted" {
|
|
||||||
gcd.UIState.AddContact(&gobjects.Contact{
|
|
||||||
Handle: contacts[i],
|
|
||||||
DisplayName: displayName,
|
|
||||||
Image: cwutil.RandomProfileImage(contacts[i]),
|
|
||||||
Trusted: contact.Trusted,
|
|
||||||
Loading: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groups := the.Peer.GetGroups()
|
|
||||||
for i := range groups {
|
|
||||||
group := the.Peer.GetGroup(groups[i])
|
|
||||||
nick, exists := group.GetAttribute("nick")
|
|
||||||
if !exists {
|
|
||||||
nick = group.GroupID[:12]
|
|
||||||
}
|
|
||||||
deleted, _ := group.GetAttribute("deleted")
|
|
||||||
// Only join servers for active and explicitly accepted groups.
|
|
||||||
if deleted != "deleted" {
|
|
||||||
|
|
||||||
gcd.UIState.AddContact(&gobjects.Contact{
|
|
||||||
Handle: group.GroupID,
|
|
||||||
DisplayName: nick,
|
|
||||||
Image: cwutil.RandomGroupImage(group.GroupID),
|
|
||||||
Server: group.GroupServer,
|
|
||||||
Trusted: group.Accepted,
|
|
||||||
Loading: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue