Merge branch 'fixGroupInvite' of dan/ui into master
the build was successful Details

This commit is contained in:
erinn 2019-09-20 14:29:06 -07:00 committed by Gogs
commit 1ef634d25d
5 changed files with 35 additions and 49 deletions

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.12
require (
cwtch.im/cwtch v0.2.1-pr-1
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6
github.com/golang/protobuf v1.3.2
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect

View File

@ -78,7 +78,6 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool
incSubscribed := make(chan bool)
go IncomingListener(&gcd.UIState, incSubscribed)
<-incSubscribed
go PresencePoller(&gcd.UIState)
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))

View File

@ -77,7 +77,18 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
DisplayName: name,
})
case event.NewGroupInvite:
log.Debugf("got a group invite!")
gid, err := the.Peer.GetProfile().ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
group := the.Peer.GetGroup(gid)
if err == nil && group != nil {
uiState.AddContact(&gobjects.Contact{
Handle: gid,
DisplayName: gid,
Image: cwutil.RandomGroupImage(gid),
Server: group.GroupServer,
Trusted: false,
Loading: false,
})
}
case event.SendMessageToGroupError:
uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
case event.SendMessageToPeerError:
@ -85,6 +96,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
case event.PeerStateChange:
cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
// if it's not in the.Peer it's new. Only add once Authed
_, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]
if !exists {
// Contact does not exist, we will add them but we won't know who they are until they are authenticated
@ -95,11 +107,27 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
}
}
// if it's in the.Peer its either existing and needs an update or not in the UI and needs to be added
if contact, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; exists {
contact.State = e.Data[event.ConnectionState]
uiContact := uiState.GetContact(contact.Onion)
if uiContact != nil && uiContact.Status != int(cxnState) {
uiContact.Status = int(cxnState)
uiState.UpdateContact(contact.Onion)
if uiContact != nil {
if uiContact.Status != int(cxnState) {
uiContact.Status = int(cxnState)
uiState.UpdateContact(contact.Onion)
}
} else {
uiState.AddContact(&gobjects.Contact{
e.Data[event.RemotePeer],
e.Data[event.RemotePeer],
cwutil.RandomProfileImage(e.Data[event.RemotePeer]),
"",
0,
int(cxnState),
false,
false,
false,
})
}
}
case event.ServerStateChange:
@ -108,6 +136,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
groups := the.Peer.GetGroups()
for _, groupID := range groups {
group := the.Peer.GetGroup(groupID)
group.State = e.Data[event.ConnectionState]
if group != nil && group.GroupServer == serverOnion {
uiState.GetContact(group.GroupID).Status = int(state)
if state == connections.AUTHENTICATED {

View File

@ -1,43 +0,0 @@
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"
"time"
)
func PresencePoller(uiState *gothings.InterfaceState) {
time.Sleep(time.Second * 4)
for {
contacts := the.Peer.GetContacts()
for i := range contacts {
ct := uiState.GetContact(contacts[i])
if ct == nil { // new contact has attempted to connect with us, treat it as an invite
toc := the.Peer.GetContact(contacts[i])
c, _ := the.Peer.GetProfile().GetContact(contacts[i])
uiState.AddContact(&gobjects.Contact{
toc.Onion,
toc.Name,
cwutil.RandomProfileImage(toc.Onion),
"",
0,
0,
c.Trusted,
c.Blocked,
false,
})
the.EventBus.Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: contacts[i],
event.Key: "name",
event.Data: c.Name,
}))
}
}
time.Sleep(time.Second * 4)
}
}

View File

@ -394,7 +394,7 @@ func (this *GrandCentralDispatcher) importString(str string) {
//eg: torv3JFDWkXExBsZLkjvfkkuAxHsiLGZBk0bvoeJID9ItYnU=EsEBCiBhOWJhZDU1OTQ0NWI3YmM2N2YxYTM5YjkzMTNmNTczNRIgpHeNaG+6jy750eDhwLO39UX4f2xs0irK/M3P6mDSYQIaOTJjM2ttb29ibnlnaGoyenc2cHd2N2Q1N3l6bGQ3NTNhdW8zdWdhdWV6enB2ZmFrM2FoYzRiZHlkCiJAdVSSVgsksceIfHe41OJu9ZFHO8Kwv3G6F5OK3Hw4qZ6hn6SiZjtmJlJezoBH0voZlCahOU7jCOg+dsENndZxAA==
if str[0:5] == "torv3" { // GROUP INVITE
_, err := the.Peer.ImportGroup(str)
err := the.Peer.ImportGroup(str)
if err != nil {
this.InvokePopup("not a valid group invite")
return