display progress of group loading and disable sending to groups until loaded

This commit is contained in:
Dan Ballard 2019-04-24 13:32:20 -07:00
parent e60b2fae0b
commit 672570ed42
15 changed files with 215 additions and 101 deletions

View File

@ -11,13 +11,15 @@ import (
"time" "time"
) )
func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(string, string,string)) { func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(string, string, string), serverStateCallback func(string, bool)) {
q := event.NewEventQueue(1000) q := event.NewEventQueue(1000)
the.CwtchApp.EventBus().Subscribe(event.NewMessageFromPeer, q.EventChannel) the.CwtchApp.EventBus().Subscribe(event.NewMessageFromPeer, q.EventChannel)
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) the.CwtchApp.EventBus().Subscribe(event.SendMessageToPeerError, q.EventChannel)
the.CwtchApp.EventBus().Subscribe(event.JoinServer, q.EventChannel)
the.CwtchApp.EventBus().Subscribe(event.FinishedFetch, q.EventChannel)
for { for {
e := q.Next() e := q.Next()
@ -71,6 +73,10 @@ func IncomingListener(callback func(*gobjects.Message), groupErrorCallback func(
groupErrorCallback(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error]) groupErrorCallback(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
case event.SendMessageToPeerError: case event.SendMessageToPeerError:
groupErrorCallback(e.Data[event.RemotePeer], e.Data[event.Signature], e.Data[event.Error]) groupErrorCallback(e.Data[event.RemotePeer], e.Data[event.Signature], e.Data[event.Error])
case event.JoinServer:
serverStateCallback(e.Data[event.GroupServer], true)
case event.FinishedFetch:
serverStateCallback(e.Data[event.GroupServer], false)
} }
} }
} }

View File

@ -28,6 +28,7 @@ func PresencePoller(getContact func(string) *gobjects.Contact, addContact func(c
0, 0,
0, 0,
c.Trusted, c.Trusted,
false,
}) })
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{

View File

@ -8,4 +8,5 @@ type Contact struct {
Badge int Badge int
Status int Status int
Trusted bool Trusted bool
Loading bool
} }

View File

