mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Improved missed call state handling.
This commit is contained in:
committed by
Greyson Parrelli
parent
95fbd7a31c
commit
e60b32202e
@@ -118,6 +118,30 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
|
||||
notifyConversationListListeners()
|
||||
}
|
||||
|
||||
fun markAllCallEventsWithPeerBeforeTimestampRead(peer: RecipientId, timestamp: Long): Call? {
|
||||
val latestCallAsOfTimestamp = writableDatabase.withinTransaction { db ->
|
||||
val updated = db.update(TABLE_NAME)
|
||||
.values(READ to ReadState.serialize(ReadState.READ))
|
||||
.where("$PEER = ? AND $TIMESTAMP <= ?", peer.toLong(), timestamp)
|
||||
.run()
|
||||
|
||||
if (updated == 0) {
|
||||
null
|
||||
} else {
|
||||
db.select()
|
||||
.from(TABLE_NAME)
|
||||
.where("$PEER = ? AND $TIMESTAMP <= ?", peer.toLong(), timestamp)
|
||||
.orderBy("$TIMESTAMP DESC")
|
||||
.limit(1)
|
||||
.run()
|
||||
.readToSingleObject(Call.Deserializer)
|
||||
}
|
||||
}
|
||||
|
||||
notifyConversationListListeners()
|
||||
return latestCallAsOfTimestamp
|
||||
}
|
||||
|
||||
fun getUnreadMissedCallCount(): Long {
|
||||
return readableDatabase
|
||||
.count()
|
||||
|
||||
@@ -433,6 +433,12 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
($TYPE = ${MessageTypes.GROUP_CALL_TYPE})
|
||||
)"""
|
||||
|
||||
private const val IS_MISSED_CALL_TYPE_CLAUSE = """(
|
||||
($TYPE = ${MessageTypes.MISSED_AUDIO_CALL_TYPE})
|
||||
OR
|
||||
($TYPE = ${MessageTypes.MISSED_VIDEO_CALL_TYPE})
|
||||
)"""
|
||||
|
||||
private val outgoingTypeClause: String by lazy {
|
||||
MessageTypes.OUTGOING_MESSAGE_TYPES
|
||||
.map { "($TABLE_NAME.$TYPE & ${MessageTypes.BASE_TYPE_MASK} = $it)" }
|
||||
@@ -4647,7 +4653,19 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
return readableDatabase
|
||||
.select(*MMS_PROJECTION)
|
||||
.from(TABLE_NAME)
|
||||
.where("$NOTIFIED = 0 AND $STORY_TYPE = 0 AND $LATEST_REVISION_ID IS NULL AND ($READ = 0 OR $REACTIONS_UNREAD = 1 ${if (stickyQuery.isNotEmpty()) "OR ($stickyQuery)" else ""})")
|
||||
.where(
|
||||
"""
|
||||
$NOTIFIED = 0
|
||||
AND $STORY_TYPE = 0
|
||||
AND $LATEST_REVISION_ID IS NULL
|
||||
AND (
|
||||
$READ = 0
|
||||
OR $REACTIONS_UNREAD = 1
|
||||
${if (stickyQuery.isNotEmpty()) "OR ($stickyQuery)" else ""}
|
||||
OR ($IS_MISSED_CALL_TYPE_CLAUSE AND EXISTS (SELECT 1 FROM ${CallTable.TABLE_NAME} WHERE ${CallTable.MESSAGE_ID} = $TABLE_NAME.$ID AND ${CallTable.EVENT} = ${CallTable.Event.serialize(CallTable.Event.MISSED)} AND ${CallTable.READ} = 0))
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
.orderBy("$DATE_RECEIVED ASC")
|
||||
.run()
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V225_AddLocalUserJo
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V226_AddAttachmentMediaIdIndex
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V227_AddAttachmentArchiveTransferState
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V228_AddNameCollisionTables
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V229_MarkMissedCallEventsNotified
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -174,10 +175,11 @@ object SignalDatabaseMigrations {
|
||||
225 to V225_AddLocalUserJoinedStateAndGroupCallActiveState,
|
||||
226 to V226_AddAttachmentMediaIdIndex,
|
||||
227 to V227_AddAttachmentArchiveTransferState,
|
||||
228 to V228_AddNameCollisionTables
|
||||
228 to V228_AddNameCollisionTables,
|
||||
229 to V229_MarkMissedCallEventsNotified
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 228
|
||||
const val DATABASE_VERSION = 229
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* In order to both correct how we display missed calls and not spam users,
|
||||
* we want to mark every missed call event in the database as notified.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V229_MarkMissedCallEventsNotified : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL(
|
||||
"""
|
||||
UPDATE message
|
||||
SET notified = 1
|
||||
WHERE (type = 3) OR (type = 8)
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user