Add initial implementation of calls tab behind a feature flag.

This commit is contained in:
Alex Hart
2023-03-15 12:52:18 -03:00
committed by Greyson Parrelli
parent d1373d2767
commit 88de0f21e7
33 changed files with 1464 additions and 63 deletions

View File

@@ -14,7 +14,10 @@ import org.signal.core.util.requireObject
import org.signal.core.util.select
import org.signal.core.util.update
import org.signal.core.util.withinTransaction
import org.thoughtcrime.securesms.calls.log.CallLogFilter
import org.thoughtcrime.securesms.calls.log.CallLogRow
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage.CallEvent
@@ -136,6 +139,86 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
return calls
}
private fun getCallsCursor(isCount: Boolean, offset: Int, limit: Int, searchTerm: String?, filter: CallLogFilter): Cursor {
val filterClause = when (filter) {
CallLogFilter.ALL -> SqlUtil.buildQuery("")
CallLogFilter.MISSED -> SqlUtil.buildQuery("$EVENT == ${Event.serialize(Event.MISSED)}")
}
val queryClause = if (!searchTerm.isNullOrEmpty()) {
val glob = SqlUtil.buildCaseInsensitiveGlobPattern(searchTerm)
val selection =
"""
${RecipientTable.TABLE_NAME}.${RecipientTable.BLOCKED} = ? AND ${RecipientTable.TABLE_NAME}.${RecipientTable.HIDDEN} = ? AND
(
sort_name GLOB ? OR
${RecipientTable.TABLE_NAME}.${RecipientTable.USERNAME} GLOB ? OR
${RecipientTable.TABLE_NAME}.${RecipientTable.PHONE} GLOB ? OR
${RecipientTable.TABLE_NAME}.${RecipientTable.EMAIL} GLOB ?
)
""".trimIndent()
SqlUtil.buildQuery(selection, 0, 0, glob, glob, glob, glob)
} else {
SqlUtil.buildQuery("")
}
val whereClause = filterClause and queryClause
val where = if (whereClause.where.isNotEmpty()) {
"WHERE ${whereClause.where}"
} else {
""
}
val offsetLimit = if (limit > 0) {
"LIMIT $offset,$limit"
} else {
""
}
//language=sql
val statement = """
SELECT
${if (isCount) "COUNT(*)," else "$TABLE_NAME.*, ${MessageTable.DATE_RECEIVED},"}
LOWER(
COALESCE(
NULLIF(${RecipientTable.TABLE_NAME}.${RecipientTable.SYSTEM_JOINED_NAME}, ''),
NULLIF(${RecipientTable.TABLE_NAME}.${RecipientTable.SYSTEM_GIVEN_NAME}, ''),
NULLIF(${RecipientTable.TABLE_NAME}.${RecipientTable.PROFILE_JOINED_NAME}, ''),
NULLIF(${RecipientTable.TABLE_NAME}.${RecipientTable.PROFILE_GIVEN_NAME}, ''),
NULLIF(${RecipientTable.TABLE_NAME}.${RecipientTable.USERNAME}, '')
)
) AS sort_name
FROM $TABLE_NAME
INNER JOIN ${RecipientTable.TABLE_NAME} ON ${RecipientTable.TABLE_NAME}.${RecipientTable.ID} = $TABLE_NAME.$PEER
INNER JOIN ${MessageTable.TABLE_NAME} ON ${MessageTable.TABLE_NAME}.${MessageTable.ID} = $TABLE_NAME.$MESSAGE_ID
$where
ORDER BY ${MessageTable.TABLE_NAME}.${MessageTable.DATE_RECEIVED} DESC
$offsetLimit
""".trimIndent()
return readableDatabase.query(statement, whereClause.whereArgs)
}
fun getCallsCount(searchTerm: String?, filter: CallLogFilter): Int {
return getCallsCursor(true, 0, 0, searchTerm, filter).use {
it.moveToFirst()
it.getInt(0)
}
}
fun getCalls(offset: Int, limit: Int, searchTerm: String?, filter: CallLogFilter): List<CallLogRow.Call> {
return getCallsCursor(false, offset, limit, searchTerm, filter).readToList {
val call = Call.deserialize(it)
val recipient = Recipient.resolved(call.peer)
val date = it.requireLong(MessageTable.DATE_RECEIVED)
CallLogRow.Call(
call = call,
peer = recipient,
date = date
)
}
}
override fun remapRecipient(fromId: RecipientId, toId: RecipientId) {
writableDatabase
.update(TABLE_NAME)

View File

@@ -131,7 +131,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
const val ID = "_id"
const val SERVICE_ID = "uuid"
const val PNI_COLUMN = "pni"
private const val USERNAME = "username"
const val USERNAME = "username"
const val PHONE = "phone"
const val EMAIL = "email"
const val GROUP_ID = "group_id"
@@ -167,9 +167,9 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
const val FORCE_SMS_SELECTION = "force_sms_selection"
private const val CAPABILITIES = "capabilities"
const val STORAGE_SERVICE_ID = "storage_service_key"
private const val PROFILE_GIVEN_NAME = "signal_profile_name"
const val PROFILE_GIVEN_NAME = "signal_profile_name"
private const val PROFILE_FAMILY_NAME = "profile_family_name"
private const val PROFILE_JOINED_NAME = "profile_joined_name"
const val PROFILE_JOINED_NAME = "profile_joined_name"
private const val MENTION_SETTING = "mention_setting"
private const val STORAGE_PROTO = "storage_proto"
private const val LAST_SESSION_RESET = "last_session_reset"
@@ -183,12 +183,12 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
private const val CUSTOM_CHAT_COLORS_ID = "custom_chat_colors_id"
private const val BADGES = "badges"
const val SEARCH_PROFILE_NAME = "search_signal_profile"
private const val SORT_NAME = "sort_name"
const val SORT_NAME = "sort_name"
private const val IDENTITY_STATUS = "identity_status"
private const val IDENTITY_KEY = "identity_key"
private const val NEEDS_PNI_SIGNATURE = "needs_pni_signature"
private const val UNREGISTERED_TIMESTAMP = "unregistered_timestamp"
private const val HIDDEN = "hidden"
const val HIDDEN = "hidden"
const val REPORTING_TOKEN = "reporting_token"
@JvmField