Merge branch 'alpha-updates' of cwtch.im/ui into master
This commit is contained in:
commit
7b350d4c54
|
@ -17,6 +17,7 @@ func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(
|
||||||
the.CwtchApp.EventBus().Subscribe(event.NewMessageFromGroup, q.EventChannel)
|
the.CwtchApp.EventBus().Subscribe(event.NewMessageFromGroup, q.EventChannel)
|
||||||
the.CwtchApp.EventBus().Subscribe(event.NewGroupInvite, q.EventChannel)
|
the.CwtchApp.EventBus().Subscribe(event.NewGroupInvite, q.EventChannel)
|
||||||
the.CwtchApp.EventBus().Subscribe(event.SendMessageToGroupError, q.EventChannel)
|
the.CwtchApp.EventBus().Subscribe(event.SendMessageToGroupError, q.EventChannel)
|
||||||
|
the.CwtchApp.EventBus().Subscribe(event.SendMessageToPeerError, q.EventChannel)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
|
@ -68,6 +69,8 @@ func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(
|
||||||
log.Debugf("got a group invite!")
|
log.Debugf("got a group invite!")
|
||||||
case event.SendMessageToGroupError:
|
case event.SendMessageToGroupError:
|
||||||
groupErrorCallback(e.Data[event.Signature], e.Data[event.Error])
|
groupErrorCallback(e.Data[event.Signature], e.Data[event.Error])
|
||||||
|
case event.SendMessageToPeerError:
|
||||||
|
groupErrorCallback(e.Data[event.Signature], e.Data[event.Error])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,36 +0,0 @@
|
||||||
package characters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"cwtch.im/ui/go/gobjects"
|
|
||||||
"cwtch.im/ui/go/the"
|
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PostmanPat(messages chan gobjects.Letter) {
|
|
||||||
postOffice := make(map[string]chan gobjects.Letter)
|
|
||||||
|
|
||||||
for {
|
|
||||||
m := <-messages
|
|
||||||
|
|
||||||
_, found := postOffice[m.To]
|
|
||||||
if !found {
|
|
||||||
postOffice[m.To] = make(chan gobjects.Letter, 100)
|
|
||||||
go andHisBlackAndWhiteCat(postOffice[m.To])
|
|
||||||
}
|
|
||||||
|
|
||||||
postOffice[m.To] <- m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func andHisBlackAndWhiteCat(incomingMessages chan gobjects.Letter) {
|
|
||||||
for {
|
|
||||||
m := <-incomingMessages
|
|
||||||
the.Peer.PeerWithOnion(m.To)
|
|
||||||
log.Debugf("sending message!")
|
|
||||||
ackID := new(the.AckId)
|
|
||||||
ackID.ID = m.MID
|
|
||||||
ackID.Ack = false
|
|
||||||
the.AcknowledgementIDs[m.To] = append(the.AcknowledgementIDs[m.To], ackID)
|
|
||||||
the.Peer.SendMessageToPeer(m.To, m.Message)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -88,24 +88,6 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
mID,err = the.Peer.SendMessageToGroupTracked(this.CurrentOpenConversation(), message)
|
mID,err = the.Peer.SendMessageToGroupTracked(this.CurrentOpenConversation(), message)
|
||||||
if err != nil {
|
|
||||||
this.InvokePopup("failed to send message " +err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// TODO: require explicit invite accept/reject instead of implicitly trusting on send
|
|
||||||
if !this.UIState.GetContact(this.CurrentOpenConversation()).Trusted {
|
|
||||||
this.UIState.GetContact(this.CurrentOpenConversation()).Trusted = true
|
|
||||||
this.UIState.UpdateContact(this.CurrentOpenConversation())
|
|
||||||
}
|
|
||||||
|
|
||||||
select { // 1 weird trick to do a non-blocking send. this means the user can only send a limited number of messages
|
|
||||||
// before the channel buffer fills. TODO: stop the user from sending if the buffer is full
|
|
||||||
case this.OutgoingMessages <- gobjects.Letter{this.CurrentOpenConversation(), message, mID}:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.UIState.AddMessage(&gobjects.Message{
|
this.UIState.AddMessage(&gobjects.Message{
|
||||||
this.CurrentOpenConversation(),
|
this.CurrentOpenConversation(),
|
||||||
|
@ -118,6 +100,42 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
|
||||||
time.Now(),
|
time.Now(),
|
||||||
false,
|
false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
this.InvokePopup("failed to send message " +err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// TODO: require explicit invite accept/reject instead of implicitly trusting on send
|
||||||
|
if !this.UIState.GetContact(this.CurrentOpenConversation()).Trusted {
|
||||||
|
this.UIState.GetContact(this.CurrentOpenConversation()).Trusted = true
|
||||||
|
this.UIState.UpdateContact(this.CurrentOpenConversation())
|
||||||
|
}
|
||||||
|
|
||||||
|
to := this.CurrentOpenConversation();
|
||||||
|
the.Peer.PeerWithOnion(to)
|
||||||
|
mID = the.Peer.SendMessageToPeer(to, message)
|
||||||
|
|
||||||
|
this.UIState.AddMessage(&gobjects.Message{
|
||||||
|
this.CurrentOpenConversation(),
|
||||||
|
"me",
|
||||||
|
"",
|
||||||
|
message,
|
||||||
|
"",
|
||||||
|
true,
|
||||||
|
mID,
|
||||||
|
time.Now(),
|
||||||
|
false,
|
||||||
|
})
|
||||||
|
|
||||||
|
ackID := new(the.AckId)
|
||||||
|
ackID.ID = mID
|
||||||
|
ackID.Ack = false
|
||||||
|
the.AcknowledgementIDs[to] = append(the.AcknowledgementIDs[to], ackID)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *GrandCentralDispatcher) loadMessagesPane(handle string) {
|
func (this *GrandCentralDispatcher) loadMessagesPane(handle string) {
|
||||||
|
|
5
main.go
5
main.go
|
@ -112,7 +112,6 @@ func main() {
|
||||||
// these are long-lived pollers/listeners for incoming messages and status changes
|
// these are long-lived pollers/listeners for incoming messages and status changes
|
||||||
loadCwtchData(gcd, acn)
|
loadCwtchData(gcd, acn)
|
||||||
go characters.IncomingListener(gcd.UIState.AddMessage, gcd.UIState.AddGroupError)
|
go characters.IncomingListener(gcd.UIState.AddMessage, gcd.UIState.AddGroupError)
|
||||||
go characters.PostmanPat(gcd.OutgoingMessages)
|
|
||||||
go characters.TorStatusPoller(gcd.TorStatus, acn)
|
go characters.TorStatusPoller(gcd.TorStatus, acn)
|
||||||
go characters.PresencePoller(gcd.UIState.GetContact, gcd.UIState.AddContact, gcd.UIState.UpdateContact)
|
go characters.PresencePoller(gcd.UIState.GetContact, gcd.UIState.AddContact, gcd.UIState.UpdateContact)
|
||||||
go characters.GroupPoller(gcd.UIState.GetContact, gcd.UIState.UpdateContact)
|
go characters.GroupPoller(gcd.UIState.GetContact, gcd.UIState.UpdateContact)
|
||||||
|
@ -208,7 +207,9 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.Accepted {
|
// Only send a join server packet if we haven't joined this server yet...
|
||||||
|
_,connecting := the.Peer.GetServers()[group.GroupServer]
|
||||||
|
if group.Accepted && !connecting {
|
||||||
the.Peer.JoinServer(group.GroupServer)
|
the.Peer.JoinServer(group.GroupServer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ RowLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupSendError: function(mid, error) {
|
onGroupSendError: function(mid, error) {
|
||||||
|
console.log("Error " + mid + " " + messageID)
|
||||||
if (mid == messageID) {
|
if (mid == messageID) {
|
||||||
root.error = error
|
root.error = error
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue