Deleting Contacts, Alerting, Click to Talk

This commit is contained in:
Sarah Jamie Lewis 2019-02-12 23:09:39 -08:00
parent 1c614a9e66
commit 1a800a44bc
11 changed files with 184 additions and 76 deletions

View File

@ -16,9 +16,11 @@ func GroupPoller(getContact func(string) *gobjects.Contact, updateContact func(s
for i := range groups { for i := range groups {
group := the.Peer.GetGroup(groups[i]) group := the.Peer.GetGroup(groups[i])
if group != nil && group.GroupID != "" { if group != nil && group.GroupID != "" {
log.Debugf("Found a Group: %v %v", group.GroupID, group.GroupServer) deleted,_ := group.GetAttribute("deleted")
getContact(group.GroupID).Status = int(servers[group.GroupServer]) if deleted != "deleted" {
updateContact(group.GroupID) getContact(group.GroupID).Status = int(servers[group.GroupServer])
updateContact(group.GroupID)
}
} else { } else {
log.Errorf("grouppoller found a group that is nil :/") log.Errorf("grouppoller found a group that is nil :/")
} }

View File

@ -17,21 +17,25 @@ func PresencePoller(getContact func(string) *gobjects.Contact, addContact func(c
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])
addContact(&gobjects.Contact{ deleted,_ := c.GetAttribute("deleted")
toc.Onion,
toc.Name,
cwutil.RandomProfileImage(toc.Onion),
"",
0,
0,
c.Trusted,
})
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ if deleted != "deleted" {
event.RemotePeer: contacts[i], addContact(&gobjects.Contact{
event.Key: "name", toc.Onion,
event.Data: c.Name, toc.Name,
})) cwutil.RandomProfileImage(toc.Onion),
"",
0,
0,
c.Trusted,
})
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: contacts[i],
event.Key: "name",
event.Data: c.Name,
}))
}
} }
cxnState, found := the.Peer.GetPeers()[contacts[i]] cxnState, found := the.Peer.GetPeers()[contacts[i]]

View File

@ -28,6 +28,7 @@ type GrandCentralDispatcher struct {
// contact list stuff // contact list stuff
_ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"AddContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"AddContact"`
_ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"UpdateContact"` _ func(handle, displayName, image, server string, badge, status int, trusted bool) `signal:"UpdateContact"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"`
// messages pane stuff // messages pane stuff
_ func(handle, from, displayName, message, image string, mID uint, fromMe bool, ts string) `signal:"AppendMessage"` _ func(handle, from, displayName, message, image string, mID uint, fromMe bool, ts string) `signal:"AppendMessage"`
@ -53,11 +54,13 @@ type GrandCentralDispatcher struct {
_ func(str string) `signal:"popup,auto"` _ func(str string) `signal:"popup,auto"`
_ 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(groupID string) `signal:"leaveGroup,auto"`
_ func() `signal:"requestGroupSettings,auto"` _ func() `signal:"requestGroupSettings,auto"`
_ func(groupID, nick string) `signal:"saveGroupSettings,auto"` _ func(groupID, nick string) `signal:"saveGroupSettings,auto"`
_ func() `signal:"requestPeerSettings,auto"` _ func() `signal:"requestPeerSettings,auto"`
_ 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 (this *GrandCentralDispatcher) sendMessage(message string, mID uint) { func (this *GrandCentralDispatcher) sendMessage(message string, mID uint) {
@ -120,8 +123,23 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
this.SetCurrentOpenConversation(handle) this.SetCurrentOpenConversation(handle)
c := this.UIState.GetContact(handle) c := this.UIState.GetContact(handle)
c.Badge = 0 if c == nil {
this.UIState.UpdateContact(handle) this.UIState.AddContact(&gobjects.Contact{
handle,
handle,
cwutil.RandomProfileImage(handle),
"",
0,
0,
false,
})
} else {
c.Badge = 0
this.UIState.UpdateContact(handle)
}
if len(handle) == 32 { // LOAD GROUP if len(handle) == 32 { // LOAD GROUP
log.Debugf("LOADING GROUP %s", handle) log.Debugf("LOADING GROUP %s", handle)
@ -255,11 +273,11 @@ func (this *GrandCentralDispatcher) requestGroupSettings() {
} }
} }
this.SupplyGroupSettings(this.CurrentOpenConversation(), nick, group.GroupServer, invite, contactnames, contactaddrs) this.SupplyGroupSettings(group.GroupID, nick, group.GroupServer, invite, contactnames, contactaddrs)
} }
func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) { func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) {
group := the.Peer.GetGroup(this.CurrentOpenConversation()) group := the.Peer.GetGroup(groupID)
if group == nil { if group == nil {
log.Errorf("couldn't find group %v", groupID) log.Errorf("couldn't find group %v", groupID)
@ -342,8 +360,12 @@ func (this *GrandCentralDispatcher) importString(str string) {
checkc := the.Peer.GetContact(onion) checkc := the.Peer.GetContact(onion)
if checkc != nil { if checkc != nil {
this.InvokePopup("already have this contact") deleted,_ := checkc.GetAttribute("deleted")
return //TODO: bring them to the duplicate if deleted != "deleted" {
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{
@ -397,4 +419,26 @@ func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) {
if err != nil { if err != nil {
log.Errorf("inviting %v to %v: %v", onion, groupID, err) log.Errorf("inviting %v to %v: %v", onion, groupID, err)
} }
}
func (this *GrandCentralDispatcher) leaveGroup(groupID string) {
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{
event.GroupID: groupID,
event.Key: "deleted",
event.Data: "deleted",
}))
this.UIState.UpdateContactAttribute(groupID, "deleted", "deleted")
}
func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) {
pp,_ := the.Peer.GetProfile().GetContact(onion)
if pp != nil {
pp.SetAttribute(key, value)
the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: onion,
event.Key: key,
event.Data: value,
}))
this.UIState.UpdateContactAttribute(onion, key, value)
}
} }

