save "silent" in chat messages (incl DB)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-01-06 15:12:45 +01:00
parent 3fdaa4bdcd
commit f665b1c116
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
9 changed files with 51 additions and 24 deletions

View File

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 13,
"identityHash": "ec1e16b220080592a488165e493b4f89",
"identityHash": "a521f027909f69f4c7d1855f84a2e67f",
"entities": [
{
"tableName": "User",
@ -450,7 +450,7 @@
},
{
"tableName": "ChatMessages",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`internalId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `token` TEXT NOT NULL, `id` INTEGER NOT NULL, `internalConversationId` TEXT NOT NULL, `actorDisplayName` TEXT NOT NULL, `message` TEXT NOT NULL, `actorId` TEXT NOT NULL, `actorType` TEXT NOT NULL, `deleted` INTEGER NOT NULL, `expirationTimestamp` INTEGER NOT NULL, `isReplyable` INTEGER NOT NULL, `lastEditActorDisplayName` TEXT, `lastEditActorId` TEXT, `lastEditActorType` TEXT, `lastEditTimestamp` INTEGER, `markdown` INTEGER, `messageParameters` TEXT, `messageType` TEXT NOT NULL, `parent` INTEGER, `reactions` TEXT, `reactionsSelf` TEXT, `referenceId` TEXT, `systemMessage` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `isTemporary` INTEGER NOT NULL, `sendingFailed` INTEGER NOT NULL, PRIMARY KEY(`internalId`), FOREIGN KEY(`internalConversationId`) REFERENCES `Conversations`(`internalId`) ON UPDATE CASCADE ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`internalId` TEXT NOT NULL, `accountId` INTEGER NOT NULL, `token` TEXT NOT NULL, `id` INTEGER NOT NULL, `internalConversationId` TEXT NOT NULL, `actorDisplayName` TEXT NOT NULL, `message` TEXT NOT NULL, `actorId` TEXT NOT NULL, `actorType` TEXT NOT NULL, `deleted` INTEGER NOT NULL, `expirationTimestamp` INTEGER NOT NULL, `isReplyable` INTEGER NOT NULL, `isTemporary` INTEGER NOT NULL, `lastEditActorDisplayName` TEXT, `lastEditActorId` TEXT, `lastEditActorType` TEXT, `lastEditTimestamp` INTEGER, `markdown` INTEGER, `messageParameters` TEXT, `messageType` TEXT NOT NULL, `parent` INTEGER, `reactions` TEXT, `reactionsSelf` TEXT, `referenceId` TEXT, `sendingFailed` INTEGER NOT NULL, `silent` INTEGER NOT NULL, `systemMessage` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, PRIMARY KEY(`internalId`), FOREIGN KEY(`internalConversationId`) REFERENCES `Conversations`(`internalId`) ON UPDATE CASCADE ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "internalId",
@ -524,6 +524,12 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isTemporary",
"columnName": "isTemporary",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastEditActorDisplayName",
"columnName": "lastEditActorDisplayName",
@ -590,6 +596,18 @@
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "sendingFailed",
"columnName": "sendingFailed",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "silent",
"columnName": "silent",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "systemMessageType",
"columnName": "systemMessage",
@ -601,18 +619,6 @@
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isTemporary",
"columnName": "isTemporary",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "sendingFailed",
"columnName": "sendingFailed",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
@ -737,7 +743,7 @@
"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, 'ec1e16b220080592a488165e493b4f89')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a521f027909f69f4c7d1855f84a2e67f')"
]
}
}

View File

@ -105,6 +105,7 @@ interface ChatMessageRepository : LifecycleAwareManager {
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
): Flow<Result<ChatMessage?>>

View File

@ -119,7 +119,9 @@ data class ChatMessage(
var referenceId: String? = null,
var sendingFailed: Boolean = true
var sendingFailed: Boolean = true,
var silent: Boolean = false
) : MessageContentType,
MessageContentType.Image {

View File

@ -929,7 +929,7 @@ class OfflineFirstChatRepository @Inject constructor(
it.message,
it.actorDisplayName,
it.parentMessageId?.toIntOrZero() ?: 0,
false,
it.silent,
it.referenceId.orEmpty()
).collect { result ->
if (result.isSuccess) {
@ -951,6 +951,7 @@ class OfflineFirstChatRepository @Inject constructor(
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
): Flow<Result<ChatMessage?>> =
flow {
@ -959,6 +960,7 @@ class OfflineFirstChatRepository @Inject constructor(
internalConversationId,
message.toString(),
replyTo,
sendWithoutNotification,
referenceId
)
@ -980,6 +982,7 @@ class OfflineFirstChatRepository @Inject constructor(
internalConversationId: String,
message: String,
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
): ChatMessageEntity {
val currentTimeMillies = System.currentTimeMillis()
@ -1007,12 +1010,13 @@ class OfflineFirstChatRepository @Inject constructor(
parentMessageId = parentMessageId,
systemMessageType = ChatMessage.SystemMessageType.DUMMY,
replyable = false,
timestamp = System.currentTimeMillis() / MILLIES,
timestamp = currentTimeMillies / MILLIES,
expirationTimestamp = 0,
actorDisplayName = currentUser.displayName!!,
referenceId = referenceId,
isTemporary = true,
sendingFailed = false
sendingFailed = false,
silent = sendWithoutNotification
)
return entity
}

View File

@ -134,6 +134,7 @@ class MessageInputViewModel @Inject constructor(
message,
displayName,
replyTo,
sendWithoutNotification,
referenceId
).collect { result ->
if (result.isSuccess) {

View File

@ -39,7 +39,8 @@ fun ChatMessageJson.asEntity(accountId: Long) =
lastEditActorType = lastEditActorType,
lastEditTimestamp = lastEditTimestamp,
deleted = deleted,
referenceId = referenceId
referenceId = referenceId,
silent = silent
)
fun ChatMessageEntity.asModel() =
@ -68,7 +69,8 @@ fun ChatMessageEntity.asModel() =
referenceId = referenceId,
isTemporary = isTemporary,
sendingFailed = sendingFailed,
readStatus = ReadStatus.NONE
readStatus = ReadStatus.NONE,
silent = silent
)
fun ChatMessageJson.asModel() =
@ -94,5 +96,6 @@ fun ChatMessageJson.asModel() =
lastEditActorType = lastEditActorType,
lastEditTimestamp = lastEditTimestamp,
isDeleted = deleted,
referenceId = referenceId
referenceId = referenceId,
silent = silent
)

View File

@ -65,7 +65,7 @@ data class ChatMessageEntity(
@ColumnInfo(name = "reactionsSelf") var reactionsSelf: ArrayList<String>? = null,
@ColumnInfo(name = "referenceId") var referenceId: String? = null,
@ColumnInfo(name = "sendingFailed") var sendingFailed: Boolean = false,
@ColumnInfo(name = "silent") var silent: Boolean = false,
@ColumnInfo(name = "systemMessage") var systemMessageType: ChatMessage.SystemMessageType,
@ColumnInfo(name = "timestamp") var timestamp: Long = 0
// missing/not needed: silent
)

View File

@ -292,5 +292,14 @@ object Migrations {
} catch (e: SQLException) {
Log.i("Migrations", "Something went wrong when adding column sendingFailed to table ChatMessages")
}
try {
db.execSQL(
"ALTER TABLE ChatMessages " +
"ADD COLUMN silent INTEGER NOT NULL DEFAULT 0;"
)
} catch (e: SQLException) {
Log.i("Migrations", "Something went wrong when adding column silent to table ChatMessages")
}
}
}

View File

@ -43,5 +43,6 @@ data class ChatMessageJson(
@JsonField(name = ["lastEditActorType"]) var lastEditActorType: String? = null,
@JsonField(name = ["lastEditTimestamp"]) var lastEditTimestamp: Long? = 0,
@JsonField(name = ["deleted"]) var deleted: Boolean = false,
@JsonField(name = ["referenceId"]) var referenceId: String? = null
@JsonField(name = ["referenceId"]) var referenceId: String? = null,
@JsonField(name = ["silent"]) var silent: Boolean = false,
) : Parcelable