refactor: prevent calls from non hasSent participants

This commit is contained in:
jubb
2021-12-07 16:09:58 +11:00
parent 75efd7b21a
commit 522c5cd520
6 changed files with 25 additions and 18 deletions

View File

@@ -46,6 +46,7 @@ class WebRtcCallActivity: PassphraseRequiredActionBarActivity() {
companion object {
const val ACTION_PRE_OFFER = "pre-offer"
const val ACTION_FULL_SCREEN_INTENT = "fullscreen-intent"
const val ACTION_ANSWER = "answer"
const val ACTION_END = "end-call"
@@ -93,10 +94,12 @@ class WebRtcCallActivity: PassphraseRequiredActionBarActivity() {
if (intent.action == ACTION_ANSWER) {
answerCall()
}
if (intent.action == ACTION_PRE_OFFER) {
wantsToAnswer = true
}
if (intent.action == ACTION_FULL_SCREEN_INTENT) {
supportActionBar?.setDisplayHomeAsUpEnabled(false)
}
microphoneButton.setOnClickListener {
val audioEnabledIntent = WebRtcCallService.microphoneIntent(this, !viewModel.microphoneEnabled)

View File

@@ -625,4 +625,13 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
val callMessage = IncomingTextMessage.fromCallInfo(callMessageType, address, Optional.absent(), sentTimestamp)
database.insertCallMessage(callMessage)
}
override fun conversationHasOutgoing(userPublicKey: String): Boolean {
val database = DatabaseComponent.get(context).threadDatabase()
val threadId = database.getThreadIdIfExistsFor(userPublicKey)
if (threadId == -1L) return false
return database.getLastSeenAndHasSent(threadId).second() ?: false
}
}

View File

@@ -439,22 +439,10 @@ public class ThreadDatabase extends Database {
SessionMetaProtocol.clearReceivedMessages();
}
public boolean hasThread(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{ ID }, ID_WHERE, new String[]{ String.valueOf(threadId) }, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) { return true; }
return false;
} finally {
if (cursor != null) cursor.close();
}
}
public long getThreadIdIfExistsFor(Recipient recipient) {
public long getThreadIdIfExistsFor(String address) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String where = ADDRESS + " = ?";
String[] recipientsArg = new String[] {recipient.getAddress().serialize()};
String[] recipientsArg = new String[] {address};
Cursor cursor = null;
try {
@@ -470,6 +458,10 @@ public class ThreadDatabase extends Database {
}
}
public long getThreadIdIfExistsFor(Recipient recipient) {
return getThreadIdIfExistsFor(recipient.getAddress().serialize());
}
public long getOrCreateThreadIdFor(Recipient recipient) {
return getOrCreateThreadIdFor(recipient, DistributionTypes.DEFAULT);
}

View File

@@ -59,7 +59,7 @@ class CallNotificationBuilder {
.setSmallIcon(R.drawable.ic_baseline_call_24)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setPriority(NotificationCompat.PRIORITY_MIN)
recipient?.name?.let { name ->
builder.setContentTitle(name)
@@ -68,7 +68,6 @@ class CallNotificationBuilder {
when (type) {
TYPE_INCOMING_CONNECTING -> {
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting))
builder.priority = NotificationCompat.PRIORITY_LOW
}
TYPE_INCOMING_PRE_OFFER,
TYPE_INCOMING_RINGING -> {
@@ -125,6 +124,7 @@ class CallNotificationBuilder {
private fun getFullScreenPendingIntent(context: Context): PendingIntent {
val intent = Intent(context, WebRtcCallActivity::class.java)
.setAction(WebRtcCallActivity.ACTION_FULL_SCREEN_INTENT)
return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}

View File

@@ -28,11 +28,13 @@ class CallMessageProcessor(private val context: Context, lifecycle: Lifecycle, p
while (isActive) {
val nextMessage = WebRtcUtils.SIGNAL_QUEUE.receive()
Log.d("Loki", nextMessage.type?.name ?: "CALL MESSAGE RECEIVED")
val sender = nextMessage.sender ?: continue
if (!storage.conversationHasOutgoing(sender)) continue
if (!TextSecurePreferences.isCallNotificationsEnabled(context)) {
Log.d("Loki","Dropping call message if call notifications disabled")
if (nextMessage.type != PRE_OFFER) continue
val sentTimestamp = nextMessage.sentTimestamp ?: continue
val sender = nextMessage.sender ?: continue
if (TextSecurePreferences.setShownCallNotification(context)) {
// first time call notification encountered
val notification = CallNotificationBuilder.getFirstCallNotification(context)

View File

@@ -155,4 +155,5 @@ interface StorageProtocol {
fun persist(message: VisibleMessage, quotes: QuoteModel?, linkPreview: List<LinkPreview?>, groupPublicKey: String?, openGroupID: String?, attachments: List<Attachment>): Long?
fun insertDataExtractionNotificationMessage(senderPublicKey: String, message: DataExtractionNotificationInfoMessage, sentTimestamp: Long)
fun insertCallMessage(senderPublicKey: String, callMessageType: CallMessageType, sentTimestamp: Long)
fun conversationHasOutgoing(userPublicKey: String): Boolean
}