From f60fbfc3d539dc36d21f40ecd8d25d890a04eb7a Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 13 Sep 2023 11:50:13 -0700 Subject: [PATCH] Upgrade Cwtch. Support Disconnection and Appearing Offline --- constants/attributes.go | 1 + go.mod | 2 +- go.sum | 4 ++-- spec | 4 ++++ templates/lib_template.go | 2 ++ utils/eventHandler.go | 15 ++++++++++++++- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/constants/attributes.go b/constants/attributes.go index 5ddb9d5..c23ec0c 100644 --- a/constants/attributes.go +++ b/constants/attributes.go @@ -12,6 +12,7 @@ const LastSeenTime = "lastMessageSeenTime" const PeerOnline = "peer-online" const PeerAutostart = "autostart" +const PeerAppearOffline = "appear-offline" // ConversationNotificationPolicy is the attribute label for conversations. When App NotificationPolicy is OptIn a true value here opts in const ConversationNotificationPolicy = "notification-policy" diff --git a/go.mod b/go.mod index 1d46f61..f807fea 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/cwtch-autobindings go 1.19 require ( - cwtch.im/cwtch v0.23.1 + cwtch.im/cwtch v0.24.0 git.openprivacy.ca/cwtch.im/server v1.4.5 git.openprivacy.ca/openprivacy/connectivity v1.11.0 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index 85d39af..f46ac97 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y= -cwtch.im/cwtch v0.23.1 h1:IXNRbIktbC+WjCkzMpDW9YrmgPZhtuPkCF10jZLl01Q= -cwtch.im/cwtch v0.23.1/go.mod h1:o8uZBYjDS1DEHftxdYl91iMQZ2WDxlajM7Pa0ScfviI= +cwtch.im/cwtch v0.24.0 h1:Obljm7Dq8+a3T4K9DvLtbo0uI1/r+M1IuaJIrnHuJ/s= +cwtch.im/cwtch v0.24.0/go.mod h1:o8uZBYjDS1DEHftxdYl91iMQZ2WDxlajM7Pa0ScfviI= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/spec b/spec index 8aad7ee..de60d04 100644 --- a/spec +++ b/spec @@ -3,6 +3,7 @@ # Peer Engine app ActivatePeerEngine profile app DeactivatePeerEngine profile +app ConfigureConnections profile bool:listen bool:peers bool:servers # Profile Management app CreateProfile name password bool:autostart @@ -20,6 +21,7 @@ profile BlockConversation conversation profile UnblockConversation conversation profile DeleteConversation conversation profile PeerWithOnion string:handle +profile DisconnectFromPeer string:handle # Search (json)profile SearchConversations string:pattern @@ -34,6 +36,8 @@ profile UpdateMessageAttribute conversation channel message string:attributeKey # Group Management profile StartGroup string:name string:server +profile QueueJoinServer string:handle +profile DisconnectFromServer string:handle ## Server List Management... import "cwtch.im/cwtch/functionality/servers" diff --git a/templates/lib_template.go b/templates/lib_template.go index 9a6188f..d01e537 100644 --- a/templates/lib_template.go +++ b/templates/lib_template.go @@ -314,6 +314,8 @@ func SetProfileAttribute(profileOnion string, key string, value string) { profile.SetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.ProfileStatus, value) } else if zone == attr.ProfileZone && key == constants.PeerAutostart { profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.PeerAutostart, value) + } else if zone == attr.ProfileZone && key == constants.PeerAppearOffline { + profile.SetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.PeerAppearOffline, value) } else { log.Errorf("attempted to set an attribute with an unknown zone: %v", key) } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 041c252..e3985b6 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -145,9 +145,15 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { // Start up the Profile if acnStatus == 100 { - autostart, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerAutostart) + autostart, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.PeerAutostart) + appearOffline, appearOfflineExists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants.PeerAppearOffline) if !exists || autostart == "true" { eh.app.ActivatePeerEngine(onion) + if appearOfflineExists && appearOffline == "true" { + // don't configure any connections... + } else { + eh.app.ConfigureConnections(onion, true, true, true) + } } } @@ -161,6 +167,13 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { } e.Data["autostart"] = autostart + appearOffline, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.ProfileZone, constants2.PeerAppearOffline) + // legacy profiles should not appearOffline by default + if !exists { + appearOffline = "false" + } + e.Data["appearOffline"] = appearOffline + // Name always exists e.Data[constants.Name], _ = profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.Name) e.Data[constants2.DefaultProfilePicture] = RandomProfileImage(onion)