From ec004afc1a226ee575f8761e0b35ec64c4bbe1c1 Mon Sep 17 00:00:00 2001 From: erinn Date: Mon, 4 Feb 2019 16:41:18 -0800 Subject: [PATCH] support changing peer/group contact names --- go/gothings/gcd.go | 89 ++++++++++++++++++++++++++------- main.go | 2 +- qml/main.qml | 14 +----- qml/panes/GroupSettingsPane.qml | 34 +++++++++---- qml/panes/OverlayPane.qml | 9 +++- qml/panes/PeerSettingsPane.qml | 61 ++++++++++++++++++++++ 6 files changed, 166 insertions(+), 43 deletions(-) create mode 100644 qml/panes/PeerSettingsPane.qml diff --git a/go/gothings/gcd.go b/go/gothings/gcd.go index 1aefc00..1481211 100644 --- a/go/gothings/gcd.go +++ b/go/gothings/gcd.go @@ -42,8 +42,9 @@ type GrandCentralDispatcher struct { _ func(status int, str string) `signal:"TorStatus"` // other stuff i can't ontologize atm - _ func(str string) `signal:"InvokePopup"` - _ func(name, server, invitation string) `signal:"SupplyGroupSettings"` + _ func(str string) `signal:"InvokePopup"` + _ func(groupID, name, server, invitation string) `signal:"SupplyGroupSettings"` + _ func(onion, nick string) `signal:"SupplyPeerSettings"` // signals emitted from the ui (written in go, below) _ func(message string, mid uint) `signal:"sendMessage,auto"` @@ -54,6 +55,9 @@ type GrandCentralDispatcher struct { _ func(nick string) `signal:"updateNick,auto"` _ func(server, groupName string) `signal:"createGroup,auto"` _ func() `signal:"requestGroupSettings,auto"` + _ func(groupID, nick string) `signal:"saveGroupSettings,auto"` + _ func() `signal:"requestPeerSettings,auto"` + _ func(onion, nick string) `signal:"savePeerSettings,auto"` } func (this *GrandCentralDispatcher) sendMessage(message string, mID uint) { @@ -137,9 +141,12 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) { } var name string var exists bool - name, exists = the.Peer.GetProfile().GetAttribute(tl[i].PeerID + "_name") - if !exists || name == "" { - name = tl[i].PeerID[:16] + "..." + ctc := the.Peer.GetContact(tl[i].PeerID) + if ctc != nil { + name, exists = ctc.GetAttribute("nick") + if !exists || name == "" { + name = tl[i].PeerID[:16] + "..." + } } this.AppendMessage( handle, @@ -156,7 +163,7 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) { } // ELSE LOAD CONTACT contact, _ := the.Peer.GetProfile().GetContact(handle) - nick,_ := contact.GetAttribute("name") + nick,_ := contact.GetAttribute("nick") if nick == "" { this.SetToolbarTitle(handle) } else { @@ -182,18 +189,72 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) { } } +func (this *GrandCentralDispatcher) requestPeerSettings() { + contact := the.Peer.GetContact(this.CurrentOpenConversation()) + if contact == nil { + log.Errorf("error: requested settings for unknown contact %v?", this.CurrentOpenConversation()) + this.SupplyPeerSettings(this.CurrentOpenConversation(), this.CurrentOpenConversation()) + return + } + + name, exists := contact.GetAttribute("nick") + if !exists { + log.Errorf("error: couldn't find contact %v", this.CurrentOpenConversation()) + this.SupplyPeerSettings(this.CurrentOpenConversation(), this.CurrentOpenConversation()) + return + } + + this.SupplyPeerSettings(contact.Onion, name) +} + +func (this *GrandCentralDispatcher) savePeerSettings(onion, nick string) { + contact := the.Peer.GetContact(onion) + if contact == nil { + log.Errorf("error: tried to save settings for unknown peer %v", onion) + return + } + + contact.SetAttribute("nick", nick) + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ + event.RemotePeer: onion, + event.Key: "nick", + event.Data: nick, + })) + + this.UIState.contacts[onion].DisplayName = nick + this.UIState.UpdateContact(onion) +} + func (this *GrandCentralDispatcher) requestGroupSettings() { - log.Debugf("requestGroupSettings()") group := the.Peer.GetGroup(this.CurrentOpenConversation()) if group == nil { - log.Errorf("requested group settings for a p2p contact") + log.Errorf("couldn't find group %v", this.CurrentOpenConversation()) return } nick, _ := group.GetAttribute("nick") invite, _ := the.Peer.ExportGroup(this.CurrentOpenConversation()) - this.SupplyGroupSettings(nick, group.GroupServer, invite) + this.SupplyGroupSettings(this.CurrentOpenConversation(), nick, group.GroupServer, invite) +} + +func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) { + group := the.Peer.GetGroup(this.CurrentOpenConversation()) + + if group == nil { + log.Errorf("couldn't find group %v", groupID) + return + } + + group.SetAttribute("nick", nick) + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{ + event.GroupID: groupID, + event.Key: "nick", + event.Data: nick, + })) + + this.UIState.contacts[groupID].DisplayName = nick + this.UIState.UpdateContact(groupID) } func (this *GrandCentralDispatcher) broadcast(signal string) { @@ -281,14 +342,8 @@ func (this *GrandCentralDispatcher) importString(str string) { return } - _, exists := the.Peer.GetProfile().GetAttribute(name + "_onion") - if exists { - this.InvokePopup("can't re-use names :(") - return - } - - _, exists = the.Peer.GetProfile().GetAttribute(onion + "_name") - if exists { + checkc := the.Peer.GetContact(onion) + if checkc != nil { this.InvokePopup("already have this contact") return //TODO: bring them to the duplicate } diff --git a/main.go b/main.go index 1d3b914..01fd0d7 100644 --- a/main.go +++ b/main.go @@ -155,7 +155,7 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) { contacts := the.Peer.GetContacts() for i := range contacts { contact, _ := the.Peer.GetProfile().GetContact(contacts[i]) - displayName, _ := contact.GetAttribute("name") + displayName, _ := contact.GetAttribute("nick") gcd.UIState.AddContact(&gobjects.Contact{ Handle: contacts[i], DisplayName: displayName, diff --git a/qml/main.qml b/qml/main.qml index cb8baa3..ed2821d 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -154,19 +154,7 @@ Item { SettingsPane{ anchors.fill: parent } - ColumnLayout { // userProfilePane - anchors.fill: parent - - - StackToolbar { - text: "Settings for Sarah" - aux.visible: false - - back.onClicked: theStack.pane = theStack.messagePane - } - - Label { text: "per-user things like contact name and picture will be edited here" } - } + PeerSettingsPane { anchors.fill: parent } GroupSettingsPane{ anchors.fill: parent } diff --git a/qml/panes/GroupSettingsPane.qml b/qml/panes/GroupSettingsPane.qml index 2ffbb14..e999167 100644 --- a/qml/panes/GroupSettingsPane.qml +++ b/qml/panes/GroupSettingsPane.qml @@ -9,6 +9,7 @@ import "../widgets" ColumnLayout { // groupSettingsPane anchors.fill: parent + property string groupID StackToolbar { @@ -23,15 +24,7 @@ ColumnLayout { // groupSettingsPane TextEdit { id: txtServer width: 100 - } - - ScalingLabel{ - text: "Group name:" - } - - TextEdit { - id: txtGroupName - width: 100 + readOnly: true } ScalingLabel { @@ -41,6 +34,7 @@ ColumnLayout { // groupSettingsPane TextEdit { id: txtInvitation width: 200 + readOnly: true } SimpleButton { @@ -54,11 +48,31 @@ ColumnLayout { // groupSettingsPane } } + ScalingLabel{ + text: "Group name:" + } + + TextEdit { + id: txtGroupName + width: 100 + } + + SimpleButton { + text: "Save" + + onClicked: { + gcd.saveGroupSettings(groupID, txtGroupName.text) + theStack.title = txtGroupName.text + theStack.pane = theStack.messagePane + } + } + Connections { target: gcd - onSupplyGroupSettings: function(name, server, invite) { + onSupplyGroupSettings: function(gid, name, server, invite) { + groupID = gid toolbar.text = name txtGroupName.text = name txtServer.text = server diff --git a/qml/panes/OverlayPane.qml b/qml/panes/OverlayPane.qml index 0f30a73..0d9a5a1 100644 --- a/qml/panes/OverlayPane.qml +++ b/qml/panes/OverlayPane.qml @@ -17,8 +17,13 @@ ColumnLayout { //text: "open privacy exec" aux.onClicked: { - theStack.pane = gcd.currentOpenConversation.length == 32 ? theStack.groupProfilePane : theStack.userProfilePane - gcd.requestGroupSettings() + if (gcd.currentOpenConversation.length == 32) { + theStack.pane = theStack.groupProfilePane + gcd.requestGroupSettings() + } else { + theStack.pane = theStack.userProfilePane + gcd.requestPeerSettings() + } } } diff --git a/qml/panes/PeerSettingsPane.qml b/qml/panes/PeerSettingsPane.qml new file mode 100644 index 0000000..a2b9410 --- /dev/null +++ b/qml/panes/PeerSettingsPane.qml @@ -0,0 +1,61 @@ +import QtGraphicalEffects 1.0 +import QtQuick 2.7 +import QtQuick.Controls 2.4 +import QtQuick.Controls.Material 2.0 +import QtQuick.Layouts 1.3 +import QtQuick.Window 2.11 + +import "../widgets" + +ColumnLayout { // peerSettingsPane + anchors.fill: parent + + + StackToolbar { + id: toolbar + aux.visible: false + + + back.onClicked: theStack.pane = theStack.messagePane + } + + ScalingLabel { + text: "Address:" + } + + TextEdit { + id: txtOnion + width: 100 + readOnly: true + } + + ScalingLabel{ + text: "Display name:" + } + + TextEdit { + id: txtDisplayName + width: 200 + } + + SimpleButton { + text: "Save" + + onClicked: { + gcd.savePeerSettings(txtOnion.text, txtDisplayName.text) + theStack.title = txtDisplayName.text + theStack.pane = theStack.messagePane + } + } + + + Connections { + target: gcd + + onSupplyPeerSettings: function(onion, nick) { + toolbar.text = nick + txtOnion.text = onion + txtDisplayName.text = nick + } + } +} \ No newline at end of file