removing fake delete to surface fake deleted contact as we still connect to them; adopting proper delete support added to cwtch

This commit is contained in:
Dan Ballard 2019-08-06 22:28:55 -07:00
parent 6de3805ecf
commit 12fde77c71
7 changed files with 60 additions and 74 deletions

View File

@ -83,17 +83,15 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool
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("nick") displayName, _ := contact.GetAttribute("nick")
deleted, _ := contact.GetAttribute("deleted")
if deleted != "deleted" { gcd.UIState.AddContact(&gobjects.Contact{
gcd.UIState.AddContact(&gobjects.Contact{ Handle: contacts[i],
Handle: contacts[i], DisplayName: displayName,
DisplayName: displayName, Image: cwutil.RandomProfileImage(contacts[i]),
Image: cwutil.RandomProfileImage(contacts[i]), Trusted: contact.Trusted,
Trusted: contact.Trusted, Blocked: contact.Blocked,
Blocked: contact.Blocked, Loading: false,
Loading: false, })
})
}
} }
groups := the.Peer.GetGroups() groups := the.Peer.GetGroups()
@ -103,19 +101,15 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool
if !exists { if !exists {
nick = group.GroupID[:12] nick = group.GroupID[:12]
} }
deleted, _ := group.GetAttribute("deleted")
// Only join servers for active and explicitly accepted groups. // Only join servers for active and explicitly accepted groups.
if deleted != "deleted" { gcd.UIState.AddContact(&gobjects.Contact{
Handle: group.GroupID,
gcd.UIState.AddContact(&gobjects.Contact{ DisplayName: nick,
Handle: group.GroupID, Image: cwutil.RandomGroupImage(group.GroupID),
DisplayName: nick, Server: group.GroupServer,
Image: cwutil.RandomGroupImage(group.GroupID), Trusted: group.Accepted,
Server: group.GroupServer, Loading: false,
Trusted: group.Accepted, })
Loading: false,
})
}
} }
if e.Data[event.Status] != "running" { if e.Data[event.Status] != "running" {

View File

@ -18,29 +18,25 @@ func PresencePoller(uiState *gothings.InterfaceState) {
if ct == nil { // new contact has attempted to connect with us, treat it as an invite if ct == nil { // new contact has attempted to connect with us, treat it as an invite
toc := the.Peer.GetContact(contacts[i]) toc := the.Peer.GetContact(contacts[i])
c, _ := the.Peer.GetProfile().GetContact(contacts[i]) c, _ := the.Peer.GetProfile().GetContact(contacts[i])
deleted, _ := c.GetAttribute("deleted")
if deleted != "deleted" { uiState.AddContact(&gobjects.Contact{
uiState.AddContact(&gobjects.Contact{ toc.Onion,
toc.Onion, toc.Name,
toc.Name, cwutil.RandomProfileImage(toc.Onion),
cwutil.RandomProfileImage(toc.Onion), "",
"", 0,
0, 0,
0, c.Trusted,
c.Trusted, c.Blocked,
c.Blocked, false,
false, })
})
the.EventBus.Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ the.EventBus.Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: contacts[i], event.RemotePeer: contacts[i],
event.Key: "name", event.Key: "name",
event.Data: c.Name, event.Data: c.Name,
})) }))
}
} }
} }
time.Sleep(time.Second * 4) time.Sleep(time.Second * 4)
} }

View File

