Support Save History Default + Delete Server
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
4db041f850
commit
066ed86598
|
@ -329,6 +329,7 @@ const (
|
||||||
|
|
||||||
// Define Default Attribute Keys
|
// Define Default Attribute Keys
|
||||||
const (
|
const (
|
||||||
|
SaveHistoryDefaultKey = "SaveHistoryDefault" // profile level default
|
||||||
SaveHistoryKey = "SavePeerHistory"
|
SaveHistoryKey = "SavePeerHistory"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -340,6 +341,7 @@ const (
|
||||||
DeleteHistoryDefault = "DefaultDeleteHistory"
|
DeleteHistoryDefault = "DefaultDeleteHistory"
|
||||||
SaveHistoryConfirmed = "SaveHistory"
|
SaveHistoryConfirmed = "SaveHistory"
|
||||||
DeleteHistoryConfirmed = "DeleteHistoryConfirmed"
|
DeleteHistoryConfirmed = "DeleteHistoryConfirmed"
|
||||||
|
SaveHistoryDefault = "DefaultSaveHistory"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bool strings
|
// Bool strings
|
||||||
|
|
|
@ -101,6 +101,21 @@ func (f *Functionality) GetServerInfoList(profile peer.CwtchPeer) []Server {
|
||||||
return servers
|
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
|
// GetServerInfo compiles all the information the UI might need regarding a particular server including any verified
|
||||||
// cryptographic keys
|
// cryptographic keys
|
||||||
func (f *Functionality) GetServerInfo(profile peer.CwtchPeer, serverOnion string) Server {
|
func (f *Functionality) GetServerInfo(profile peer.CwtchPeer, serverOnion string) Server {
|
||||||
|
|
|
@ -981,8 +981,8 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) (string, error) {
|
||||||
// we haven't seen this key associated with the server before
|
// 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
|
// 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
|
// server with no conflicting keys. So we are going to save all the keys
|
||||||
for k, v := range ab {
|
for k, v := range ab {
|
||||||
cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v)
|
cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -835,12 +835,26 @@ func (cps *CwtchProfileStorage) PurgeConversationChannel(conversation int, chann
|
||||||
|
|
||||||
// PurgeNonSavedMessages deletes all message conversations that are not explicitly set to saved.
|
// PurgeNonSavedMessages deletes all message conversations that are not explicitly set to saved.
|
||||||
func (cps *CwtchProfileStorage) PurgeNonSavedMessages() {
|
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...
|
// Purge Messages that are not stored...
|
||||||
ci, err := cps.FetchConversations()
|
ci, err := cps.FetchConversations()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, conversation := range ci {
|
for _, conversation := range ci {
|
||||||
if !conversation.IsGroup() && !conversation.IsServer() {
|
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...")
|
log.Debugf("purging conversation...")
|
||||||
// TODO: At some point in the future this needs to iterate over channels and make a decision for each on..
|
// 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)
|
cps.PurgeConversationChannel(conversation.ID, 0)
|
||||||
|
|
|
@ -464,6 +464,10 @@ func (e *engine) peerWithTokenServer(onion string, tokenServerOnion string, toke
|
||||||
e.ignoreOnShutdown(e.serverAuthed)(onion)
|
e.ignoreOnShutdown(e.serverAuthed)(onion)
|
||||||
return
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue