remove uistate's state; remove contact; remove trusted
the build was successful Details

This commit is contained in:
Dan Ballard 2019-11-01 17:40:06 -07:00
parent 30b8d9ab6d
commit f0099acb2b
16 changed files with 165 additions and 344 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module cwtch.im/ui
go 1.12 go 1.12
require ( require (
cwtch.im/cwtch v0.3.2 cwtch.im/cwtch v0.3.3
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6 git.openprivacy.ca/openprivacy/libricochet-go v1.0.6
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/kr/pretty v0.1.0 // indirect github.com/kr/pretty v0.1.0 // indirect

10
go.sum
View File

@ -4,6 +4,8 @@ cwtch.im/cwtch v0.3.1 h1:C0DLIrOqpNs5aecKTjNJZhpMq4/EvWNmLiKklIS8RTM=
cwtch.im/cwtch v0.3.1/go.mod h1:8tmtp3c7fccWw9H7s9u6E8GD2PKI3ar21i0fjN8pzd0= cwtch.im/cwtch v0.3.1/go.mod h1:8tmtp3c7fccWw9H7s9u6E8GD2PKI3ar21i0fjN8pzd0=
cwtch.im/cwtch v0.3.2 h1:JxoauToMckHjmQz3QCmI7XG9pun1tF3pV/o5ziuqV1A= cwtch.im/cwtch v0.3.2 h1:JxoauToMckHjmQz3QCmI7XG9pun1tF3pV/o5ziuqV1A=
cwtch.im/cwtch v0.3.2/go.mod h1:4b2qGW5bZKm4CwYxqc0+4pgpDU0LjjyoihC8a/ezOoQ= cwtch.im/cwtch v0.3.2/go.mod h1:4b2qGW5bZKm4CwYxqc0+4pgpDU0LjjyoihC8a/ezOoQ=
cwtch.im/cwtch v0.3.3 h1:mAypnkTCehej5ebSEzl43nPufsyyXLNz/dw2RWOO+Wk=
cwtch.im/cwtch v0.3.3/go.mod h1:I95rbE3aK8uic7LsMOB1lfJDSzlNsRUP0/5cFCLkD0Y=
cwtch.im/tapir v0.1.10 h1:V+TkmwXNd6gySZqlVw468wMYEkmDwMSyvhkkpOfUw7w= cwtch.im/tapir v0.1.10 h1:V+TkmwXNd6gySZqlVw468wMYEkmDwMSyvhkkpOfUw7w=
cwtch.im/tapir v0.1.10/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34= cwtch.im/tapir v0.1.10/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
cwtch.im/tapir v0.1.11 h1:JLm1MIYq4VXKzhj68+P8OuVPllAU9U6G0DtUor2fbc4= cwtch.im/tapir v0.1.11 h1:JLm1MIYq4VXKzhj68+P8OuVPllAU9U6G0DtUor2fbc4=
@ -14,6 +16,7 @@ git.openprivacy.ca/openprivacy/libricochet-go v1.0.6/go.mod h1:yMSG1gBaP4f1U+RMZ
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/c-bata/go-prompt v0.2.3/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34= github.com/c-bata/go-prompt v0.2.3/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g= github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw= github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -25,6 +28,7 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f h1:KMlcu9X58lhTA/KrfX8Bi1LQSO4pzoVjTiL3h4Jk+Zk= github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f h1:KMlcu9X58lhTA/KrfX8Bi1LQSO4pzoVjTiL3h4Jk+Zk=
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gordonklaus/ineffassign v0.0.0-20190601041439-ed7b1b5ee0f8/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@ -61,14 +65,17 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -78,7 +85,10 @@ golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191031220737-6d8f1af9ccc0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -5,7 +5,6 @@ import (
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"cwtch.im/ui/go/constants" "cwtch.im/ui/go/constants"
"cwtch.im/ui/go/cwutil" "cwtch.im/ui/go/cwutil"
"cwtch.im/ui/go/gobjects"
"cwtch.im/ui/go/gothings" "cwtch.im/ui/go/gothings"
"cwtch.im/ui/go/the" "cwtch.im/ui/go/the"
"git.openprivacy.ca/openprivacy/libricochet-go/log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
@ -86,36 +85,13 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool
contacts := the.Peer.GetContacts() contacts := the.Peer.GetContacts()
for i := range contacts { for i := range contacts {
contact, _ := the.Peer.GetProfile().GetContact(contacts[i]) gcd.UIState.AddContact(contacts[i])
displayName, _ := contact.GetAttribute(constants.Nick)
gcd.UIState.AddContact(&gobjects.Contact{
Handle: contacts[i],
DisplayName: displayName,
Image: cwutil.RandomProfileImage(contacts[i]),
Trusted: contact.Trusted,
Blocked: contact.Blocked,
Loading: false,
})
} }
groups := the.Peer.GetGroups() groups := the.Peer.GetGroups()
for i := range groups { for i := range groups {
group := the.Peer.GetGroup(groups[i])
nick, exists := group.GetAttribute(constants.Nick)
if !exists {
nick = group.GroupID[:12]
}
// Only join servers for active and explicitly accepted groups. // Only join servers for active and explicitly accepted groups.
gcd.UIState.AddContact(&gobjects.Contact{ gcd.UIState.AddContact(groups[i])
Handle: group.GroupID,
DisplayName: nick,
Image: cwutil.RandomGroupImage(group.GroupID),
Server: group.GroupServer,
Trusted: group.Accepted,
Loading: false,
})
} }
if e.Data[event.Status] != "running" { if e.Data[event.Status] != "running" {

View File

@ -73,14 +73,7 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
gid, err := the.Peer.GetProfile().ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer]) gid, err := the.Peer.GetProfile().ProcessInvite(e.Data[event.GroupInvite], e.Data[event.RemotePeer])
group := the.Peer.GetGroup(gid) group := the.Peer.GetGroup(gid)
if err == nil && group != nil { if err == nil && group != nil {
uiState.AddContact(&gobjects.Contact{ uiState.AddContact(gid)
Handle: gid,
DisplayName: gid,
Image: cwutil.RandomGroupImage(gid),
Server: group.GroupServer,
Trusted: false,
Loading: false,
})
} }
case event.SendMessageToGroupError: case event.SendMessageToGroupError:
uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error]) uiState.AddSendMessageError(e.Data[event.GroupServer], e.Data[event.Signature], e.Data[event.Error])
@ -90,37 +83,21 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]] cxnState := connections.ConnectionStateToType[e.Data[event.ConnectionState]]
// if it's not in the.Peer it's new. Only add once Authed // if it's not in the.Peer it's new. Only add once Authed
_, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]] if _, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; !exists {
if !exists {
// Contact does not exist, we will add them but we won't know who they are until they are authenticated // Contact does not exist, we will add them but we won't know who they are until they are authenticated
// So if we get any other state from an unknown contact we do nothing // So if we get any other state from an unknown contact we do nothing
// (the next exists check will fail) // (the next exists check will fail)
if cxnState == connections.AUTHENTICATED { if cxnState == connections.AUTHENTICATED {
the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false) the.Peer.AddContact(e.Data[event.RemotePeer], e.Data[event.RemotePeer], false)
uiState.AddContact(e.Data[event.RemotePeer])
} }
} }
// if it's in the.Peer its either existing and needs an update or not in the UI and needs to be added // if it's in the.Peer its either existing and needs an update or not in the UI and needs to be added
if contact, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; exists { if contact, exists := the.Peer.GetProfile().Contacts[e.Data[event.RemotePeer]]; exists {
contact.State = e.Data[event.ConnectionState] contact.State = e.Data[event.ConnectionState]
uiContact := uiState.GetContact(contact.Onion) uiState.UpdateContactStatus(contact.Onion, int(cxnState), false)
if uiContact != nil {
if uiContact.Status != int(cxnState) {
uiContact.Status = int(cxnState)
uiState.UpdateContact(contact.Onion)
}
} else {
uiState.AddContact(&gobjects.Contact{
e.Data[event.RemotePeer],
e.Data[event.RemotePeer],
cwutil.RandomProfileImage(e.Data[event.RemotePeer]),
"",
int(cxnState),
false,
false,
false,
})
}
} }
case event.ServerStateChange: case event.ServerStateChange:
serverOnion := e.Data[event.GroupServer] serverOnion := e.Data[event.GroupServer]
@ -128,15 +105,13 @@ func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
groups := the.Peer.GetGroups() groups := the.Peer.GetGroups()
for _, groupID := range groups { for _, groupID := range groups {
group := the.Peer.GetGroup(groupID) group := the.Peer.GetGroup(groupID)
group.State = e.Data[event.ConnectionState]
if group != nil && group.GroupServer == serverOnion { if group != nil && group.GroupServer == serverOnion {
uiState.GetContact(group.GroupID).Status = int(state) group.State = e.Data[event.ConnectionState]
loading := false
if state == connections.AUTHENTICATED { if state == connections.AUTHENTICATED {
uiState.GetContact(group.GroupID).Loading = true loading = true
} else {
uiState.GetContact(group.GroupID).Loading = false
} }
uiState.UpdateContact(group.GroupID) uiState.UpdateContactStatus(group.GroupID, int(state), loading)
} else { } else {
log.Errorf("found group that is nil :/") log.Errorf("found group that is nil :/")
} }

View File

@ -2,3 +2,4 @@ package constants
const Nick = "nick" const Nick = "nick"
const LastRead = "last-read" const LastRead = "last-read"
const Picture = "picture"

View File

@ -3,7 +3,6 @@ package cwutil
import ( import (
"encoding/base32" "encoding/base32"
"encoding/hex" "encoding/hex"
"fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"strings" "strings"
) )
@ -23,7 +22,7 @@ func RandomGroupImage(handle string) string {
choices := []string{"001-borobudur", "002-opera-house", "003-burj-al-arab", "004-chrysler", "005-acropolis", "006-empire-state-building", "007-temple", "008-indonesia-1", "009-new-zealand", "010-notre-dame", "011-space-needle", "012-seoul", "013-mosque", "014-milan", "015-statue", "016-pyramid", "017-cologne", "018-brandenburg-gate", "019-berlin-cathedral", "020-hungarian-parliament", "021-buckingham", "022-thailand", "023-independence", "024-angkor-wat", "025-vaticano", "026-christ-the-redeemer", "027-colosseum", "028-golden-gate-bridge", "029-sphinx", "030-statue-of-liberty", "031-cradle-of-humankind", "032-istanbul", "033-london-eye", "034-sagrada-familia", "035-tower-bridge", "036-burj-khalifa", "037-washington", "038-big-ben", "039-stonehenge", "040-white-house", "041-ahu-tongariki", "042-capitol", "043-eiffel-tower", "044-church-of-the-savior-on-spilled-blood", "045-arc-de-triomphe", "046-windmill", "047-louvre", "048-torii-gate", "049-petronas", "050-matsumoto-castle", "051-fuji", "052-temple-of-heaven", "053-pagoda", "054-chichen-itza", "055-forbidden-city", "056-merlion", "057-great-wall-of-china", "058-taj-mahal", "059-pisa", "060-indonesia"} choices := []string{"001-borobudur", "002-opera-house", "003-burj-al-arab", "004-chrysler", "005-acropolis", "006-empire-state-building", "007-temple", "008-indonesia-1", "009-new-zealand", "010-notre-dame", "011-space-needle", "012-seoul", "013-mosque", "014-milan", "015-statue", "016-pyramid", "017-cologne", "018-brandenburg-gate", "019-berlin-cathedral", "020-hungarian-parliament", "021-buckingham", "022-thailand", "023-independence", "024-angkor-wat", "025-vaticano", "026-christ-the-redeemer", "027-colosseum", "028-golden-gate-bridge", "029-sphinx", "030-statue-of-liberty", "031-cradle-of-humankind", "032-istanbul", "033-london-eye", "034-sagrada-familia", "035-tower-bridge", "036-burj-khalifa", "037-washington", "038-big-ben", "039-stonehenge", "040-white-house", "041-ahu-tongariki", "042-capitol", "043-eiffel-tower", "044-church-of-the-savior-on-spilled-blood", "045-arc-de-triomphe", "046-windmill", "047-louvre", "048-torii-gate", "049-petronas", "050-matsumoto-castle", "051-fuji", "052-temple-of-heaven", "053-pagoda", "054-chichen-itza", "055-forbidden-city", "056-merlion", "057-great-wall-of-china", "058-taj-mahal", "059-pisa", "060-indonesia"}
barr, err := hex.DecodeString(handle) barr, err := hex.DecodeString(handle)
if err != nil || len(barr) == 0 { if err != nil || len(barr) == 0 {
fmt.Printf("error: %v %v %v\n", handle, err, barr) log.Errorf("error: %v %v %v\n", handle, err, barr)
return "qrc:/qml/images/extra/openprivacy.png" return "qrc:/qml/images/extra/openprivacy.png"
} }
return "qrc:/qml/images/servers/" + choices[int(barr[0])%len(choices)] + ".png" return "qrc:/qml/images/servers/" + choices[int(barr[0])%len(choices)] + ".png"

View File

@ -1,12 +0,0 @@
package gobjects
type Contact struct {
Handle string
DisplayName string
Image string
Server string
Status int
Trusted bool
Blocked bool
Loading bool
}

View File

@ -2,6 +2,7 @@ package gothings
import ( import (
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/ui/go/constants" "cwtch.im/ui/go/constants"
"cwtch.im/ui/go/cwutil" "cwtch.im/ui/go/cwutil"
"github.com/therecipe/qt/qml" "github.com/therecipe/qt/qml"
@ -30,11 +31,13 @@ type GrandCentralDispatcher struct {
_ string `property:"buildDate"` _ string `property:"buildDate"`
// 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, blocked bool, loading bool) `signal:"AddContact"`
_ func(handle, displayName, image, server string, status int, trusted bool, blocked bool, loading bool) `signal:"UpdateContact"` _ func(handle, displayName string) `signal:"UpdateContactDisplayName"`
_ func(handle string) `signal:"IncContactUnreadCount"` _ func(handle string, status int, loading bool) `signal:"UpdateContactStatus"`
_ func(handle string) `signal:"RemoveContact"` _ func(handle string, blocked bool) `signal:"UpdateContactBlocked"`
_ func(handle, key, value string) `signal:"UpdateContactAttribute"` _ func(handle string) `signal:"IncContactUnreadCount"`
_ 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"`
@ -94,16 +97,13 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
return return
} }
if len(this.CurrentOpenConversation()) == 32 { // SEND TO GROUP if isGroup(this.CurrentOpenConversation()) {
if !the.Peer.GetGroup(this.CurrentOpenConversation()).Accepted { if !the.Peer.GetGroup(this.CurrentOpenConversation()).Accepted {
err := the.Peer.AcceptInvite(this.CurrentOpenConversation()) err := the.Peer.AcceptInvite(this.CurrentOpenConversation())
if err != nil { if err != nil {
log.Errorf("tried to mark a nonexistent group as existed. bad!") log.Errorf("tried to mark a nonexistent group as existed. bad!")
return return
} }
c := this.UIState.GetContact(this.CurrentOpenConversation())
c.Trusted = true
this.UIState.UpdateContact(c.Handle)
} }
var err error var err error
@ -127,13 +127,6 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID string) {
return return
} }
} else { } else {
// TODO: require explicit invite accept/reject instead of implicitly trusting on send
if !this.UIState.GetContact(this.CurrentOpenConversation()).Trusted {
this.UIState.GetContact(this.CurrentOpenConversation()).Trusted = true
this.UIState.UpdateContact(this.CurrentOpenConversation())
}
to := this.CurrentOpenConversation() to := this.CurrentOpenConversation()
mID = the.Peer.SendMessageToPeer(to, message) mID = the.Peer.SendMessageToPeer(to, message)
@ -163,28 +156,20 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
} }
this.ClearMessages() this.ClearMessages()
this.SetCurrentOpenConversation(handle) this.SetCurrentOpenConversation(handle)
c := this.UIState.GetContact(handle)
if c == nil { if isGroup(handle) { // LOAD GROUP
this.UIState.AddContact(&gobjects.Contact{
handle,
handle,
cwutil.RandomProfileImage(handle),
"",
0,
false,
false,
false,
})
} else {
this.UIState.UpdateContact(handle)
}
if len(handle) == 32 { // LOAD GROUP
group := the.Peer.GetGroup(handle) group := the.Peer.GetGroup(handle)
loading := false
state := connections.ConnectionStateToType[group.State]
if state == connections.AUTHENTICATED {
loading = true
}
this.UpdateContactStatus(group.GroupID, int(state), loading)
tl := group.GetTimeline() tl := group.GetTimeline()
nick, _ := group.GetAttribute(constants.Nick) nick, _ := group.GetAttribute(constants.Nick)
updateLastReadTime(group) updateLastReadTime(group.GroupID)
if nick == "" { if nick == "" {
this.SetToolbarTitle(handle) this.SetToolbarTitle(handle)
} else { } else {
@ -226,6 +211,9 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
} // ELSE LOAD CONTACT } // ELSE LOAD CONTACT
contact, _ := the.Peer.GetProfile().GetContact(handle) contact, _ := the.Peer.GetProfile().GetContact(handle)
this.UpdateContactStatus(handle, int(connections.ConnectionStateToType[contact.State]), false)
var nick string var nick string
if contact != nil { if contact != nil {
nick, _ = contact.GetAttribute(constants.Nick) nick, _ = contact.GetAttribute(constants.Nick)
@ -233,7 +221,7 @@ func (this *GrandCentralDispatcher) loadMessagesPaneHelper(handle string) {
nick = handle nick = handle
} }
} }
updateLastReadTime(contact) updateLastReadTime(contact.Onion)
this.SetToolbarTitle(nick) this.SetToolbarTitle(nick)
peer := the.Peer.GetContact(handle) peer := the.Peer.GetContact(handle)
@ -286,11 +274,7 @@ func (this *GrandCentralDispatcher) saveSettings(zoom, locale string) {
return return
} }
the.EventBus.Publish(event.NewEvent(event.SetAttribute, map[event.Field]string{ the.Peer.SetAttribute(constants.ZoomSetting, zoom)
event.Key: constants.ZoomSetting,
event.Data: zoom,
}))
the.Peer.GetProfile().SetAttribute(constants.ZoomSetting, zoom)
} }
func (this *GrandCentralDispatcher) requestPeerSettings() { func (this *GrandCentralDispatcher) requestPeerSettings() {
@ -312,23 +296,8 @@ func (this *GrandCentralDispatcher) requestPeerSettings() {
} }
func (this *GrandCentralDispatcher) savePeerSettings(onion, nick string) { func (this *GrandCentralDispatcher) savePeerSettings(onion, nick string) {
contact := the.Peer.GetContact(onion) the.Peer.SetContactAttribute(onion, constants.Nick, nick)
if contact == nil { this.UpdateContactDisplayName(onion, nick)
log.Errorf("error: tried to save settings for unknown peer %v", onion)
return
}
contact.SetAttribute(constants.Nick, nick)
the.EventBus.Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{
event.RemotePeer: onion,
event.Key: constants.Nick,
event.Data: nick,
}))
cif, _ := this.UIState.contacts.Load(onion)
c := cif.(*gobjects.Contact)
c.DisplayName = nick
this.UIState.UpdateContact(onion)
} }
func (this *GrandCentralDispatcher) requestGroupSettings(groupID string) { func (this *GrandCentralDispatcher) requestGroupSettings(groupID string) {
@ -357,24 +326,8 @@ func (this *GrandCentralDispatcher) requestGroupSettings(groupID string) {
} }
func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) { func (this *GrandCentralDispatcher) saveGroupSettings(groupID, nick string) {
group := the.Peer.GetGroup(groupID) the.Peer.SetGroupAttribute(groupID, constants.Nick, nick)
this.UpdateContactDisplayName(groupID, nick)
if group == nil {
log.Errorf("couldn't find group %v", groupID)
return
}
group.SetAttribute(constants.Nick, nick)
the.EventBus.Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{
event.GroupID: groupID,
event.Key: constants.Nick,
event.Data: nick,
}))
cif, _ := this.UIState.contacts.Load(groupID)
c := cif.(*gobjects.Contact)
c.DisplayName = nick
this.UIState.UpdateContact(groupID)
} }
func (this *GrandCentralDispatcher) broadcast(signal string) { func (this *GrandCentralDispatcher) broadcast(signal string) {
@ -446,12 +399,7 @@ func (this *GrandCentralDispatcher) importString(str string) {
return //TODO: bring them to the duplicate return //TODO: bring them to the duplicate
} }
this.UIState.AddContact(&gobjects.Contact{ this.UIState.AddContact(onion)
Handle: onion,
DisplayName: name,
Image: cwutil.RandomProfileImage(onion),
Trusted: true,
})
} }
func (this *GrandCentralDispatcher) popup(str string) { func (this *GrandCentralDispatcher) popup(str string) {
@ -472,21 +420,9 @@ func (this *GrandCentralDispatcher) createGroup(server, groupName string) {
return return
} }
this.UIState.AddContact(&gobjects.Contact{ this.UIState.AddContact(groupID)
Handle: groupID,
DisplayName: groupName,
Image: cwutil.RandomGroupImage(groupID),
Server: server,
Trusted: true,
})
group := the.Peer.GetGroup(groupID) the.Peer.SetGroupAttribute(groupID, constants.Nick, groupName)
group.SetAttribute(constants.Nick, groupName)
the.EventBus.Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{
event.GroupID: groupID,
event.Key: constants.Nick,
event.Data: groupName,
}))
the.Peer.JoinServer(server) the.Peer.JoinServer(server)
} }
@ -496,7 +432,7 @@ func (this *GrandCentralDispatcher) blockPeer(onion string) {
if err != nil { if err != nil {
this.InvokePopup("Error Blocking Peer: " + err.Error()) this.InvokePopup("Error Blocking Peer: " + err.Error())
} }
this.UIState.UpdateContact(onion) this.UpdateContactBlocked(onion, true)
} }
func (this *GrandCentralDispatcher) unblockPeer(onion string) { func (this *GrandCentralDispatcher) unblockPeer(onion string) {
@ -505,7 +441,7 @@ func (this *GrandCentralDispatcher) unblockPeer(onion string) {
this.InvokePopup("Error Unblocking Peer: " + err.Error()) this.InvokePopup("Error Unblocking Peer: " + err.Error())
} }
the.Peer.PeerWithOnion(onion) the.Peer.PeerWithOnion(onion)
this.UIState.UpdateContact(onion) this.UpdateContactBlocked(onion, false)
} }
func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) { func (this *GrandCentralDispatcher) inviteToGroup(onion, groupID string) {
@ -528,54 +464,28 @@ func (this *GrandCentralDispatcher) deleteContact(onion string) {
func (this *GrandCentralDispatcher) acceptGroup(groupID string) { func (this *GrandCentralDispatcher) acceptGroup(groupID string) {
if the.Peer.GetGroup(groupID) != nil { if the.Peer.GetGroup(groupID) != nil {
the.Peer.AcceptInvite(groupID) the.Peer.AcceptInvite(groupID)
this.UIState.UpdateContact(groupID)
} }
} }
func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) { func (this *GrandCentralDispatcher) setAttribute(onion, key, value string) {
pp, _ := the.Peer.GetProfile().GetContact(onion) the.Peer.SetContactAttribute(onion, key, value)
if pp != nil { this.UIState.UpdateContactAttribute(onion, key, value)
pp.SetAttribute(key, value)
the.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)
}
} }
func (this *GrandCentralDispatcher) blockUnknownPeers() { func (this *GrandCentralDispatcher) blockUnknownPeers() {
the.Peer.SetAttribute(constants.BlockUnknownPeersSetting, "true")
// Save this setting
the.EventBus.Publish(event.NewEvent(event.SetAttribute, map[event.Field]string{
event.Key: constants.BlockUnknownPeersSetting,
event.Data: "true",
}))
the.Peer.GetProfile().SetAttribute(constants.BlockUnknownPeersSetting, "true")
the.EventBus.Publish(event.NewEvent(event.BlockUnknownPeers, map[event.Field]string{})) the.EventBus.Publish(event.NewEvent(event.BlockUnknownPeers, map[event.Field]string{}))
} }
func (this *GrandCentralDispatcher) allowUnknownPeers() { func (this *GrandCentralDispatcher) allowUnknownPeers() {
the.Peer.SetAttribute(constants.BlockUnknownPeersSetting, "false")
// Save this setting
the.EventBus.Publish(event.NewEvent(event.SetAttribute, map[event.Field]string{
event.Key: constants.BlockUnknownPeersSetting,
event.Data: "false",
}))
the.Peer.GetProfile().SetAttribute(constants.BlockUnknownPeersSetting, "false")
the.EventBus.Publish(event.NewEvent(event.AllowUnknownPeers, map[event.Field]string{})) the.EventBus.Publish(event.NewEvent(event.AllowUnknownPeers, map[event.Field]string{}))
} }
func (this *GrandCentralDispatcher) setLocale(locale string) { func (this *GrandCentralDispatcher) setLocale(locale string) {
this.SetLocale_helper(locale) this.SetLocale_helper(locale)
the.EventBus.Publish(event.NewEvent(event.SetAttribute, map[event.Field]string{ the.Peer.SetAttribute(constants.LocaleSetting, locale)
event.Key: constants.LocaleSetting,
event.Data: locale,
}))
zoom, _ := the.Peer.GetProfile().GetAttribute(constants.ZoomSetting) zoom, _ := the.Peer.GetProfile().GetAttribute(constants.ZoomSetting)
blockunkownpeers, _ := the.Peer.GetProfile().GetAttribute(constants.BlockUnknownPeersSetting) blockunkownpeers, _ := the.Peer.GetProfile().GetAttribute(constants.BlockUnknownPeersSetting)

View File

@ -2,41 +2,68 @@ package gothings
import ( import (
"cwtch.im/cwtch/model" "cwtch.im/cwtch/model"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/ui/go/constants" "cwtch.im/ui/go/constants"
"cwtch.im/ui/go/cwutil" "cwtch.im/ui/go/cwutil"
"cwtch.im/ui/go/gobjects" "cwtch.im/ui/go/gobjects"
"cwtch.im/ui/go/the" "cwtch.im/ui/go/the"
"git.openprivacy.ca/openprivacy/libricochet-go/log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"runtime/debug" "runtime/debug"
"sync"
"time" "time"
) )
type Attributable interface { func isGroup(id string) bool {
GetAttribute(string) (string, bool) return len(id) == 32
SetAttribute(string, string) }
func isPeer(id string) bool {
return len(id) == 56
}
func getWithSetDefault(id string, key, defaultVal string) string {
var val string
var ok bool
if isGroup(id) {
val, ok = the.Peer.GetGroupAttribute(id, key)
} else {
val, ok = the.Peer.GetContactAttribute(id, key)
}
if !ok {
val = defaultVal
if isGroup(id) {
the.Peer.SetGroupAttribute(id, key, defaultVal)
} else {
the.Peer.SetContactAttribute(id, key, defaultVal)
}
}
return val
} }
// initLastReadTime checks and gets the Attributable's LastRead time or sets it to now // initLastReadTime checks and gets the Attributable's LastRead time or sets it to now
func initLastReadTime(attr Attributable) time.Time { func initLastReadTime(id string) time.Time {
lastRead := time.Now() nowStr, _ := time.Now().MarshalText()
lastReadVal, ok := attr.GetAttribute(constants.LastRead) lastReadStr := getWithSetDefault(id, constants.LastRead, string(nowStr))
if ok { var lastRead time.Time
err := lastRead.UnmarshalText([]byte(lastReadVal)) lastRead.UnmarshalText([]byte(lastReadStr))
if err != nil {
lastRead = time.Now()
}
} else {
lastReadVal, _ := lastRead.MarshalText()
attr.SetAttribute(constants.LastRead, string(lastReadVal))
}
return lastRead return lastRead
} }
func updateLastReadTime(attr Attributable) { func initProfilePicture(id string) string {
lastRead := time.Now() log.Infof("initProfilePic: %v\n", id)
lastReadVal, _ := lastRead.MarshalText() if isGroup(id) {
attr.SetAttribute(constants.LastRead, string(lastReadVal)) return getWithSetDefault(id, constants.Picture, cwutil.RandomGroupImage(id))
} else {
return getWithSetDefault(id, constants.Picture, cwutil.RandomProfileImage(id))
}
}
func updateLastReadTime(id string) {
lastRead, _ := time.Now().MarshalText()
if isGroup(id) {
the.Peer.SetGroupAttribute(id, constants.LastRead, string(lastRead))
} else {
the.Peer.SetContactAttribute(id, constants.LastRead, string(lastRead))
}
} }
func countUnread(messages []model.Message, lastRead time.Time) int { func countUnread(messages []model.Message, lastRead time.Time) int {
@ -53,11 +80,10 @@ func countUnread(messages []model.Message, lastRead time.Time) int {
type InterfaceState struct { type InterfaceState struct {
parentGcd *GrandCentralDispatcher parentGcd *GrandCentralDispatcher
contacts sync.Map // string : *gobjects.Contact
} }
func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) { func NewUIState(gcd *GrandCentralDispatcher) (uis InterfaceState) {
uis = InterfaceState{gcd, sync.Map{}} uis = InterfaceState{gcd}
return return
} }
@ -65,96 +91,39 @@ func (this *InterfaceState) Acknowledge(mID string) {
this.parentGcd.Acknowledged(mID) this.parentGcd.Acknowledged(mID)
} }
func (this *InterfaceState) AddContact(c *gobjects.Contact) { func (this *InterfaceState) AddContact(Handle string) {
if len(c.Handle) == 32 { // ADD GROUP if isGroup(Handle) {
unread := 0 group := the.Peer.GetGroup(Handle)
group := the.Peer.GetGroup(c.Handle)
if group != nil { if group != nil {
lastRead := initLastReadTime(group) lastRead := initLastReadTime(group.GroupID)
unread = countUnread(group.Timeline.GetMessages(), lastRead) unread := countUnread(group.Timeline.GetMessages(), lastRead)
} picture := initProfilePicture(Handle)
if _, found := this.contacts.Load(c.Handle); !found { nick, exists := group.GetAttribute(constants.Nick)
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, unread, c.Status, c.Trusted, c.Blocked, c.Loading) if !exists {
this.contacts.Store(c.Handle, c) nick = Handle
}
this.parentGcd.AddContact(Handle, nick, picture, group.GroupServer, unread, int(connections.ConnectionStateToType[group.State]), false, false)
} }
return return
} else if len(c.Handle) != 56 { } else if !isPeer(Handle) {
log.Errorf("sorry, unable to handle AddContact(%v)", c.Handle) log.Errorf("sorry, unable to handle AddContact(%v)", Handle)
debug.PrintStack() debug.PrintStack()
return return
} }
unread := 0 contact := the.Peer.GetContact(Handle)
contact := the.Peer.GetContact(c.Handle)
if contact != nil { if contact != nil {
lastRead := initLastReadTime(contact) lastRead := initLastReadTime(contact.Onion)
unread = countUnread(contact.Timeline.GetMessages(), lastRead) unread := countUnread(contact.Timeline.GetMessages(), lastRead)
} picture := initProfilePicture(Handle)
if _, found := this.contacts.Load(c.Handle); !found { nick, exists := contact.GetAttribute(constants.Nick)
this.contacts.Store(c.Handle, c) if !exists {
this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, unread, c.Status, c.Trusted, c.Blocked, false) nick = Handle
if the.Peer.GetContact(c.Handle) == nil {
the.Peer.AddContact(c.DisplayName, c.Handle, c.Trusted)
go the.Peer.PeerWithOnion(c.Handle)
} }
}
}
func (this *InterfaceState) DeleteContact(id string) { this.parentGcd.AddContact(Handle, nick, picture, "", unread, int(connections.ConnectionStateToType[contact.State]), contact.Blocked, false)
this.contacts.Delete(id)
}
func (this *InterfaceState) GetContact(handle string) *gobjects.Contact {
if _, found := this.contacts.Load(handle); !found {
if len(handle) == 32 {
group := the.Peer.GetGroup(handle)
if group != nil {
nick, exists := group.GetAttribute(constants.Nick)
if !exists {
nick = group.GroupID[:12]
}
this.AddContact(&gobjects.Contact{
handle,
nick,
cwutil.RandomGroupImage(handle),
group.GroupServer,
0,
group.Accepted,
false,
false,
})
} else {
log.Errorf("Attempting to add non existent group to ui %v", handle)
}
} else {
contact := the.Peer.GetContact(handle)
if contact != nil && handle != contact.Onion {
nick, exists := contact.GetAttribute("name")
if !exists {
nick = contact.Onion
}
this.AddContact(&gobjects.Contact{
handle,
nick,
cwutil.RandomProfileImage(handle),
"",
0,
false,
contact.Blocked,
false,
})
} else if contact == nil {
//log.Errorf("Attempting to add non existent contact to ui %v", handle)
}
}
} }
contactIntf, _ := this.contacts.Load(handle)
if contactIntf == nil {
return nil
}
contact := contactIntf.(*gobjects.Contact)
return contact
} }
func (this *InterfaceState) AddSendMessageError(peer string, signature string, err string) { func (this *InterfaceState) AddSendMessageError(peer string, signature string, err string) {
@ -165,11 +134,7 @@ func (this *InterfaceState) AddSendMessageError(peer string, signature string, e
} }
func (this *InterfaceState) AddMessage(m *gobjects.Message) { func (this *InterfaceState) AddMessage(m *gobjects.Message) {
if len(m.Handle) == 32 { // GROUP updateLastReadTime(m.Handle)
updateLastReadTime(the.Peer.GetGroup(m.Handle))
} else {
updateLastReadTime(the.Peer.GetContact(m.Handle))
}
// If we have this group loaded already // If we have this group loaded already
if this.parentGcd.CurrentOpenConversation() == m.Handle { if this.parentGcd.CurrentOpenConversation() == m.Handle {
@ -184,17 +149,12 @@ func (this *InterfaceState) AddMessage(m *gobjects.Message) {
} }
} }
func (this *InterfaceState) UpdateContact(handle string) { func (this *InterfaceState) UpdateContactDisplayName(handle string, name string) {
contact := the.Peer.GetContact(handle) this.parentGcd.UpdateContactDisplayName(handle, name)
cif, found := this.contacts.Load(handle) }
if found {
c := cif.(*gobjects.Contact)
if contact != nil {
c.Blocked = contact.Blocked
}
this.parentGcd.UpdateContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Status, c.Trusted, c.Blocked, c.Loading)
} func (this *InterfaceState) UpdateContactStatus(handle string, status int, loading bool) {
this.parentGcd.UpdateContactStatus(handle, status, loading)
} }
func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) { func (this *InterfaceState) UpdateContactAttribute(handle, key, value string) {

View File

@ -87,12 +87,12 @@ ColumnLayout {
}) })
} }
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
} }*/
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _status, _trusted, _blocked, _loading) { onUpdateContactStatus: function(_handle, _status, _loading) {
if (gcd.currentOpenConversation == _handle) { if (gcd.currentOpenConversation == _handle) {
if (_loading == true) { if (_loading == true) {
newposttitle.enabled = false newposttitle.enabled = false

View File

@ -110,10 +110,10 @@ ColumnLayout {
messagesListView.positionViewAtEnd() messagesListView.positionViewAtEnd()
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _status, _trusted, _blocked, _loading) { onUpdateContactStatus: function(_handle, _status, _loading) {
if (gcd.currentOpenConversation == _handle) { if (gcd.currentOpenConversation == _handle) {
// Group is Synced OR p2p is Authenticated // Group is Synced OR p2p is Authenticated
if ( (_handle.length == 32 && _status == 4) || _status == 3) { if ( (_handle.length == 32 && _status == 4) || (_handle.length == 56 && _status == 3) ) {
txtMessage.enabled = true txtMessage.enabled = true
btnSend.enabled = true btnSend.enabled = true
} else { } else {

View File

@ -87,16 +87,16 @@ ColumnLayout {
}) })
} }
if(msg.c != undefined) { /*if(msg.c != undefined) {
jsonModel4.get(msg.c).complete = true jsonModel4.get(msg.c).complete = true
} }
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
} }*/
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _status, _trusted, _blocked, _loading) { onUpdateContactStatus: function(_handle, _status, _loading) {
if (gcd.currentOpenConversation == _handle) { if (gcd.currentOpenConversation == _handle) {
if (_loading == true) { if (_loading == true) {
newposttitle.enabled = false newposttitle.enabled = false

View File

@ -105,7 +105,6 @@ ColumnLayout {
handle: _handle handle: _handle
displayName: _displayName displayName: _displayName
image: _image image: _image
trusted: true
blocked: false blocked: false
background: false background: false
} }

View File

@ -47,7 +47,7 @@ ColumnLayout {
Connections { // ADD/REMOVE CONTACT ENTRIES Connections { // ADD/REMOVE CONTACT ENTRIES
target: gcd target: gcd
onAddContact: function(handle, displayName, image, server, badge, status, trusted, blocked, loading) { onAddContact: function(handle, displayName, image, server, badge, status, blocked, loading) {
contactsModel.append({ contactsModel.append({
"_handle": handle, "_handle": handle,
"_displayName": displayName + (blocked ? " (blocked)" : "" ), "_displayName": displayName + (blocked ? " (blocked)" : "" ),
@ -55,7 +55,6 @@ ColumnLayout {
"_server": server, "_server": server,
"_badge": badge, "_badge": badge,
"_status": status, "_status": status,
"_trusted": trusted,
"_blocked": blocked, "_blocked": blocked,
"_loading": loading, "_loading": loading,
"_loading": loading "_loading": loading
@ -86,7 +85,6 @@ ColumnLayout {
server: _server server: _server
badge: _badge badge: _badge
status: _status status: _status
trusted: _trusted
blocked: _blocked blocked: _blocked
loading: _loading loading: _loading
} }

View File

@ -68,7 +68,7 @@ Item {
anchors.margins: 4 * logscale anchors.margins: 4 * logscale
Rectangle { //-2:WtfCodeError,-1:Untrusted,0:Disconnected,1:Connecting,2:Connected,3:Authenticated,4:Synced,5:Failed,6:Killed Rectangle { //-2:WtfCodeError,-1:Error,0:Disconnected,1:Connecting,2:Connected,3:Authenticated,4:Synced,5:Failed,6:Killed
color: status == 4 ? "green" : status == 3 ? "green" : status == -1 ? "blue" : status == 1 ? "orange" : status == 2 ? "orange" : "red" color: status == 4 ? "green" : status == 3 ? "green" : status == -1 ? "blue" : status == 1 ? "orange" : status == 2 ? "orange" : "red"
width: 5 * logscale width: 5 * logscale
height: 5 * logscale height: 5 * logscale

View File

@ -22,7 +22,6 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
property int badge property int badge
property bool isActive property bool isActive
property bool isHover property bool isHover
property bool trusted
property bool blocked property bool blocked
property bool loading property bool loading
property alias status: imgProfile.status property alias status: imgProfile.status
@ -52,7 +51,6 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.right: loading ? loadingProgress.left : rectUnread.left anchors.right: loading ? loadingProgress.left : rectUnread.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 16 * gcd.themeScale font.pixelSize: 16 * gcd.themeScale
font.italic: !trusted
font.strikeout: blocked font.strikeout: blocked
textFormat: Text.PlainText textFormat: Text.PlainText
//fontSizeMode: Text.HorizontalFit //fontSizeMode: Text.HorizontalFit
@ -146,17 +144,24 @@ Item { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
isActive = false isActive = false
} }
onUpdateContact: function(_handle, _displayName, _image, _server, _status, _trusted, _blocked, _loading) { onUpdateContactStatus: function(_handle, _status, _loading) {
if (handle == _handle) { if (handle == _handle) {
displayName = _displayName + (_blocked == true ? " (blocked)" : "") status = _status
image = _image
server = _server
status = _status
trusted = _trusted
blocked = _blocked
loadingProgress.visible = loadingProgress.running = loading = _loading loadingProgress.visible = loadingProgress.running = loading = _loading
} }
} }
onUpdateContactBlocked: function(_handle, _blocked) {
if (handle == _handle) {
blocked = _blocked
}
}
onUpdateContactDisplayName: function(_handle, _displayName) {
if (handle == _handle) {
displayName = _displayName + (_blocked == true ? " (blocked)" : "")
}
}
onIncContactUnreadCount: function(handle) { onIncContactUnreadCount: function(handle) {
if (handle == _handle) { if (handle == _handle) {