+ public int removeStorageIdsFromLocalOnlyUnregisteredRecipients(
+ final Connection connection, final List<StorageId> storageIds
+ ) throws SQLException {
+ final var sql = (
+ """
+ UPDATE %s
+ SET storage_id = NULL
+ WHERE storage_id = ? AND storage_id IS NOT NULL AND unregistered_timestamp IS NOT NULL
+ """
+ ).formatted(TABLE_RECIPIENT);
+ var count = 0;
+ try (final var statement = connection.prepareStatement(sql)) {
+ for (final var storageId : storageIds) {
+ statement.setBytes(1, storageId.getRaw());
+ count += statement.executeUpdate();
+ }
+ }
+ return count;
+ }
+
+ public void markUnregistered(final Set<String> unregisteredUsers) {
+ logger.debug("Marking {} numbers as unregistered", unregisteredUsers.size());
+ try (final var connection = database.getConnection()) {
+ connection.setAutoCommit(false);
+ for (final var number : unregisteredUsers) {
+ final var recipient = findByNumber(connection, number);
+ if (recipient.isPresent()) {
+ markUnregistered(connection, recipient.get().id());
+ }
+ }
+ connection.commit();
+ } catch (SQLException e) {
+ throw new RuntimeException("Failed update recipient store", e);
+ }
+ }
+
+ private void markRegistered(
+ final Connection connection, final RecipientId recipientId
+ ) throws SQLException {
+ final var sql = (
+ """
+ UPDATE %s
+ SET unregistered_timestamp = ?
+ WHERE _id = ?
+ """
+ ).formatted(TABLE_RECIPIENT);
+ try (final var statement = connection.prepareStatement(sql)) {
+ statement.setNull(1, Types.INTEGER);
+ statement.setLong(2, recipientId.id());
+ statement.executeUpdate();
+ }
+ }
+
+ private void markUnregistered(
+ final Connection connection, final RecipientId recipientId
+ ) throws SQLException {
+ final var sql = (
+ """
+ UPDATE %s
+ SET unregistered_timestamp = ?
+ WHERE _id = ? AND unregistered_timestamp IS NULL
+ """
+ ).formatted(TABLE_RECIPIENT);
+ try (final var statement = connection.prepareStatement(sql)) {
+ statement.setLong(1, System.currentTimeMillis());
+ statement.setLong(2, recipientId.id());
+ statement.executeUpdate();
+ }
+ }
+