support changing peer/group contact names #56
|
@ -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
|
||||
}
|
||||
|
|
2
main.go
2
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,
|
||||
|
|
14
qml/main.qml
14
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 }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue