mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Allow call links to exist in the calls tab.
This commit is contained in:
@@ -5,8 +5,10 @@ import android.content.Context
|
||||
import android.database.Cursor
|
||||
import androidx.core.content.contentValuesOf
|
||||
import org.signal.core.util.Serializer
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.insertInto
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.readToList
|
||||
import org.signal.core.util.readToSingleInt
|
||||
import org.signal.core.util.readToSingleObject
|
||||
import org.signal.core.util.requireBlob
|
||||
@@ -20,8 +22,10 @@ import org.signal.core.util.select
|
||||
import org.signal.core.util.update
|
||||
import org.signal.core.util.withinTransaction
|
||||
import org.signal.ringrtc.CallLinkState.Restrictions
|
||||
import org.thoughtcrime.securesms.calls.log.CallLogRow
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkCredentials
|
||||
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkRoomId
|
||||
@@ -88,7 +92,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
callLink: CallLink
|
||||
) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
val recipientId = SignalDatabase.recipients.getOrInsertFromCallLinkRoomId(callLink.roomId)
|
||||
val recipientId = SignalDatabase.recipients.getOrInsertFromCallLinkRoomId(callLink.roomId, callLink.avatarColor)
|
||||
|
||||
db
|
||||
.insertInto(TABLE_NAME)
|
||||
@@ -97,6 +101,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
}
|
||||
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallLinkObservers(callLink.roomId)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallUpdateObservers()
|
||||
}
|
||||
|
||||
fun updateCallLinkCredentials(
|
||||
@@ -115,6 +120,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
.run()
|
||||
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallLinkObservers(roomId)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallUpdateObservers()
|
||||
}
|
||||
|
||||
fun updateCallLinkState(
|
||||
@@ -128,6 +134,7 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
.run()
|
||||
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallLinkObservers(roomId)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyCallUpdateObservers()
|
||||
}
|
||||
|
||||
fun callLinkExists(
|
||||
@@ -171,6 +178,59 @@ class CallLinkTable(context: Context, databaseHelper: SignalDatabase) : Database
|
||||
}
|
||||
}
|
||||
|
||||
fun getCallLinksCount(query: String?): Int {
|
||||
return queryCallLinks(query, -1, -1, true).readToSingleInt(0)
|
||||
}
|
||||
|
||||
fun getCallLinks(query: String?, offset: Int, limit: Int): List<CallLogRow.CallLink> {
|
||||
return queryCallLinks(query, offset, limit, false).readToList {
|
||||
val callLink = CallLinkDeserializer.deserialize(it)
|
||||
CallLogRow.CallLink(callLink, Recipient.resolved(callLink.recipientId), query)
|
||||
}
|
||||
}
|
||||
|
||||
private fun queryCallLinks(query: String?, offset: Int, limit: Int, asCount: Boolean): Cursor {
|
||||
//language=sql
|
||||
val noCallEvent = """
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM ${CallTable.TABLE_NAME}
|
||||
WHERE ${CallTable.PEER} = $TABLE_NAME.$RECIPIENT_ID
|
||||
AND ${CallTable.TYPE} = ${CallTable.Type.serialize(CallTable.Type.AD_HOC_CALL)}
|
||||
AND ${CallTable.EVENT} != ${CallTable.Event.serialize(CallTable.Event.DELETE)}
|
||||
)
|
||||
""".trimIndent()
|
||||
|
||||
val searchFilter = if (!query.isNullOrEmpty()) {
|
||||
SqlUtil.buildQuery("AND $NAME GLOB ?", SqlUtil.buildCaseInsensitiveGlobPattern(query))
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val limitOffset = if (limit >= 0 && offset >= 0) {
|
||||
//language=sql
|
||||
"LIMIT $limit OFFSET $offset"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
val projection = if (asCount) {
|
||||
"COUNT(*)"
|
||||
} else {
|
||||
"*"
|
||||
}
|
||||
|
||||
//language=sql
|
||||
val statement = """
|
||||
SELECT $projection
|
||||
FROM $TABLE_NAME
|
||||
WHERE $noCallEvent AND NOT $REVOKED ${searchFilter?.where ?: ""}
|
||||
$limitOffset
|
||||
""".trimIndent()
|
||||
|
||||
return readableDatabase.query(statement, searchFilter?.whereArgs)
|
||||
}
|
||||
|
||||
private object CallLinkSerializer : Serializer<CallLink, ContentValues> {
|
||||
override fun serialize(data: CallLink): ContentValues {
|
||||
return contentValuesOf(
|
||||
|
||||
@@ -47,14 +47,14 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
|
||||
private val TAG = Log.tag(CallTable::class.java)
|
||||
private val TIME_WINDOW = TimeUnit.HOURS.toMillis(4)
|
||||
|
||||
private const val TABLE_NAME = "call"
|
||||
const val TABLE_NAME = "call"
|
||||
private const val ID = "_id"
|
||||
private const val CALL_ID = "call_id"
|
||||
private const val MESSAGE_ID = "message_id"
|
||||
private const val PEER = "peer"
|
||||
private const val TYPE = "type"
|
||||
const val PEER = "peer"
|
||||
const val TYPE = "type"
|
||||
private const val DIRECTION = "direction"
|
||||
private const val EVENT = "event"
|
||||
const val EVENT = "event"
|
||||
private const val TIMESTAMP = "timestamp"
|
||||
private const val RINGER = "ringer"
|
||||
private const val DELETION_TIMESTAMP = "deletion_timestamp"
|
||||
|
||||
@@ -319,7 +319,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
DISTRIBUTION_LIST_ID,
|
||||
NEEDS_PNI_SIGNATURE,
|
||||
HIDDEN,
|
||||
REPORTING_TOKEN
|
||||
REPORTING_TOKEN,
|
||||
CALL_LINK_ROOM_ID
|
||||
)
|
||||
|
||||
private val ID_PROJECTION = arrayOf(ID)
|
||||
@@ -564,14 +565,15 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
).recipientId
|
||||
}
|
||||
|
||||
fun getOrInsertFromCallLinkRoomId(callLinkRoomId: CallLinkRoomId): RecipientId {
|
||||
fun getOrInsertFromCallLinkRoomId(callLinkRoomId: CallLinkRoomId, avatarColor: AvatarColor): RecipientId {
|
||||
return getOrInsertByColumn(
|
||||
CALL_LINK_ROOM_ID,
|
||||
callLinkRoomId.serialize(),
|
||||
contentValuesOf(
|
||||
GROUP_TYPE to GroupType.CALL_LINK.id,
|
||||
CALL_LINK_ROOM_ID to callLinkRoomId.serialize(),
|
||||
PROFILE_SHARING to 1
|
||||
PROFILE_SHARING to 1,
|
||||
AVATAR_COLOR to avatarColor.serialize()
|
||||
)
|
||||
).recipientId
|
||||
}
|
||||
@@ -4172,7 +4174,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
hasGroupsInCommon = cursor.requireBoolean(GROUPS_IN_COMMON),
|
||||
badges = parseBadgeList(cursor.requireBlob(BADGES)),
|
||||
needsPniSignature = cursor.requireBoolean(NEEDS_PNI_SIGNATURE),
|
||||
isHidden = cursor.requireBoolean(HIDDEN)
|
||||
isHidden = cursor.requireBoolean(HIDDEN),
|
||||
callLinkRoomId = cursor.requireString(CALL_LINK_ROOM_ID)?.let { CallLinkRoomId.DatabaseSerializer.deserialize(it) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkRoomId
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
@@ -79,7 +80,8 @@ data class RecipientRecord(
|
||||
val badges: List<Badge>,
|
||||
@get:JvmName("needsPniSignature")
|
||||
val needsPniSignature: Boolean,
|
||||
val isHidden: Boolean
|
||||
val isHidden: Boolean,
|
||||
val callLinkRoomId: CallLinkRoomId?
|
||||
) {
|
||||
|
||||
fun getDefaultSubscriptionId(): Optional<Int> {
|
||||
|
||||
Reference in New Issue
Block a user