Merge branch 'progress' of dan/ui into master

This commit is contained in:
erinn 2019-04-24 13:38:02 -07:00 committed by Gogs
commit b6f0e7f171
15 changed files with 215 additions and 101 deletions

View File

@ -11,13 +11,15 @@ import (
"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)
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)
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 {
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])
case event.SendMessageToPeerError:
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,
c.Trusted,
false,
})
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{

View File

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

View File

@ -30,8 +30,8 @@ type GrandCentralDispatcher struct {
_ string `property:"buildDate"`
// 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) `signal:"UpdateContact"`
_ 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, loading bool) `signal:"UpdateContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"`
// messages pane stuff
@ -42,6 +42,7 @@ type GrandCentralDispatcher struct {
_ func(mID string) `signal:"Acknowledged"`
_ func(title string) `signal:"SetToolbarTitle"`
_ func(signature string, err string) `signal:"GroupSendError"`
_ func(loading bool) `signal:"SetLoadingState"`
// profile-area stuff
_ func(name, onion, image string) `signal:"UpdateMyProfile"`
@ -125,7 +126,7 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
this.UIState.UpdateContact(this.CurrentOpenConversation())
}
to := this.CurrentOpenConversation();
to := this.CurrentOpenConversation()
the.Peer.PeerWithOnion(to)
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)
}
}
func (this *GrandCentralDispatcher) loadMessagesPane(handle string) {
@ -169,15 +169,13 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
0,
0,
false,
false,
})
} else {
c.Badge = 0
this.UIState.UpdateContact(handle)
}
if len(handle) == 32 { // LOAD GROUP
group := the.Peer.GetGroup(handle)
tl := group.GetTimeline()
@ -495,7 +493,6 @@ func (this *GrandCentralDispatcher) leaveGroup(groupID string) {
func (this *GrandCentralDispatcher) acceptGroup(groupID string) {
if the.Peer.GetGroup(groupID) != nil {
the.Peer.AcceptInvite(groupID)
the.Peer.JoinServer(the.Peer.GetGroup(groupID).GroupServer)
this.UIState.UpdateContact(groupID)
}
}

View File

@ -27,7 +27,7 @@ func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
func (this *InterfaceState) AddContact(c *gobjects.Contact) {
if len(c.Handle) == 32 { // ADD GROUP
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
}
return
@ -39,7 +39,7 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
if _, found := this.contacts[c.Handle]; !found {
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 {
decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(c.Handle))
the.Peer.AddContact(c.DisplayName, c.Handle, decodedPub, c.Trusted)
@ -61,6 +61,7 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
0,
0,
group.Accepted,
false,
})
go the.Peer.JoinServer(group.GroupServer)
@ -78,6 +79,7 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
0,
0,
false,
false,
})
} else if contact == nil {
//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) {
c, found := this.contacts[handle]
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) {
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
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.PresencePoller(gcd.UIState.GetContact, gcd.UIState.AddContact, 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,
Image: cwutil.RandomProfileImage(contacts[i]),
Trusted: contact.Trusted,
Loading: false,
})
}
}
@ -248,6 +249,7 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
Image: cwutil.RandomGroupImage(group.GroupID),
Server: group.GroupServer,
Trusted: group.Accepted,
Loading: true,
})
// Only send a join server packet if we haven't joined this server yet...

View File

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

View File

@ -91,6 +91,21 @@ ColumnLayout {
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{

View File

@ -11,7 +11,7 @@ import "../utils.js" as Utils
ColumnLayout {
Layout.fillWidth: true
property bool loading
ListModel { // MESSAGE OBJECTS ARE STORED HERE ...
id: messagesModel
@ -109,6 +109,19 @@ ColumnLayout {
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
}
}
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{

View File

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

View File

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

View File

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

View File

@ -4,6 +4,10 @@ import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
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
anchors.left: parent.left
@ -21,6 +25,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
property bool isHover
property bool trusted
property bool deleted
property bool loading
property alias status: imgProfile.status
property string server
property bool background: true
@ -45,7 +50,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
rightPadding: 10
//wrapMode: Text.WordWrap
anchors.left: imgProfile.right
anchors.right: rectUnread.left
anchors.right: loadingProgress.left
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 16 * gcd.themeScale
font.italic: !trusted
@ -81,6 +86,31 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
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
@ -113,7 +143,7 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
isActive = false
}
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted) {
onUpdateContact: function(_handle, _displayName, _image, _server, _badge, _status, _trusted, _loading) {
if (handle == _handle) {
displayName = _displayName
image = _image
@ -121,6 +151,16 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
badge = _badge
status = _status
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
image = _image
parentStack.currentIndex = 1
splashPane.running = false
}
onTorStatus: function(code, str) {