@ -30,8 +30,8 @@ type GrandCentralDispatcher struct {
_ string `property:"buildDate"` _ string `property:"buildDate"`
// contact list stuff // contact list stuff
_ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"AddContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool, loading bool) `signal:"AddContact"`
_ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"UpdateContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool, loading bool) `signal:"UpdateContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"` _ func(handle, key, value string) `signal:"UpdateContactAttribute"`
// messages pane stuff // messages pane stuff
@ -42,6 +42,7 @@ type GrandCentralDispatcher struct {
_ func(mID string) `signal:"Acknowledged"` _ func(mID string) `signal:"Acknowledged"`
_ func(title string) `signal:"SetToolbarTitle"` _ func(title string) `signal:"SetToolbarTitle"`
_ func(signature string, err string) `signal:"GroupSendError"` _ func(signature string, err string) `signal:"GroupSendError"`
_ func(loading bool) `signal:"SetLoadingState"`
// profile-area stuff // profile-area stuff
_ func(name, onion, image string) `signal:"UpdateMyProfile"` _ func(name, onion, image string) `signal:"UpdateMyProfile"`
@ -125,7 +126,7 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
this.UIState.UpdateContact(this.CurrentOpenConversation()) this.UIState.UpdateContact(this.CurrentOpenConversation())
} }
to := this.CurrentOpenConversation(); to := this.CurrentOpenConversation()
the.Peer.PeerWithOnion(to) the.Peer.PeerWithOnion(to)
mID = the.Peer.SendMessageToPeer(to, message) mID = the.Peer.SendMessageToPeer(to, message)
@ -148,7 +149,6 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
the.AcknowledgementIDs[to] = append(the.AcknowledgementIDs[to], ackID) the.AcknowledgementIDs[to] = append(the.AcknowledgementIDs[to], ackID)
} }
} }
func (this *GrandCentralDispatcher) loadMessagesPane(handle string) { func (this *GrandCentralDispatcher) loadMessagesPane(handle string) {
@ -169,15 +169,13 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
0, 0,
0, 0,
false, false,
false,
}) })
} else { } else {
c.Badge = 0 c.Badge = 0
this.UIState.UpdateContact(handle) this.UIState.UpdateContact(handle)
} }
if len(handle) == 32 { // LOAD GROUP if len(handle) == 32 { // LOAD GROUP
group := the.Peer.GetGroup(handle) group := the.Peer.GetGroup(handle)
tl := group.GetTimeline() tl := group.GetTimeline()
@ -492,7 +490,6 @@ func (this *GrandCentralDispatcher) leaveGroup(groupID string) {
func (this *GrandCentralDispatcher) acceptGroup(groupID string) { func (this *GrandCentralDispatcher) acceptGroup(groupID string) {
if the.Peer.GetGroup(groupID) != nil { if the.Peer.GetGroup(groupID) != nil {
the.Peer.AcceptInvite(groupID) the.Peer.AcceptInvite(groupID)
the.Peer.JoinServer(the.Peer.GetGroup(groupID).GroupServer)
this.UIState.UpdateContact(groupID) this.UIState.UpdateContact(groupID)
} }
} }

View File

@ -27,7 +27,7 @@ func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
func (this *InterfaceState) AddContact(c *gobjects.Contact) { func (this *InterfaceState) AddContact(c *gobjects.Contact) {
if len(c.Handle) == 32 { // ADD GROUP if len(c.Handle) == 32 { // ADD GROUP
if _, found := this.contacts[c.Handle]; !found { if _, found := this.contacts[c.Handle]; !found {
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Loading)
this.contacts[c.Handle] = c this.contacts[c.Handle] = c
} }
return return
@ -39,7 +39,7 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
if _, found := this.contacts[c.Handle]; !found { if _, found := this.contacts[c.Handle]; !found {
this.contacts[c.Handle] = c this.contacts[c.Handle] = c
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, false)
if the.Peer.GetContact(c.Handle) == nil { if the.Peer.GetContact(c.Handle) == nil {
decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(c.Handle)) decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(c.Handle))
the.Peer.AddContact(c.DisplayName, c.Handle, decodedPub, c.Trusted) the.Peer.AddContact(c.DisplayName, c.Handle, decodedPub, c.Trusted)
@ -61,6 +61,7 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
0, 0,
0, 0,
group.Accepted, group.Accepted,
false,
}) })
go the.Peer.JoinServer(group.GroupServer) go the.Peer.JoinServer(group.GroupServer)
@ -78,6 +79,7 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
0, 0,
0, 0,
false, false,
false,
}) })
} else if contact == nil { } else if contact == nil {
//log.Errorf("Attempting to add non existent contact to ui %v", handle) //log.Errorf("Attempting to add non existent contact to ui %v", handle)
@ -169,10 +171,19 @@ func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message {
func (this *InterfaceState) UpdateContact(handle string) { func (this *InterfaceState) UpdateContact(handle string) {
c, found := this.contacts[handle] c, found := this.contacts[handle]
if found { if found {
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted, c.Loading)
} }
} }
func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) { func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) {
this.parentGcd.UpdateContactAttribute(handle, key, value) this.parentGcd.UpdateContactAttribute(handle, key, value)
} }
func (this *InterfaceState) UpdateServerStatus(server string, loading bool) {
for _, contact := range this.contacts {
if contact.Server == server {
contact.Loading = loading
this.UpdateContact(contact.Handle)
}
}
}

View File

