(ctx context.Context, userId, deviceId string)
| 214 | } |
| 215 | |
| 216 | func (db *DB) UninstallDevice(ctx context.Context, userId, deviceId string) (int64, error) { |
| 217 | // Note that this is deleting entries that are destined to be *read* by this device. If there are other devices on this account, |
| 218 | // those queues are unaffected. |
| 219 | r1 := db.WithContext(ctx).Where("user_id = ? AND device_id = ?", userId, deviceId).Delete(&shared.EncHistoryEntry{}) |
| 220 | if r1.Error != nil { |
| 221 | return 0, fmt.Errorf("UninstallDevice: failed to delete entries: %w", r1.Error) |
| 222 | } |
| 223 | // Note that this is deleting deletion requests that were destined to be processed by this device. So if this device deleted anything, |
| 224 | // those requests are still pending. |
| 225 | r2 := db.WithContext(ctx).Where("user_id = ? AND destination_device_id = ?", userId, deviceId).Delete(&shared.DeletionRequest{}) |
| 226 | if r2.Error != nil { |
| 227 | return 0, fmt.Errorf("UninstallDevice: failed to delete deletion requests: %w", r2.Error) |
| 228 | } |
| 229 | // Similarly, note that this is deleting dump requests from this device so that other devices won't respond to these. |
| 230 | r3 := db.WithContext(ctx).Where("user_id = ? AND requesting_device_id = ?", userId, deviceId).Delete(&shared.DumpRequest{}) |
| 231 | if r3.Error != nil { |
| 232 | return 0, fmt.Errorf("UninstallDevice: failed to delete dump requests: %w", r3.Error) |
| 233 | } |
| 234 | // Lastly, update the flag so that we know this device has been deleted |
| 235 | r := db.WithContext(ctx).Model(&Device{}).Where("user_id = ? AND device_id = ?", userId, deviceId).Update("uninstall_date", time.Now().UTC()) |
| 236 | if r.Error != nil { |
| 237 | return 0, fmt.Errorf("UnisntallDevice: failed to update uninstall_date: %w", r.Error) |
| 238 | } |
| 239 | return r1.RowsAffected + r2.RowsAffected + r3.RowsAffected, nil |
| 240 | } |
| 241 | |
| 242 | func (db *DB) DeleteMessagesFromBackend(ctx context.Context, userId string, deletedMessages []shared.MessageIdentifier) (int64, error) { |
| 243 | if len(deletedMessages) == 0 { |
no test coverage detected