From f6b3890f20ddfbb9f684a06922934668cdc792d1 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 15 Oct 2023 12:59:42 -0700 Subject: [PATCH] Fix incorrect comparisons for checking if a timestamp is zero-valued --- backend/server/internal/database/db.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/server/internal/database/db.go b/backend/server/internal/database/db.go index 46b7741..0358e06 100644 --- a/backend/server/internal/database/db.go +++ b/backend/server/internal/database/db.go @@ -206,15 +206,15 @@ func (db *DB) DeleteMessagesFromBackend(ctx context.Context, userId string, dele if message.DeviceId == "" { return 0, fmt.Errorf("failed to delete entry because MessageIdentifier.DeviceId is empty") } - if message.EndTime.UTC().UnixMilli() > 0 && message.EntryId != "" { + 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)) - } else if message.EndTime.UTC().UnixMilli() > 0 && 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)) - } else if message.EndTime.UTC().UnixMilli() == 0 && message.EntryId != "" { + } 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)) } else { - return 0, fmt.Errorf("failed to delete entry because message.EndTime and message.EntryId are both empty") + return 0, fmt.Errorf("failed to delete entry because message.EndTime=%#v and message.EntryId=%#v are both empty", message.EndTime, message.EntryId) } } result := tx.Delete(&shared.EncHistoryEntry{})