fix: return CustomizationColor only on db rows affected (#4593)

This commit is contained in:
frank 2024-01-19 18:26:39 +08:00 committed by GitHub
parent 926f6a3c72
commit 81f4c86086
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -344,9 +344,8 @@ func (db *Database) UpdateAccountTimestamp(keyUID string, loginTimestamp int64)
return err
}
func (db *Database) UpdateAccountCustomizationColor(keyUID string, color string, clock uint64) error {
_, err := db.db.Exec("UPDATE accounts SET customizationColor = ?, customizationColorClock = ? WHERE keyUid = ? AND customizationColorClock < ?", color, clock, keyUID, clock)
return err
func (db *Database) UpdateAccountCustomizationColor(keyUID string, color string, clock uint64) (sql.Result, error) {
return db.db.Exec("UPDATE accounts SET customizationColor = ?, customizationColorClock = ? WHERE keyUid = ? AND customizationColorClock < ?", color, clock, keyUID, clock)
}
func (db *Database) DeleteAccount(keyUID string) error {

View File

@ -2415,12 +2415,18 @@ func (m *Messenger) HandleSyncSetting(messageState *ReceivedMessageState, messag
}
func (m *Messenger) HandleSyncAccountCustomizationColor(state *ReceivedMessageState, message *protobuf.SyncAccountCustomizationColor, statusMessage *v1protocol.StatusMessage) error {
err := m.multiAccounts.UpdateAccountCustomizationColor(message.GetKeyUid(), message.GetCustomizationColor(), message.GetUpdatedAt())
result, err := m.multiAccounts.UpdateAccountCustomizationColor(message.GetKeyUid(), message.GetCustomizationColor(), message.GetUpdatedAt())
if err != nil {
return err
}
state.Response.CustomizationColor = message.GetCustomizationColor()
affected, err := result.RowsAffected()
if err != nil {
return err
}
if affected > 0 {
state.Response.CustomizationColor = message.GetCustomizationColor()
}
return nil
}