forked from cwtch.im/ui
support changing peer/group contact names
This commit is contained in:
parent
eb3f6c9e32
commit
ec004afc1a
|
@ -42,8 +42,9 @@ type GrandCentralDispatcher struct {
|
||||||
_ func(status int, str string) `signal:"TorStatus"`
|
_ func(status int, str string) `signal:"TorStatus"`
|
||||||
|
|
||||||
// other stuff i can't ontologize atm
|
// other stuff i can't ontologize atm
|
||||||
_ func(str string) `signal:"InvokePopup"`
|
_ func(str string) `signal:"InvokePopup"`
|
||||||
_ func(name, server, invitation string) `signal:"SupplyGroupSettings"`
|
_ func(groupID, name, server, invitation string) `signal:"SupplyGroupSettings"`
|
||||||
|
_ func(onion, nick string) `signal:"SupplyPeerSettings"`
|
||||||
|
|
||||||
// signals emitted from the ui (written in go, below)
|
// signals emitted from the ui (written in go, below)
|
||||||
_ func(message string, mid uint) `signal:"sendMessage,auto"`
|
_ func(message string, mid uint) `signal:"sendMessage,auto"`
|
||||||
|
@ -54,6 +55,9 @@ type GrandCentralDispatcher struct {
|
||||||
_ func(nick string) `signal:"updateNick,auto"`
|
_ func(nick string) `signal:"updateNick,auto"`
|
||||||
_ func(server, groupName string) `signal:"createGroup,auto"`
|
_ func(server, groupName string) `signal:"createGroup,auto"`
|
||||||
_ func() `signal:"requestGroupSettings,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) {
|
func (this *GrandCentralDispatcher) sendMessage(message string, mID uint) {
|
||||||
|
@ -137,9 +141,12 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
|
||||||
}
|
}
|
||||||
var name string
|
var name string
|
||||||
var exists bool
|
var exists bool
|
||||||
name, exists = the.Peer.GetProfile().GetAttribute(tl[i].PeerID + "_name")
|
ctc := the.Peer.GetContact(tl[i].PeerID)
|
||||||
if !exists || name == "" {
|
if ctc != nil {
|
||||||
name = tl[i].PeerID[:16] + "..."
|
name, exists = ctc.GetAttribute("nick")
|
||||||
|
if !exists || name == "" {
|
||||||
|
name = tl[i].PeerID[:16] + "..."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.AppendMessage(
|
this.AppendMessage(
|
||||||
handle,
|
handle,
|
||||||
|
@ -156,7 +163,7 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
|
||||||
} // ELSE LOAD CONTACT
|
} // ELSE LOAD CONTACT
|
||||||
|
|
||||||
contact, _ := the.Peer.GetProfile().GetContact(handle)
|
contact, _ := the.Peer.GetProfile().GetContact(handle)
|
||||||
nick,_ := contact.GetAttribute("name")
|
nick,_ := contact.GetAttribute("nick")
|
||||||
if nick == "" {
|
if nick == "" {
|
||||||
this.SetToolbarTitle(handle)
|
this.SetToolbarTitle(handle)
|
||||||
} else {
|
} 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() {
|
func (this *GrandCentralDispatcher) requestGroupSettings() {
|
||||||
log.Debugf("requestGroupSettings()")
|
|
||||||
group := the.Peer.GetGroup(this.CurrentOpenConversation())
|
group := the.Peer.GetGroup(this.CurrentOpenConversation())
|
||||||
|
|
||||||
if group == nil {
|
if group == nil {
|
||||||
log.Errorf("requested group settings for a p2p contact")
|
log.Errorf("couldn't find group %v", this.CurrentOpenConversation())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nick, _ := group.GetAttribute("nick")
|
nick, _ := group.GetAttribute("nick")
|
||||||
invite, _ := the.Peer.ExportGroup(this.CurrentOpenConversation())
|
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) {
|
func (this *GrandCentralDispatcher) broadcast(signal string) {
|
||||||
|
@ -281,14 +342,8 @@ func (this *GrandCentralDispatcher) importString(str string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exists := the.Peer.GetProfile().GetAttribute(name + "_onion")
|
checkc := the.Peer.GetContact(onion)
|
||||||
if exists {
|
if checkc != nil {
|
||||||
this.InvokePopup("can't re-use names :(")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, exists = the.Peer.GetProfile().GetAttribute(onion + "_name")
|
|
||||||
if exists {
|
|
||||||
this.InvokePopup("already have this contact")
|
this.InvokePopup("already have this contact")
|
||||||
return //TODO: bring them to the duplicate
|
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()
|
contacts := the.Peer.GetContacts()
|
||||||
for i := range contacts {
|
for i := range contacts {
|
||||||
contact, _ := the.Peer.GetProfile().GetContact(contacts[i])
|
contact, _ := the.Peer.GetProfile().GetContact(contacts[i])
|
||||||
displayName, _ := contact.GetAttribute("name")
|
displayName, _ := contact.GetAttribute("nick")
|
||||||
gcd.UIState.AddContact(&gobjects.Contact{
|
gcd.UIState.AddContact(&gobjects.Contact{
|
||||||
Handle: contacts[i],
|
Handle: contacts[i],
|
||||||
DisplayName: displayName,
|
DisplayName: displayName,
|
||||||
|
|
14
qml/main.qml
14
qml/main.qml
|
@ -154,19 +154,7 @@ Item {
|
||||||
|
|
||||||
SettingsPane{ anchors.fill: parent }
|
SettingsPane{ anchors.fill: parent }
|
||||||
|
|
||||||
ColumnLayout { // userProfilePane
|
PeerSettingsPane { anchors.fill: parent }
|
||||||
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" }
|
|
||||||
}
|
|
||||||
|
|
||||||
GroupSettingsPane{ anchors.fill: parent }
|
GroupSettingsPane{ anchors.fill: parent }
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import "../widgets"
|
||||||
|
|
||||||
ColumnLayout { // groupSettingsPane
|
ColumnLayout { // groupSettingsPane
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
property string groupID
|
||||||
|
|
||||||
|
|
||||||
StackToolbar {
|
StackToolbar {
|
||||||
|
@ -23,15 +24,7 @@ ColumnLayout { // groupSettingsPane
|
||||||
TextEdit {
|
TextEdit {
|
||||||
id: txtServer
|
id: txtServer
|
||||||
width: 100
|
width: 100
|
||||||
}
|
readOnly: true
|
||||||
|
|
||||||
ScalingLabel{
|
|
||||||
text: "Group name:"
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEdit {
|
|
||||||
id: txtGroupName
|
|
||||||
width: 100
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScalingLabel {
|
ScalingLabel {
|
||||||
|
@ -41,6 +34,7 @@ ColumnLayout { // groupSettingsPane
|
||||||
TextEdit {
|
TextEdit {
|
||||||
id: txtInvitation
|
id: txtInvitation
|
||||||
width: 200
|
width: 200
|
||||||
|
readOnly: true
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleButton {
|
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 {
|
Connections {
|
||||||
target: gcd
|
target: gcd
|
||||||
|
|
||||||
onSupplyGroupSettings: function(name, server, invite) {
|
onSupplyGroupSettings: function(gid, name, server, invite) {
|
||||||
|
groupID = gid
|
||||||
toolbar.text = name
|
toolbar.text = name
|
||||||
txtGroupName.text = name
|
txtGroupName.text = name
|
||||||
txtServer.text = server
|
txtServer.text = server
|
||||||
|
|
|
@ -17,8 +17,13 @@ ColumnLayout {
|
||||||
//text: "open privacy exec"
|
//text: "open privacy exec"
|
||||||
|
|
||||||
aux.onClicked: {
|
aux.onClicked: {
|
||||||
theStack.pane = gcd.currentOpenConversation.length == 32 ? theStack.groupProfilePane : theStack.userProfilePane
|
if (gcd.currentOpenConversation.length == 32) {
|
||||||
gcd.requestGroupSettings()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue