Purge on Startup + Fix SetSZA eventbus safety
This commit is contained in:
parent
af8322b734
commit
5a3d393472
|
@ -159,8 +159,9 @@ func (cp *cwtchPeer) SetScopedZonedAttribute(scope attr.Scope, zone attr.Zone, k
|
|||
|
||||
// We always want to publish profile level attributes to the ui
|
||||
// This should be low traffic.
|
||||
cp.eventBus.Publish(event.NewEvent(event.UpdatedProfileAttribute, map[event.Field]string{event.Key: scopedZonedKey.ToString(), event.Data: value}))
|
||||
|
||||
if cp.eventBus != nil {
|
||||
cp.eventBus.Publish(event.NewEvent(event.UpdatedProfileAttribute, map[event.Field]string{event.Key: scopedZonedKey.ToString(), event.Data: value}))
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessage is a higher level that merges sending messages to contacts and group handles
|
||||
|
@ -266,6 +267,9 @@ func FromEncryptedStorage(cps *CwtchProfileStorage) CwtchPeer {
|
|||
cp.state = make(map[string]connections.ConnectionState)
|
||||
// At some point we may want to populate caches here, for now we will assume hitting the
|
||||
// database directly is tolerable
|
||||
// Clean up anything that wasn't cleaned up on shutdown
|
||||
// TODO ideally this shouldn't need to be done but the UI sometimes doesn't shut down cleanly
|
||||
cp.storage.PurgeNonSavedMessages()
|
||||
return cp
|
||||
}
|
||||
|
||||
|
|
|
@ -538,7 +538,7 @@ func (cps *CwtchProfileStorage) GetChannelMessageByContentHash(conversation int,
|
|||
rows.Close()
|
||||
|
||||
// Return the offset **not** the count
|
||||
return id-1, nil
|
||||
return id - 1, nil
|
||||
}
|
||||
|
||||
// GetRowNumberByMessageID looks up the row number of a message by the message ID
|
||||
|
@ -693,23 +693,28 @@ func (cps *CwtchProfileStorage) PurgeConversationChannel(conversation int, chann
|
|||
return conversationStmt.Close()
|
||||
}
|
||||
|
||||
// PurgeNonSavedMessages deletes all message conversations that are not explicitly set to saved.
|
||||
func (cps *CwtchProfileStorage) PurgeNonSavedMessages() {
|
||||
// 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 {
|
||||
log.Infof("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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the underlying database and prepared statements
|
||||
func (cps *CwtchProfileStorage) Close() {
|
||||
if cps.db != nil {
|
||||
|
||||
// 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 {
|
||||
log.Infof("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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cps.PurgeNonSavedMessages()
|
||||
|
||||
cps.insertProfileKeyValueStmt.Close()
|
||||
cps.selectProfileKeyValueStmt.Close()
|
||||
|
|
Loading…
Reference in New Issue