From 25d035267af14e05d3fa2531e8300eee46c7f6ae Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sat, 20 Nov 2021 10:10:14 -0800 Subject: [PATCH] minor support to manage profile servers --- constants/attributes.go | 3 +++ features/groups/group_functionality.go | 7 ++++++- features/groups/server.go | 1 + features/servers/servers_functionality.go | 4 ++++ lib.go | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/constants/attributes.go b/constants/attributes.go index 79f6801..78031c4 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -14,6 +14,9 @@ const ProfileTypeV1Password = "v1-userPassword" // PeerOnline stores state on if the peer believes it is online const PeerOnline = "peer-online" +// Description is used on server contacts, +const Description = "description" + const StateProfilePane = "state-profile-pane" const StateSelectedConversation = "state-selected-conversation" const StateSelectedProfileTime = "state-selected-profile-time" diff --git a/features/groups/group_functionality.go b/features/groups/group_functionality.go index d74019a..edea7a5 100644 --- a/features/groups/group_functionality.go +++ b/features/groups/group_functionality.go @@ -7,6 +7,8 @@ import ( "cwtch.im/cwtch/peer" "cwtch.im/cwtch/protocol/connections" "fmt" + "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" ) const groupExperiment = "tapir-groups-experiment" @@ -54,5 +56,8 @@ func (gf *GroupFunctionality) GetServerInfo(serverOnion string, profile peer.Cwt serverKeys = append(serverKeys, ServerKey{Type: string(keyType), Key: key}) } } - return Server{Onion: serverOnion, Status: connections.ConnectionStateName[profile.GetPeerState(serverInfo.Handle)], Keys: serverKeys} + + descPath := attr.LocalScope.ConstructScopedZonedPath(servers.ServerZone.ConstructZonedPath(constants.Description)) + description, _ := serverInfo.GetAttribute(descPath.ToString()) + return Server{Onion: serverOnion, Status: connections.ConnectionStateName[profile.GetPeerState(serverInfo.Handle)], Keys: serverKeys, Description: description} } diff --git a/features/groups/server.go b/features/groups/server.go index 8ac07f7..700f038 100644 --- a/features/groups/server.go +++ b/features/groups/server.go @@ -8,5 +8,6 @@ type ServerKey struct { type Server struct { Onion string `json:"onion"` Status string `json:"status"` + Description string `json:"description"` Keys []ServerKey `json:"keys"` } diff --git a/features/servers/servers_functionality.go b/features/servers/servers_functionality.go index c8147c4..a18a1d4 100644 --- a/features/servers/servers_functionality.go +++ b/features/servers/servers_functionality.go @@ -2,6 +2,7 @@ package servers import ( "cwtch.im/cwtch/event" + "cwtch.im/cwtch/model/attr" "fmt" "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" "git.openprivacy.ca/cwtch.im/server" @@ -30,6 +31,9 @@ const ( IntentStopped = "stopped" ) +// TODO: move into Cwtch model/attr +const ServerZone = attr.Zone("server") + type ServerInfo struct { Onion string ServerBundle string diff --git a/lib.go b/lib.go index b6a51f0..71fd9b1 100644 --- a/lib.go +++ b/lib.go @@ -323,6 +323,7 @@ func SendAppEvent(eventJson string) { settings := utils.ReadGlobalSettings() + // TODO: Should track state an only launch servers if server experiment re-enabled, not every save of settings _, err = servers.ExperimentGate(settings.Experiments) if err == nil { servers.InitServers(globalACN, globalAppDir)