diff --git a/go/gothings/gcd.go b/go/gothings/gcd.go index 0e95add..bab9b22 100644 --- a/go/gothings/gcd.go +++ b/go/gothings/gcd.go @@ -41,9 +41,9 @@ type GrandCentralDispatcher struct { _ func(name, onion, image string) `signal:"UpdateMyProfile"` _ func(status int, str string) `signal:"TorStatus"` - // other stuff i can't ontologize atm + // settings helpers _ func(str string) `signal:"InvokePopup"` - _ func(groupID, name, server, invitation string, addrbooknames, addrbookaddrs []string) `signal:"SupplyGroupSettings"` + _ func(groupID, name, server, invitation string, accepted bool, addrbooknames, addrbookaddrs []string) `signal:"SupplyGroupSettings"` _ func(onion, nick string) `signal:"SupplyPeerSettings"` // signals emitted from the ui (written in go, below) @@ -55,7 +55,8 @@ type GrandCentralDispatcher struct { _ func(nick string) `signal:"updateNick,auto"` _ func(server, groupName string) `signal:"createGroup,auto"` _ func(groupID string) `signal:"leaveGroup,auto"` - _ func() `signal:"requestGroupSettings,auto"` + _ func(groupID string) `signal:"acceptGroup,auto"` + _ func(groupID string) `signal:"requestGroupSettings,auto"` _ func(groupID, nick string) `signal:"saveGroupSettings,auto"` _ func() `signal:"requestPeerSettings,auto"` _ func(onion, nick string) `signal:"savePeerSettings,auto"` @@ -251,16 +252,16 @@ func (this *GrandCentralDispatcher) savePeerSettings(onion, nick string) { this.UIState.UpdateContact(onion) } -func (this *GrandCentralDispatcher) requestGroupSettings() { - group := the.Peer.GetGroup(this.CurrentOpenConversation()) +func (this *GrandCentralDispatcher) requestGroupSettings(groupID string) { + group := the.Peer.GetGroup(groupID) if group == nil { - log.Errorf("couldn't find group %v", this.CurrentOpenConversation()) + log.Errorf("couldn't find group %v", groupID) return } nick, _ := group.GetAttribute("nick") - invite, _ := the.Peer.ExportGroup(this.CurrentOpenConversation()) + invite, _ := the.Peer.ExportGroup(groupID) contactaddrs := the.Peer.GetContacts() contactnames := make([]string, len(contactaddrs)) @@ -273,7 +274,7 @@ func (this *GrandCentralDispatcher) requestGroupSettings() { } } - this.SupplyGroupSettings(group.GroupID, nick, group.GroupServer, invite, contactnames, contactaddrs) + this.SupplyGroupSettings(group.GroupID, nick, group.GroupServer, invite, group.Accepted, contactnames, contactaddrs) } func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) { @@ -430,6 +431,14 @@ func (this *GrandCentralDispatcher) leaveGroup(groupID string) { this.UIState.UpdateContactAttribute(groupID, "deleted", "deleted") } +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) + } +} + func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) { pp,_ := the.Peer.GetProfile().GetContact(onion) if pp != nil { diff --git a/go/gothings/uistate.go b/go/gothings/uistate.go index e9ed0de..4405d6a 100644 --- a/go/gothings/uistate.go +++ b/go/gothings/uistate.go @@ -55,10 +55,10 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { handle, handle, cwutil.RandomGroupImage(handle), - "", + group.GroupServer, 0, 0, - false, + group.Accepted, }) go the.Peer.JoinServer(group.GroupServer) @@ -78,7 +78,7 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { false, }) } 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) } } } diff --git a/main.go b/main.go index 913571b..8624c58 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,13 @@ func init() { } func main() { - log.SetLevel(log.LevelInfo) + + if len(os.Args) >= 3 && os.Args[2] == "-debug" { + log.SetLevel(log.LevelDebug) + } else { + log.SetLevel(log.LevelInfo) + } + // our globals gcd := gothings.NewGrandCentralDispatcher(nil) @@ -39,7 +45,7 @@ func main() { // this is to load local qml files quickly when developing var qmlSource *core.QUrl - if len(os.Args) == 2 && os.Args[1] == "-local" { + if len(os.Args) >= 2 && os.Args[1] == "-local" { qmlSource = core.QUrl_FromLocalFile("./qml/main.qml") } else { qmlSource = core.NewQUrl3("qrc:/qml/main.qml", 0) @@ -160,8 +166,9 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) { nick = group.GroupID[:12] } deleted,_ := group.GetAttribute("deleted") - if deleted != "deleted" { - the.Peer.JoinServer(group.GroupServer) + // Only join servers for active and explicitly accepted groups. + if deleted != "deleted"{ + gcd.UIState.AddContact(&gobjects.Contact{ Handle: group.GroupID, DisplayName: nick, @@ -170,5 +177,9 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) { Trusted: group.Accepted, }) } + + if group.Accepted { + the.Peer.JoinServer(group.GroupServer) + } } } diff --git a/qml/panes/GroupSettingsPane.qml b/qml/panes/GroupSettingsPane.qml index b3440e6..c8b55d8 100644 --- a/qml/panes/GroupSettingsPane.qml +++ b/qml/panes/GroupSettingsPane.qml @@ -120,7 +120,7 @@ ColumnLayout { // groupSettingsPane Connections { target: gcd - onSupplyGroupSettings: function(gid, name, server, invite, addrbooknames, addrbookaddrs) { + onSupplyGroupSettings: function(gid, name, server, invite, accepted, addrbooknames, addrbookaddrs) { console.log("Supplied " + gid + " " + name) gsp.groupID = gid toolbar.text = name diff --git a/qml/panes/OverlayPane.qml b/qml/panes/OverlayPane.qml index f9836df..f3703be 100644 --- a/qml/panes/OverlayPane.qml +++ b/qml/panes/OverlayPane.qml @@ -10,7 +10,9 @@ import "../overlays" ColumnLayout { Layout.fillWidth: true property alias title: toolbar.text - + id: overlay + property string name + property bool accepted StackToolbar { id: toolbar @@ -19,7 +21,7 @@ ColumnLayout { aux.onClicked: { if (gcd.currentOpenConversation.length == 32) { theStack.pane = theStack.groupProfilePane - gcd.requestGroupSettings() + gcd.requestGroupSettings(gcd.currentOpenConversation) } else { theStack.pane = theStack.userProfilePane gcd.requestPeerSettings() @@ -28,6 +30,29 @@ ColumnLayout { back.visible: false } + RowLayout { + visible:!overlay.accepted + Text { + text: "Do you want to accept the invitation to " + overlay.name + "?" + } + SimpleButton { + text: "Accept" + icon: "regular/heart" + onClicked: { + gcd.acceptGroup(gcd.currentOpenConversation) + gcd.requestGroupSettings(gcd.currentOpenConversation) + } + } + SimpleButton { + text: "Reject" + icon: "regular/trash-alt" + onClicked: { + gcd.leaveGroup(gcd.currentOpenConversation) + theStack.pane = theStack.emptyPane + } + } + } + RowLayout { id: switcher @@ -54,18 +79,12 @@ ColumnLayout { } SimpleButton { - text: "Game 1" + text: "Puzzle Game" onClicked: overlayStack.overlay = overlayStack.game1Overlay } - SimpleButton { - text: "Game 2" - - - onClicked: overlayStack.overlay = overlayStack.game2Overlay - } } StackLayout { @@ -81,7 +100,6 @@ ColumnLayout { readonly property int listOverlay: 1 readonly property int bulletinOverlay: 2 readonly property int game1Overlay: 3 - readonly property int game2Overlay: 4 ChatOverlay {} //0 @@ -91,7 +109,15 @@ ColumnLayout { BulletinOverlay{} //2 Game1Overlay{} //3 - - Game2Overlay{} //4 } + + Connections { + target: gcd + + onSupplyGroupSettings: function(gid, name, server, invite, accepted, addrbooknames, addrbookaddrs) { + console.log("Supplied " + gid + " " + name + "Accepted " + accepted) + overlay.name = name + overlay.accepted = accepted + } + } } \ No newline at end of file diff --git a/qml/widgets/ContactRow.qml b/qml/widgets/ContactRow.qml index ea2f941..64f3ad7 100644 --- a/qml/widgets/ContactRow.qml +++ b/qml/widgets/ContactRow.qml @@ -88,6 +88,9 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY isActive = true theStack.pane = theStack.messagePane gcd.loadMessagesPane(handle) + if (handle.length == 32) { + gcd.requestGroupSettings(handle) + } } onEntered: {