@ -32,7 +32,8 @@ type GrandCentralDispatcher struct {
// contact list stuff // contact list stuff
_ func(handle, displayName, image, server string, badge, status int, trusted bool, blocked bool, loading bool) `signal:"AddContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool, blocked bool, loading bool) `signal:"AddContact"`
_ func(handle, displayName, image, server string, badge, status int, trusted bool, blocked bool, loading bool) `signal:"UpdateContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool, blocked bool, loading bool) `signal:"UpdateContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"` _ func(handle string) `signal:"RemoveContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"`
// messages pane stuff // messages pane stuff
_ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool, error bool) `signal:"AppendMessage"` _ func(handle, from, displayName, message, image string, mID string, fromMe bool, ts string, ackd bool, error bool) `signal:"AppendMessage"`
@ -52,7 +53,7 @@ type GrandCentralDispatcher struct {
_ func(str string) `signal:"InvokePopup"` _ func(str string) `signal:"InvokePopup"`
_ func(zoom, locale string) `signal:"SupplySettings"` _ func(zoom, locale string) `signal:"SupplySettings"`
_ func(groupID, name, server, invitation string, accepted bool, addrbooknames, addrbookaddrs []string) `signal:"SupplyGroupSettings"` _ func(groupID, name, server, invitation string, accepted bool, addrbooknames, addrbookaddrs []string) `signal:"SupplyGroupSettings"`
_ func(onion, nick string, blocked bool) `signal:"SupplyPeerSettings"` _ func(onion, nick string, blocked bool) `signal:"SupplyPeerSettings"`
// signals emitted from the ui (written in go, below) // signals emitted from the ui (written in go, below)
_ func(message string, mid string) `signal:"sendMessage,auto"` _ func(message string, mid string) `signal:"sendMessage,auto"`
@ -74,6 +75,7 @@ type GrandCentralDispatcher struct {
_ func(onion, nick string) `signal:"savePeerSettings,auto"` _ func(onion, nick string) `signal:"savePeerSettings,auto"`
_ func(onion, groupID string) `signal:"inviteToGroup,auto"` _ func(onion, groupID string) `signal:"inviteToGroup,auto"`
_ func(onion, key, nick string) `signal:"setAttribute,auto"` _ func(onion, key, nick string) `signal:"setAttribute,auto"`
_ func(onion string) `signal:"deleteContact,auto""`
_ func(locale string) `signal:"setLocale,auto"` _ func(locale string) `signal:"setLocale,auto"`
} }
@ -431,12 +433,8 @@ func (this *GrandCentralDispatcher) importString(str string) {
checkc := the.Peer.GetContact(onion) checkc := the.Peer.GetContact(onion)
if checkc != nil { if checkc != nil {
deleted, _ := checkc.GetAttribute("deleted") this.InvokePopup("already have this contact")
if deleted != "deleted" { return //TODO: bring them to the duplicate
this.InvokePopup("already have this contact")
return //TODO: bring them to the duplicate
}
this.SetAttribute(onion, "deleted", "")
} }
this.UIState.AddContact(&gobjects.Contact{ this.UIState.AddContact(&gobjects.Contact{
@ -484,7 +482,6 @@ func (this *GrandCentralDispatcher) createGroup(server, groupName string) {
the.Peer.JoinServer(server) the.Peer.JoinServer(server)
} }
func (this *GrandCentralDispatcher) blockPeer(onion string) { func (this *GrandCentralDispatcher) blockPeer(onion string) {
err := the.Peer.BlockPeer(onion) err := the.Peer.BlockPeer(onion)
if err != nil { if err != nil {
@ -502,7 +499,6 @@ func (this *GrandCentralDispatcher) unblockPeer(onion string) {
this.UIState.UpdateContact(onion) this.UIState.UpdateContact(onion)
} }
func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) { func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) {
err := the.Peer.InviteOnionToGroup(onion, groupID) err := the.Peer.InviteOnionToGroup(onion, groupID)
if err != nil { if err != nil {
@ -511,12 +507,13 @@ func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) {
} }
func (this *GrandCentralDispatcher) leaveGroup(groupID string) { func (this *GrandCentralDispatcher) leaveGroup(groupID string) {
the.EventBus.Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{ the.Peer.DeleteGroup(groupID)
event.GroupID: groupID, this.RemoveContact(groupID)
event.Key: "deleted", }
event.Data: "deleted",
})) func (this *GrandCentralDispatcher) deleteContact(onion string) {
this.UIState.UpdateContactAttribute(groupID, "deleted", "deleted") the.Peer.DeleteContact(onion)
this.RemoveContact(onion)
} }
func (this *GrandCentralDispatcher) acceptGroup(groupID string) { func (this *GrandCentralDispatcher) acceptGroup(groupID string) {

View File

@ -49,6 +49,10 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
} }
} }
func (this *InterfaceState) DeleteContact(id string) {
this.contacts.Delete(id)
}
func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
if _, found := this.contacts.Load(handle); !found { if _, found := this.contacts.Load(handle); !found {
if len(handle) == 32 { if len(handle) == 32 {

View File

@ -99,7 +99,7 @@ ColumnLayout { // peerSettingsPane
text: qsTr("delete-btn") text: qsTr("delete-btn")
onClicked: { onClicked: {
gcd.setAttribute(txtOnion.text, "deleted", "deleted") gcd.deleteContact(txtOnion.text)
theStack.pane = theStack.emptyPane theStack.pane = theStack.emptyPane
} }
} }

View File

@ -57,22 +57,20 @@ ColumnLayout {
"_status": status, "_status": status,
"_trusted": trusted, "_trusted": trusted,
"_blocked": blocked, "_blocked": blocked,
"_deleted": false,
"_loading": loading, "_loading": loading,
"_loading": loading
}) })
} }
onUpdateContactAttribute: function(handle, key, value) { onRemoveContact: function(handle) {
if (key == "deleted" && value == "deleted") { for(var i = 0; i < contactsModel.count; i++){
for(var i = 0; i<contactsModel.count;i++){ if(contactsModel.get(i)["_handle"] == handle) {
if(contactsModel.get(i)["_handle"] == handle) { console.log("deleting contact " + contactsModel.get(i)["_handle"])
console.log("deleting contact " + contactsModel.get(i).handle) contactsModel.remove(i)
contactsModel.get(i)._deleted = true return
} }
} }
}
} }
} }
ListModel { // CONTACT OBJECTS ARE STORED HERE ... ListModel { // CONTACT OBJECTS ARE STORED HERE ...
@ -90,7 +88,6 @@ ColumnLayout {
status: _status status: _status
trusted: _trusted trusted: _trusted
blocked: _blocked blocked: _blocked
deleted: _deleted
loading: _loading loading: _loading
} }
} }

View File

@ -12,7 +12,6 @@ import QtQuick.Controls.Styles 1.4
Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
visible: !deleted
height: 48 * logscale + 3 height: 48 * logscale + 3
implicitHeight: height implicitHeight: height
@ -25,7 +24,6 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
property bool isHover property bool isHover
property bool trusted property bool trusted
property bool blocked property bool blocked
property bool deleted
property bool loading property bool loading
property alias status: imgProfile.status property alias status: imgProfile.status
property string server property string server