Skip to content

Commit

Permalink
[messages] pending messages queue
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Feb 29, 2024
1 parent c2a6afc commit 201d5dd
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 116 deletions.
144 changes: 144 additions & 0 deletions app/schemas/me.capcom.smsgateway.data.AppDatabase/7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"formatVersion": 1,
"database": {
"version": 7,
"identityHash": "0638620d8ed8717433cb8e718cfc4646",
"entities": [
{
"tableName": "Message",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `text` TEXT NOT NULL, `withDeliveryReport` INTEGER NOT NULL DEFAULT 1, `simNumber` INTEGER, `validUntil` TEXT, `isEncrypted` INTEGER NOT NULL DEFAULT 0, `skipPhoneValidation` INTEGER NOT NULL DEFAULT 0, `source` TEXT NOT NULL DEFAULT 'Local', `state` TEXT NOT NULL, `createdAt` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "text",
"columnName": "text",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "withDeliveryReport",
"columnName": "withDeliveryReport",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "simNumber",
"columnName": "simNumber",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "validUntil",
"columnName": "validUntil",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isEncrypted",
"columnName": "isEncrypted",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "skipPhoneValidation",
"columnName": "skipPhoneValidation",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "source",
"columnName": "source",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "'Local'"
},
{
"fieldPath": "state",
"columnName": "state",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "createdAt",
"columnName": "createdAt",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "MessageRecipient",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`messageId` TEXT NOT NULL, `phoneNumber` TEXT NOT NULL, `state` TEXT NOT NULL, `error` TEXT, PRIMARY KEY(`messageId`, `phoneNumber`), FOREIGN KEY(`messageId`) REFERENCES `Message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "messageId",
"columnName": "messageId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "phoneNumber",
"columnName": "phoneNumber",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "state",
"columnName": "state",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "error",
"columnName": "error",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"messageId",
"phoneNumber"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": [
{
"table": "Message",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"messageId"
],
"referencedColumns": [
"id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0638620d8ed8717433cb8e718cfc4646')"
]
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/me/capcom/smsgateway/data/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import me.capcom.smsgateway.data.entities.MessageRecipient

@Database(
entities = [Message::class, MessageRecipient::class],
version = 6,
version = 7,
autoMigrations = [
AutoMigration(from = 1, to = 2),
AutoMigration(from = 2, to = 3),
AutoMigration(from = 3, to = 4),
AutoMigration(from = 4, to = 5),
AutoMigration(from = 5, to = 6),
AutoMigration(from = 6, to = 7),
]
)
@TypeConverters(Converters::class)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/me/capcom/smsgateway/data/dao/MessageDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ interface MessageDao {
@Query("SELECT * FROM message ORDER BY createdAt DESC LIMIT 50")
fun selectLast(): LiveData<List<Message>>

@Transaction
@Query("SELECT * FROM message WHERE state = 'Pending' ORDER BY createdAt")
fun selectPending(): List<MessageWithRecipients>

@Transaction
@Query("SELECT * FROM message WHERE id = :id")
fun get(id: String): MessageWithRecipients?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class Message(
val validUntil: Date?,
@ColumnInfo(defaultValue = "0")
val isEncrypted: Boolean,
@ColumnInfo(defaultValue = "0")
val skipPhoneValidation: Boolean,

@ColumnInfo(defaultValue = "Local")
val source: MessageSource,
Expand Down
Loading

0 comments on commit 201d5dd

Please sign in to comment.