@ -167,7 +167,7 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher) {
// 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, the.ACN) loadCwtchData(gcd, the.ACN)
go characters.IncomingListener(gcd.UIState.AddMessage, gcd.UIState.AddSendMessageError) go characters.IncomingListener(gcd.UIState.AddMessage, gcd.UIState.AddSendMessageError, gcd.UIState.UpdateServerStatus)
go characters.TorStatusPoller(gcd.TorStatus, the.ACN) go characters.TorStatusPoller(gcd.TorStatus, the.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)
@ -227,6 +227,7 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
DisplayName: displayName, DisplayName: displayName,
Image: cwutil.RandomProfileImage(contacts[i]), Image: cwutil.RandomProfileImage(contacts[i]),
Trusted: contact.Trusted, Trusted: contact.Trusted,
Loading: false,
}) })
} }
} }
@ -248,6 +249,7 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
Image: cwutil.RandomGroupImage(group.GroupID), Image: cwutil.RandomGroupImage(group.GroupID),
Server: group.GroupServer, Server: group.GroupServer,
Trusted: group.Accepted, Trusted: group.Accepted,
Loading: true,
}) })
// Only send a join server packet if we haven't joined this server yet... // Only send a join server packet if we haven't joined this server yet...

View File

@ -125,7 +125,9 @@ ApplicationWindow {
visible: true visible: true
SplashPane { SplashPane {
id: splashPane
anchors.fill: parent anchors.fill: parent
running: true
} }
} }

View File

@ -91,6 +91,21 @@ ColumnLayout {
sv.contentY = sv.contentHeight - sv.height sv.contentY = sv.contentHeight - sv.height
} }
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted, _loading) {
if (gcd.currentOpenConversation == _handle) {
if (_loading == true) {
newposttitle.enabled = false
newpostbody.enabled = false
btnSend.enabled = false
} else {
newposttitle.enabled = true
newpostbody.enabled = true
btnSend.enabled = true
}
}
}
} }
ScrollBar.vertical: ScrollBar{ ScrollBar.vertical: ScrollBar{

View File

@ -11,7 +11,7 @@ import "../utils.js" as Utils
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
property bool loading
ListModel { // MESSAGE OBJECTS ARE STORED HERE ... ListModel { // MESSAGE OBJECTS ARE STORED HERE ...
id: messagesModel id: messagesModel
@ -108,6 +108,19 @@ ColumnLayout {
messagesListView.positionViewAtEnd() messagesListView.positionViewAtEnd()
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted, _loading) {
if (gcd.currentOpenConversation == _handle) {
if (_loading == true) {
txtMessage.enabled = false
btnSend.enabled = false
} else {
txtMessage.enabled = true
btnSend.enabled = true
}
}
}
} }
} }

View File

