From 4e3ca4853ce148eaa69e4d76613ad0f257405929 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 20 Feb 2019 13:45:42 -0800 Subject: [PATCH] Surfacing Group Send Errors in UI --- go/characters/cwtchlistener.go | 37 ------------------------------- go/characters/incominglistener.go | 5 ++++- go/gothings/gcd.go | 3 ++- go/gothings/uistate.go | 4 ++++ main.go | 2 +- qml/widgets/Message.qml | 16 ++++++++++++- 6 files changed, 26 insertions(+), 41 deletions(-) delete mode 100644 go/characters/cwtchlistener.go diff --git a/go/characters/cwtchlistener.go b/go/characters/cwtchlistener.go deleted file mode 100644 index d6abc36..0000000 --- a/go/characters/cwtchlistener.go +++ /dev/null @@ -1,37 +0,0 @@ -package characters - -import ( - "cwtch.im/cwtch/model" - "cwtch.im/ui/go/gobjects" - "cwtch.im/ui/go/the" -) - -func CwtchListener(callback func(message *gobjects.Message), groupID string, channel chan model.Message) { - for { - m := <-channel - - name := m.PeerID - if name == the.Peer.GetProfile().Onion { - name = "me" - } else { - contact := the.Peer.GetContact(m.PeerID) - if contact != nil { - name, _ = contact.GetAttribute("name") - } else { - name = m.PeerID[:16] + "..." - } - } - - callback(&gobjects.Message{ - groupID, - m.PeerID, - name, - m.Message, - "", - m.PeerID == the.Peer.GetProfile().Onion, - "0", - m.Timestamp, - false, - }) - } -} diff --git a/go/characters/incominglistener.go b/go/characters/incominglistener.go index 76532ec..266c5ea 100644 --- a/go/characters/incominglistener.go +++ b/go/characters/incominglistener.go @@ -11,11 +11,12 @@ import ( "time" ) -func IncomingListener(callback func(*gobjects.Message)) { +func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(string,string)) { q := event.NewEventQueue(1000) the.CwtchApp.EventBus().Subscribe(event.NewMessageFromPeer, q.EventChannel) the.CwtchApp.EventBus().Subscribe(event.NewMessageFromGroup, q.EventChannel) the.CwtchApp.EventBus().Subscribe(event.NewGroupInvite, q.EventChannel) + the.CwtchApp.EventBus().Subscribe(event.SendMessageToGroupError, q.EventChannel) for { e := q.Next() @@ -52,6 +53,8 @@ func IncomingListener(callback func(*gobjects.Message)) { }) case event.NewGroupInvite: log.Debugf("got a group invite!") + case event.SendMessageToGroupError: + groupErrorCallback(e.Data[event.Signature], e.Data[event.Error]) } } } \ No newline at end of file diff --git a/go/gothings/gcd.go b/go/gothings/gcd.go index e02bfe3..a3548ed 100644 --- a/go/gothings/gcd.go +++ b/go/gothings/gcd.go @@ -32,8 +32,9 @@ type GrandCentralDispatcher struct { _ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool) `signal:"AppendMessage"` _ func() `signal:"ClearMessages"` _ func() `signal:"ResetMessagePane"` - _ func(mID string) `signal:"Acknowledged"` + _ func(mID string) `signal:"Acknowledged"` _ func(title string) `signal:"SetToolbarTitle"` + _ func(signature string, err string) `signal:"GroupSendError"` // profile-area stuff _ func(name, onion, image string) `signal:"UpdateMyProfile"` diff --git a/go/gothings/uistate.go b/go/gothings/uistate.go index 6442ff1..96c75ba 100644 --- a/go/gothings/uistate.go +++ b/go/gothings/uistate.go @@ -86,6 +86,10 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { return this.contacts[handle] } +func (this *InterfaceState) AddGroupError(signature string, err string) { + this.parentGcd.GroupSendError(signature, err) +} + func (this *InterfaceState) AddMessage(m *gobjects.Message) { this.GetContact(m.From) diff --git a/main.go b/main.go index 844f741..5c7a3b9 100644 --- a/main.go +++ b/main.go @@ -109,7 +109,7 @@ func main() { // these are long-lived pollers/listeners for incoming messages and status changes loadCwtchData(gcd, acn) - go characters.IncomingListener(gcd.UIState.AddMessage) + go characters.IncomingListener(gcd.UIState.AddMessage, gcd.UIState.AddGroupError) go characters.PostmanPat(gcd.OutgoingMessages) go characters.TorStatusPoller(gcd.TorStatus, acn) go characters.PresencePoller(gcd.UIState.GetContact, gcd.UIState.AddContact, gcd.UIState.UpdateContact) diff --git a/qml/widgets/Message.qml b/qml/widgets/Message.qml index 153a001..e545c64 100644 --- a/qml/widgets/Message.qml +++ b/qml/widgets/Message.qml @@ -23,6 +23,7 @@ RowLayout { property alias timestamp: ts.text property alias image: imgProfile.source property alias status: imgProfile.status + property string error Connections { target: gcd @@ -33,6 +34,12 @@ RowLayout { } } + onGroupSendError: function(mid, error) { + if (mid == messageID) { + root.error = error + } + } + } @@ -130,10 +137,17 @@ RowLayout { Image { // ACKNOWLEDGEMENT ICON id: ack anchors.right: parent.right - source: root.ackd ? "qrc:/qml/images/fontawesome/regular/check-circle.svg" : "qrc:/qml/images/fontawesome/regular/hourglass.svg" + source: root.error != "" ? "qrc:/qml/images/fontawesome/regular/window-close.svg" : (root.ackd ? "qrc:/qml/images/fontawesome/regular/check-circle.svg" : "qrc:/qml/images/fontawesome/regular/hourglass.svg") height: 10 sourceSize.height: 10 visible: fromMe + ToolTip.visible: ma.containsMouse + ToolTip.text: root.error != "" ? qsTr("Could not send this message: ") + qsTr(root.error) : (root.ackd ? qsTr("Acknowledged") : qsTr("Pending")) + MouseArea { + id: ma + anchors.fill: parent + hoverEnabled: true + } } } }