diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt index a18ae1fcfa..6c834e9dcf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt @@ -892,7 +892,7 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl Log.d(TAG, "Updating group call state: localJoined: $localJoined, isGroupCallActive: $isGroupCallActive") - return writableDatabase.update(TABLE_NAME) + val changed = writableDatabase.update(TABLE_NAME) .values( LOCAL_JOINED to localJoined, GROUP_CALL_ACTIVE to isGroupCallActive @@ -905,6 +905,16 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl isGroupCallActive.toInt() ) .run() > 0 + + if (hasLocalUserJoined && !call.didLocalUserJoin && call.event == Event.RINGING) { + writableDatabase.update(TABLE_NAME) + .values(EVENT to Event.serialize(Event.ACCEPTED)) + .where("$CALL_ID = ?", call.callId) + .run() + Log.d(TAG, "[updateGroupCallState] Transitioned group call ${call.callId} from RINGING to ACCEPTED on local join") + } + + return changed } private fun handleGroupRingState( @@ -936,7 +946,14 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl RingUpdate.EXPIRED_REQUEST, RingUpdate.CANCELLED_BY_RINGER -> { when (call.event) { - Event.GENERIC_GROUP_CALL, Event.RINGING -> updateEventFromRingState(ringId, if (dueToNotificationProfile) Event.MISSED_NOTIFICATION_PROFILE else Event.MISSED, ringerRecipient) + Event.GENERIC_GROUP_CALL -> updateEventFromRingState(ringId, if (dueToNotificationProfile) Event.MISSED_NOTIFICATION_PROFILE else Event.MISSED, ringerRecipient) + Event.RINGING -> { + if (call.didLocalUserJoin) { + updateEventFromRingState(ringId, Event.ACCEPTED, ringerRecipient) + } else { + updateEventFromRingState(ringId, if (dueToNotificationProfile) Event.MISSED_NOTIFICATION_PROFILE else Event.MISSED, ringerRecipient) + } + } Event.JOINED -> updateEventFromRingState(ringId, Event.ACCEPTED, ringerRecipient) Event.OUTGOING_RING -> Log.w(TAG, "Received an expiration or cancellation while in OUTGOING_RING state. Ignoring.") else -> Unit @@ -946,7 +963,14 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl RingUpdate.BUSY_LOCALLY -> { when (call.event) { Event.JOINED -> updateEventFromRingState(ringId, Event.ACCEPTED) - Event.GENERIC_GROUP_CALL, Event.RINGING -> updateEventFromRingState(ringId, Event.MISSED) + Event.GENERIC_GROUP_CALL -> updateEventFromRingState(ringId, Event.MISSED) + Event.RINGING -> { + if (call.didLocalUserJoin) { + updateEventFromRingState(ringId, Event.ACCEPTED) + } else { + updateEventFromRingState(ringId, Event.MISSED) + } + } else -> { updateEventFromRingState(ringId, call.event, ringerRecipient) Log.w(TAG, "Received a busy event we can't process. Updating ringer only.") @@ -957,7 +981,14 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl RingUpdate.BUSY_ON_ANOTHER_DEVICE -> { when (call.event) { Event.JOINED -> updateEventFromRingState(ringId, Event.ACCEPTED) - Event.GENERIC_GROUP_CALL, Event.RINGING -> updateEventFromRingState(ringId, Event.MISSED) + Event.GENERIC_GROUP_CALL -> updateEventFromRingState(ringId, Event.MISSED) + Event.RINGING -> { + if (call.didLocalUserJoin) { + updateEventFromRingState(ringId, Event.ACCEPTED) + } else { + updateEventFromRingState(ringId, Event.MISSED) + } + } else -> Log.w(TAG, "Received a busy event we can't process. Ignoring.") } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MessageTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/MessageTable.kt index 775ea30297..e3ff070108 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MessageTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MessageTable.kt @@ -1064,7 +1064,8 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat val updateDetail = GroupCallUpdateDetailsUtil.parse(message.body) val containsSelf = joinedUuids.contains(SignalStore.account.requireAci().rawUuid) - val sameEraId = updateDetail.eraId == eraId && !Util.isEmpty(eraId) + // Treat empty eraId from ring requests as matching for updating + val sameEraId = (updateDetail.eraId == eraId || updateDetail.eraId.isEmpty()) && !Util.isEmpty(eraId) val inCallUuids = if (sameEraId) joinedUuids.map { it.toString() } else emptyList() val body = GroupCallUpdateDetailsUtil.createUpdatedBody(updateDetail, inCallUuids, isCallFull, isRingingOnLocalDevice) val contentValues = contentValuesOf( @@ -1111,7 +1112,8 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat val record = reader.getNext() ?: return@withinTransaction false val groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(record.body) val containsSelf = peekJoinedUuids.contains(SignalStore.account.requireAci().rawUuid) - val sameEraId = groupCallUpdateDetails.eraId == peekGroupCallEraId && !Util.isEmpty(peekGroupCallEraId) + // Treat empty eraId from ring requests as matching for updating + val sameEraId = (groupCallUpdateDetails.eraId == peekGroupCallEraId || groupCallUpdateDetails.eraId.isEmpty()) && !Util.isEmpty(peekGroupCallEraId) val inCallUuids = if (sameEraId) { peekJoinedUuids.map { it.toString() }.toList()