@ -95,6 +95,19 @@ ColumnLayout {
sv.contentY = sv.contentHeight - sv.height sv.contentY = sv.contentHeight - sv.height
} }
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted, _loading) {
if (gcd.currentOpenConversation == _handle) {
if (_loading == true) {
newposttitle.enabled = false
btnSend.enabled = false
} else {
newposttitle.enabled = true
btnSend.enabled = true
}
}
}
} }
ScrollBar.vertical: ScrollBar{ ScrollBar.vertical: ScrollBar{

View File

@ -8,6 +8,9 @@ import QtQuick.Controls.Styles 1.4
import "../styles" import "../styles"
Item { Item {
id: sp
property bool running
Image { Image {
id: splashImage id: splashImage
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@ -17,14 +20,17 @@ Item {
} }
ProgressBar { ProgressBar {
id: progressBar
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.top: splashImage.bottom anchors.top: splashImage.bottom
anchors.topMargin: 10 anchors.topMargin: 10
width: splashImage.width
indeterminate: true indeterminate: true
style: ProgressBarStyle { style: ProgressBarStyle {
progress: CwtchProgress {} progress: CwtchProgress { running: sp.running }
} }
} }
} }

View File

@ -8,8 +8,12 @@ import QtQuick.Controls.Styles 1.4
Rectangle { Rectangle {
border.color: "#D2C0DD" id: pb
color: "red" border.color: "#FFFFFF"
border.width: 1
color: "#D2C0DD"
property bool running
// Indeterminate animation by animating alternating stripes: // Indeterminate animation by animating alternating stripes:
Item { Item {
@ -28,7 +32,7 @@ Rectangle {
XAnimator on x { XAnimator on x {
from: 0 ; to: -40 from: 0 ; to: -40
loops: Animation.Infinite loops: Animation.Infinite
running: parentStack.currentIndex == 0 running: pb.running
} }
} }
} }

View File

@ -47,7 +47,7 @@ ColumnLayout {
Connections { // ADD/REMOVE CONTACT ENTRIES Connections { // ADD/REMOVE CONTACT ENTRIES
target: gcd target: gcd
onAddContact: function(handle, displayName, image, server, badge, status, trusted) { onAddContact: function(handle, displayName, image, server, badge, status, trusted, loading) {
contactsModel.append({ contactsModel.append({
"_handle": handle, "_handle": handle,
"_displayName": displayName, "_displayName": displayName,
@ -56,7 +56,8 @@ ColumnLayout {
"_badge": badge, "_badge": badge,
"_status": status, "_status": status,
"_trusted": trusted, "_trusted": trusted,
"_deleted": false "_deleted": false,
"_loading": loading
}) })
} }
@ -88,6 +89,7 @@ ColumnLayout {
status: _status status: _status
trusted: _trusted trusted: _trusted
deleted: _deleted deleted: _deleted
loading: _loading
} }
} }
} }

View File

@ -4,6 +4,10 @@ import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0 import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import CustomQmlTypes 1.0 import CustomQmlTypes 1.0
import "../styles"
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.left: parent.left anchors.left: parent.left
@ -20,6 +24,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
property bool isHover property bool isHover
property bool trusted property bool trusted
property bool deleted property bool deleted
property bool loading
property alias status: imgProfile.status property alias status: imgProfile.status
property string server property string server
property bool background: true property bool background: true
@ -44,7 +49,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
rightPadding: 10 rightPadding: 10
//wrapMode: Text.WordWrap //wrapMode: Text.WordWrap
anchors.left: imgProfile.right anchors.left: imgProfile.right
anchors.right: rectUnread.left anchors.right: loadingProgress.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 16 * gcd.themeScale font.pixelSize: 16 * gcd.themeScale
font.italic: !trusted font.italic: !trusted
@ -80,6 +85,31 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
font: lblUnread.font font: lblUnread.font
} }
} }
ProgressBar { // LOADING ?
id: loadingProgress
property bool running
running: loading
anchors.right: rectUnread.left
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 1 * gcd.themeScale
anchors.rightMargin: 1 * gcd.themeScale
height: cn.height/2
width: 100 * gcd.themeScale
indeterminate: true
visible: loading
style: ProgressBarStyle {
progress: CwtchProgress { running: loadingProgress.running}
}
}
} }
MouseArea { // ONCLICK: LOAD CONVERSATION WITH THIS CONTACT MouseArea { // ONCLICK: LOAD CONVERSATION WITH THIS CONTACT
@ -112,7 +142,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
isActive = false isActive = false
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted) { onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted, _loading) {
if (handle == _handle) { if (handle == _handle) {
displayName = _displayName displayName = _displayName
image = _image image = _image
@ -120,6 +150,16 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
badge = _badge badge = _badge
status = _status status = _status
trusted = _trusted trusted = _trusted
loading = _loading
if (loading == true) {
loadingProgress.visible = true
loadingProgress.running = true
} else {
loadingProgress.visible = false
loadingProgress.running = false
}
} }
} }
} }

View File

@ -230,6 +230,7 @@ ColumnLayout {
onion = _onion onion = _onion
image = _image image = _image
parentStack.currentIndex = 1 parentStack.currentIndex = 1
splashPane.running = false
} }
onTorStatus: function(code, str) { onTorStatus: function(code, str) {