View File

@ -49,28 +49,37 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) {
func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
if _, found := this.contacts[handle]; !found { if _, found := this.contacts[handle]; !found {
if len(handle) == 32 { if len(handle) == 32 {
this.AddContact(&gobjects.Contact{
handle,
handle,
cwutil.RandomGroupImage(handle),
"",
0,
0,
false,
})
group := the.Peer.GetGroup(handle) group := the.Peer.GetGroup(handle)
go the.Peer.JoinServer(group.GroupServer) if group != nil {
this.AddContact(&gobjects.Contact{
handle,
handle,
cwutil.RandomGroupImage(handle),
"",
0,
0,
false,
})
go the.Peer.JoinServer(group.GroupServer)
} else {
log.Errorf("Attempting to add non existent group to ui %v", handle)
}
} else { } else {
this.AddContact(&gobjects.Contact{ contact := the.Peer.GetContact(handle)
handle, if contact != nil && handle != contact.Onion {
handle, this.AddContact(&gobjects.Contact{
cwutil.RandomProfileImage(handle), handle,
"", handle,
0, cwutil.RandomProfileImage(handle),
0, "",
false, 0,
}) 0,
go the.Peer.PeerWithOnion(handle) false,
})
} else if contact == nil {
log.Errorf("Attempting to add non existent contact to ui %v", handle)
}
} }
} }
@ -78,20 +87,9 @@ func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
} }
func (this *InterfaceState) AddMessage(m *gobjects.Message) { func (this *InterfaceState) AddMessage(m *gobjects.Message) {
_, found := this.contacts[m.Handle] this.GetContact(m.From)
if !found {
this.AddContact(&gobjects.Contact{
m.Handle,
m.Handle,
cwutil.RandomProfileImage(m.Handle),
"",
0,
0,
false,
})
}
_, found = this.messages[m.Handle] _, found := this.messages[m.Handle]
if !found { if !found {
this.messages[m.Handle] = make([]*gobjects.Message, 0) this.messages[m.Handle] = make([]*gobjects.Message, 0)
} }
@ -110,8 +108,10 @@ func (this *InterfaceState) AddMessage(m *gobjects.Message) {
this.parentGcd.AppendMessage(m.Handle, m.From, m.DisplayName, m.Message, m.Image, uint(m.MessageID), m.FromMe, m.Timestamp.Format(constants.TIME_FORMAT)) this.parentGcd.AppendMessage(m.Handle, m.From, m.DisplayName, m.Message, m.Image, uint(m.MessageID), m.FromMe, m.Timestamp.Format(constants.TIME_FORMAT))
} else { } else {
c := this.GetContact(m.Handle) c := this.GetContact(m.Handle)
c.Badge++ if c != nil {
this.UpdateContact(c.Handle) c.Badge++
this.UpdateContact(c.Handle)
}
} }
} }
@ -131,3 +131,7 @@ func (this *InterfaceState) UpdateContact(handle string) {
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted)
} }
} }
func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) {
this.parentGcd.UpdateContactAttribute(handle, key, value)
}

36
main.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
libapp "cwtch.im/cwtch/app" libapp "cwtch.im/cwtch/app"
"cwtch.im/cwtch/model"
"cwtch.im/ui/go/characters" "cwtch.im/ui/go/characters"
"cwtch.im/ui/go/cwutil" "cwtch.im/ui/go/cwutil"
"cwtch.im/ui/go/gobjects" "cwtch.im/ui/go/gobjects"
@ -142,29 +141,34 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher, acn connectivity.ACN) {
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")
gcd.UIState.AddContact(&gobjects.Contact{ deleted, _ := contact.GetAttribute("deleted")
Handle: contacts[i], if deleted != "deleted" {
DisplayName: displayName, gcd.UIState.AddContact(&gobjects.Contact{
Image: cwutil.RandomProfileImage(contacts[i]), Handle: contacts[i],
Trusted: contact.Trusted, DisplayName: displayName,
}) Image: cwutil.RandomProfileImage(contacts[i]),
Trusted: contact.Trusted,
})
}
} }
groups := the.Peer.GetGroups() groups := the.Peer.GetGroups()
for i := range groups { for i := range groups {
group := the.Peer.GetGroup(groups[i]) group := the.Peer.GetGroup(groups[i])
group.NewMessage = make(chan model.Message)
the.Peer.JoinServer(group.GroupServer)
nick, exists := group.GetAttribute("nick") nick, exists := group.GetAttribute("nick")
if !exists { if !exists {
nick = group.GroupID[:12] nick = group.GroupID[:12]
} }
gcd.UIState.AddContact(&gobjects.Contact{ deleted,_ := group.GetAttribute("deleted")
Handle: group.GroupID, if deleted != "deleted" {
DisplayName: nick, the.Peer.JoinServer(group.GroupServer)
Image: cwutil.RandomGroupImage(group.GroupID), gcd.UIState.AddContact(&gobjects.Contact{
Server: group.GroupServer, Handle: group.GroupID,
Trusted: group.Accepted, DisplayName: nick,
}) Image: cwutil.RandomGroupImage(group.GroupID),
Server: group.GroupServer,
Trusted: group.Accepted,
})
}
} }
} }

