diff --git a/event/common.go b/event/common.go index ca9984c..490f035 100644 --- a/event/common.go +++ b/event/common.go @@ -329,7 +329,8 @@ const ( // Define Default Attribute Keys const ( - SaveHistoryKey = "SavePeerHistory" + SaveHistoryDefaultKey = "SaveHistoryDefault" // profile level default + SaveHistoryKey = "SavePeerHistory" ) // Define Default Attribute Values @@ -340,6 +341,7 @@ const ( DeleteHistoryDefault = "DefaultDeleteHistory" SaveHistoryConfirmed = "SaveHistory" DeleteHistoryConfirmed = "DeleteHistoryConfirmed" + SaveHistoryDefault = "DefaultSaveHistory" ) // Bool strings diff --git a/functionality/servers/servers_functionality.go b/functionality/servers/servers_functionality.go index ccafc8e..9b31593 100644 --- a/functionality/servers/servers_functionality.go +++ b/functionality/servers/servers_functionality.go @@ -101,6 +101,21 @@ func (f *Functionality) GetServerInfoList(profile peer.CwtchPeer) []Server { return servers } +// DeleteServer purges a server and all related keys from a profile +func (f *Functionality) DeleteServer(profile peer.CwtchPeer, serverOnion string) error { + // Servers are stores as special conversations + ci, err := profile.FetchConversationInfo(serverOnion) + if err != nil { + return err + } + // Purge keys... + // NOTE: This will leave some groups in the state of being unable to connect to a particular + // server. + profile.DeleteConversation(ci.ID) + f.PublishServerUpdate(profile) + return nil +} + // GetServerInfo compiles all the information the UI might need regarding a particular server including any verified // cryptographic keys func (f *Functionality) GetServerInfo(profile peer.CwtchPeer, serverOnion string) Server { diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 46c7e3d..c47e223 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -981,8 +981,8 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) (string, error) { // we haven't seen this key associated with the server before } - // // If we have gotten to this point we can assume this is a safe key bundle signed by the - // // server with no conflicting keys. So we are going to save all the keys + // If we have gotten to this point we can assume this is a safe key bundle signed by the + // server with no conflicting keys. So we are going to save all the keys for k, v := range ab { cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v) } diff --git a/peer/cwtchprofilestorage.go b/peer/cwtchprofilestorage.go index 7bf8e7b..784f1fe 100644 --- a/peer/cwtchprofilestorage.go +++ b/peer/cwtchprofilestorage.go @@ -835,12 +835,26 @@ func (cps *CwtchProfileStorage) PurgeConversationChannel(conversation int, chann // PurgeNonSavedMessages deletes all message conversations that are not explicitly set to saved. func (cps *CwtchProfileStorage) PurgeNonSavedMessages() { + + defaultSave := false + key, err := cps.LoadProfileKeyValue(TypeAttribute, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(event.SaveHistoryDefaultKey)).ToString()) + if err == nil { + if string(key) == event.SaveHistoryDefault { + defaultSave = true + } + } + // Purge Messages that are not stored... ci, err := cps.FetchConversations() if err == nil { for _, conversation := range ci { if !conversation.IsGroup() && !conversation.IsServer() { - if conversation.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(event.SaveHistoryKey)).ToString()] != event.SaveHistoryConfirmed { + saveHistoryConfirmed := conversation.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(event.SaveHistoryKey)).ToString()] == event.SaveHistoryConfirmed + deleteHistoryConfirmed := conversation.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(event.SaveHistoryKey)).ToString()] == event.DeleteHistoryConfirmed + // we purge conversation history in two specific instances... + // if the conversation has been explicitly marked as default history confirmed OR + // if save history hasn't been confirmed and default save history is false - i.e. in all other cases + if deleteHistoryConfirmed || (!saveHistoryConfirmed && !defaultSave) { log.Debugf("purging conversation...") // TODO: At some point in the future this needs to iterate over channels and make a decision for each on.. cps.PurgeConversationChannel(conversation.ID, 0) diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index 533a81a..1e4b81c 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -464,6 +464,10 @@ func (e *engine) peerWithTokenServer(onion string, tokenServerOnion string, toke e.ignoreOnShutdown(e.serverAuthed)(onion) return } + + // if we are not authed or synced then we are stuck... + e.ignoreOnShutdown(e.serverConnecting)(onion) + log.Errorf("server connection attempt issued to active connection") } }