Change deletion request code to not filter on DeviceId since the two device ID fields are not actually the same (see the newly added comment)

This commit is contained in:
David Dworken 2023-11-19 08:51:22 -08:00
parent b4f5f50ef7
commit 0c2774ec15
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View File

@ -209,11 +209,11 @@ func (db *DB) DeleteMessagesFromBackend(ctx context.Context, userId string, dele
}
if message.EndTime != (time.Time{}) && message.EntryId != "" {
// Note that we do an OR with date or the ID matching since the ID is not always recorded for older history entries.
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND device_id = ? AND (date = ? OR encrypted_id = ?)", userId, message.DeviceId, message.EndTime, message.EntryId))
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND (date = ? OR encrypted_id = ?)", userId, message.EndTime, message.EntryId))
} else if message.EndTime != (time.Time{}) && message.EntryId == "" {
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND device_id = ? AND (date = ?)", userId, message.DeviceId, message.EndTime))
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND (date = ?)", userId, message.EndTime))
} else if message.EndTime == (time.Time{}) && message.EntryId != "" {
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND device_id = ? AND (encrypted_id = ?)", userId, message.DeviceId, message.EntryId))
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND (encrypted_id = ?)", userId, message.EntryId))
} else {
return 0, fmt.Errorf("failed to delete entry because message.EndTime=%#v and message.EntryId=%#v are both empty", message.EndTime, message.EntryId)
}

View File

@ -11,8 +11,9 @@ import (
type EncHistoryEntry struct {
EncryptedData []byte `json:"enc_data"`
Nonce []byte `json:"nonce"`
DeviceId string `json:"device_id"`
UserId string `json:"user_id"`
// DeviceId is the ID of the device that will read this entry from the backend. It is *not* the ID of the device that recorded the command.
DeviceId string `json:"device_id"`
UserId string `json:"user_id"`
// Note that EncHistoryEntry.Date == HistoryEntry.EndTime
Date time.Time `json:"time"`
// Note that EncHistoryEntry.EncryptedId == HistoryEntry.Id (for entries created after pre-saving support)