Upgrade Cwtch. Support Disconnection and Appearing Offline

This commit is contained in:
Sarah Jamie Lewis 2023-09-13 11:50:13 -07:00
parent f32ad741e0
commit f60fbfc3d5
6 changed files with 24 additions and 4 deletions

View File

@ -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"

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

4
spec
View File

@ -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"

View File

@ -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)
}

View File

@ -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)