View File

@ -52,6 +52,9 @@ ColumnLayout {
"_ts": ts, "_ts": ts,
}) })
// If the window is out of focus, alert the user (makes taskbar light up)
windowItem.alert(0)
if (sv.contentY + sv.height >= sv.contentHeight - colMessages.height && sv.contentHeight > sv.height) { if (sv.contentY + sv.height >= sv.contentHeight - colMessages.height && sv.contentHeight > sv.height) {
sv.contentY = sv.contentHeight - sv.height sv.contentY = sv.contentHeight - sv.height
} }

View File

@ -11,6 +11,7 @@ import "../styles"
import "../utils.js" as Utils import "../utils.js" as Utils
ColumnLayout { // groupSettingsPane ColumnLayout { // groupSettingsPane
id: gsp
anchors.fill: parent anchors.fill: parent
property string groupID property string groupID
property variant addrbook property variant addrbook
@ -104,13 +105,24 @@ ColumnLayout { // groupSettingsPane
} }
} }
SimpleButton {
icon: "regular/trash-alt"
text: "delete"
onClicked: {
gcd.leaveGroup(groupID)
theStack.pane = theStack.emptyPane
}
}
}//end of column with padding }//end of column with padding
Connections { Connections {
target: gcd target: gcd
onSupplyGroupSettings: function(gid, name, server, invite, addrbooknames, addrbookaddrs) { onSupplyGroupSettings: function(gid, name, server, invite, addrbooknames, addrbookaddrs) {
groupID = gid console.log("Supplied " + gid + " " + name)
gsp.groupID = gid
toolbar.text = name toolbar.text = name
txtGroupName.text = name txtGroupName.text = name
txtServer.text = server txtServer.text = server

View File

@ -65,6 +65,16 @@ ColumnLayout { // peerSettingsPane
} }
} }
SimpleButton {
icon: "regular/trash-alt"
text: "delete"
onClicked: {
gcd.setAttribute(txtOnion.text, "deleted", "deleted")
theStack.pane = theStack.emptyPane
}
}
}//end of column with padding }//end of column with padding

View File

@ -48,8 +48,21 @@ ColumnLayout {
"_badge": badge, "_badge": badge,
"_status": status, "_status": status,
"_trusted": trusted, "_trusted": trusted,
"_deleted": false
}) })
} }
onUpdateContactAttribute: function(handle, key, value) {
if (key == "deleted" && value == "deleted") {
for(var i = 0; i<contactsModel.count;i++){
if(contactsModel.get(i)["_handle"] == handle) {
console.log("deleting contact " + contactsModel.get(i).handle)
contactsModel.get(i)._deleted = true
}
}
}
}
} }
ListModel { // CONTACT OBJECTS ARE STORED HERE ... ListModel { // CONTACT OBJECTS ARE STORED HERE ...
@ -66,6 +79,7 @@ ColumnLayout {
badge: _badge badge: _badge
status: _status status: _status
trusted: _trusted trusted: _trusted
deleted: _deleted
} }
} }
} }

View File

@ -8,7 +8,7 @@ import CustomQmlTypes 1.0
RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY RowLayout { // 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: true visible: !deleted
property alias displayName: cn.text property alias displayName: cn.text
property alias image: imgProfile.source property alias image: imgProfile.source
@ -17,6 +17,7 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
property bool isActive property bool isActive
property bool isHover property bool isHover
property bool trusted property bool trusted
property bool deleted
property alias status: imgProfile.status property alias status: imgProfile.status
property string server property string server

View File

@ -38,6 +38,16 @@ RowLayout {
id: imgProfile id: imgProfile
anchors.left: parent.left anchors.left: parent.left
visible: !fromMe visible: !fromMe
MouseArea {
anchors.fill: parent
onClicked: {
gcd.broadcast("ResetMessagePane")
theStack.pane = theStack.messagePane
gcd.loadMessagesPane(from)
overlayStack.overlay = overlayStack.chatOverlay
}
}
} }
Rectangle { // THIS IS JUST A PRETTY MESSAGE-HOLDING RECTANGLE Rectangle { // THIS IS JUST A PRETTY MESSAGE-HOLDING RECTANGLE