]> nmode's Git Repositories - signal-cli/commitdiff
Store urgent field in database
authorAsamK <asamk@gmx.de>
Wed, 17 Aug 2022 19:20:36 +0000 (21:20 +0200)
committerAsamK <asamk@gmx.de>
Sun, 28 Aug 2022 14:04:05 +0000 (16:04 +0200)
lib/src/main/java/org/asamk/signal/manager/storage/AccountDatabase.java
lib/src/main/java/org/asamk/signal/manager/storage/sendLog/MessageSendLogStore.java

index 26c2e3666bbb8eac8cf2a07599152ed32021eb21..c077708b21ba73cec73d354f6ea1a071b7735555 100644 (file)
@@ -22,7 +22,7 @@ import java.sql.SQLException;
 public class AccountDatabase extends Database {
 
     private final static Logger logger = LoggerFactory.getLogger(AccountDatabase.class);
 public class AccountDatabase extends Database {
 
     private final static Logger logger = LoggerFactory.getLogger(AccountDatabase.class);
-    private static final long DATABASE_VERSION = 8;
+    private static final long DATABASE_VERSION = 9;
 
     private AccountDatabase(final HikariDataSource dataSource) {
         super(logger, DATABASE_VERSION, dataSource);
 
     private AccountDatabase(final HikariDataSource dataSource) {
         super(logger, DATABASE_VERSION, dataSource);
@@ -204,5 +204,13 @@ public class AccountDatabase extends Database {
                                         """);
             }
         }
                                         """);
             }
         }
+        if (oldVersion < 9) {
+            logger.debug("Updating database: Adding urgent field");
+            try (final var statement = connection.createStatement()) {
+                statement.executeUpdate("""
+                                        ALTER TABLE message_send_log_content ADD COLUMN urgent BOOLEAN NOT NULL DEFAULT TRUE;
+                                        """);
+            }
+        }
     }
 }
     }
 }
index 5dde88b2db91747b0d10544341ef6e4cc69afed4..8a807fd56c7003c0e80ecb3bf7846866b26fc914 100644 (file)
@@ -76,7 +76,8 @@ public class MessageSendLogStore implements AutoCloseable {
                                       group_id BLOB,
                                       timestamp INTEGER NOT NULL,
                                       content BLOB NOT NULL,
                                       group_id BLOB,
                                       timestamp INTEGER NOT NULL,
                                       content BLOB NOT NULL,
-                                      content_hint INTEGER NOT NULL
+                                      content_hint INTEGER NOT NULL,
+                                      urgent BOOLEAN NOT NULL
                                     );
                                     CREATE INDEX mslc_timestamp_index ON message_send_log_content (timestamp);
                                     CREATE INDEX msl_recipient_index ON message_send_log (recipient_id, device_id, content_id);
                                     );
                                     CREATE INDEX mslc_timestamp_index ON message_send_log_content (timestamp);
                                     CREATE INDEX msl_recipient_index ON message_send_log (recipient_id, device_id, content_id);
@@ -112,7 +113,7 @@ public class MessageSendLogStore implements AutoCloseable {
                         return null;
                     }
                     final var contentHint = ContentHint.fromType(resultSet.getInt("content_hint"));
                         return null;
                     }
                     final var contentHint = ContentHint.fromType(resultSet.getInt("content_hint"));
-                    final var urgent = true; // TODO
+                    final var urgent = resultSet.getBoolean("urgent");
                     return new MessageSendLogEntry(groupId, content, contentHint, urgent);
                 })) {
                     return result.filter(Objects::nonNull)
                     return new MessageSendLogEntry(groupId, content, contentHint, urgent);
                 })) {
                     return result.filter(Objects::nonNull)
@@ -274,10 +275,9 @@ public class MessageSendLogStore implements AutoCloseable {
     ) {
         byte[] groupId = getGroupId(content);
 
     ) {
         byte[] groupId = getGroupId(content);
 
-        // TODO store urgent
         final var sql = """
         final var sql = """
-                        INSERT INTO %s (timestamp, group_id, content, content_hint)
-                        VALUES (?,?,?,?)
+                        INSERT INTO %s (timestamp, group_id, content, content_hint, urgent)
+                        VALUES (?,?,?,?,?)
                         """.formatted(TABLE_MESSAGE_SEND_LOG_CONTENT);
         try (final var connection = database.getConnection()) {
             connection.setAutoCommit(false);
                         """.formatted(TABLE_MESSAGE_SEND_LOG_CONTENT);
         try (final var connection = database.getConnection()) {
             connection.setAutoCommit(false);
@@ -287,6 +287,7 @@ public class MessageSendLogStore implements AutoCloseable {
                 statement.setBytes(2, groupId);
                 statement.setBytes(3, content.toByteArray());
                 statement.setInt(4, contentHint.getType());
                 statement.setBytes(2, groupId);
                 statement.setBytes(3, content.toByteArray());
                 statement.setInt(4, contentHint.getType());
+                statement.setBoolean(5, urgent);
                 statement.executeUpdate();
                 final var generatedKeys = statement.getGeneratedKeys();
                 if (generatedKeys.next()) {
                 statement.executeUpdate();
                 final var generatedKeys = statement.getGeneratedKeys();
                 if (generatedKeys.next()) {