Skip to content

Commit

Permalink
Manage homeserver supported VoIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Dec 13, 2023
1 parent 891f90a commit 013666e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.DefaultVectorFeatures
import im.vector.app.features.DefaultVectorOverrides
import im.vector.app.features.VectorFeatures
Expand All @@ -43,8 +44,8 @@ interface FeaturesModule {
companion object {

@Provides
fun providesDefaultVectorFeatures(booleanProvider: BooleanProvider): DefaultVectorFeatures {
return DefaultVectorFeatures(booleanProvider)
fun providesDefaultVectorFeatures(stringArrayProvider: StringArrayProvider, booleanProvider: BooleanProvider): DefaultVectorFeatures {
return DefaultVectorFeatures(stringArrayProvider, booleanProvider)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DebugVectorFeatures(

private val dataStore = context.dataStore

override fun tchapIsVoipSupported() = vectorFeatures.tchapIsVoipSupported()
override fun tchapIsVoipSupported(homeServerUrl: String) = vectorFeatures.tchapIsVoipSupported(homeServerUrl)

override fun tchapIsCrossSigningEnabled() = vectorFeatures.tchapIsCrossSigningEnabled()

Expand Down
2 changes: 2 additions & 0 deletions vector-config/src/btchap/res/values/config-features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<bool name="tchap_is_cross_signing_enabled">true</bool>
<bool name="tchap_is_key_backup_enabled">true</bool>
<bool name="tchap_is_thread_enabled">false</bool>

<string-array name="tchap_is_voip_supported_homeservers" translatable="false" />
</resources>
2 changes: 2 additions & 0 deletions vector-config/src/devTchap/res/values/config-features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<bool name="tchap_is_cross_signing_enabled">true</bool>
<bool name="tchap_is_key_backup_enabled">true</bool>
<bool name="tchap_is_thread_enabled">false</bool>

<string-array name="tchap_is_voip_supported_homeservers" translatable="false" />
</resources>
4 changes: 4 additions & 0 deletions vector-config/src/tchap/res/values/config-features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<bool name="tchap_is_cross_signing_enabled">true</bool>
<bool name="tchap_is_key_backup_enabled">true</bool>
<bool name="tchap_is_thread_enabled">false</bool>

<string-array name="tchap_is_voip_supported_homeservers" translatable="false">
<item>agent.dinum.tchap.gouv.fr</item>
</string-array>
</resources>
9 changes: 7 additions & 2 deletions vector/src/main/java/im/vector/app/features/VectorFeatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import im.vector.app.R
import im.vector.app.config.Config
import im.vector.app.config.OnboardingVariant
import im.vector.app.core.resources.BooleanProvider
import im.vector.app.core.resources.StringArrayProvider
import im.vector.app.features.settings.VectorPreferences
import javax.inject.Inject

interface VectorFeatures {

fun tchapIsVoipSupported(): Boolean
fun tchapIsVoipSupported(homeServerUrl: String): Boolean
fun tchapIsCrossSigningEnabled(): Boolean
fun tchapIsKeyBackupEnabled(): Boolean
fun tchapIsThreadEnabled(): Boolean
Expand Down Expand Up @@ -55,9 +56,13 @@ interface VectorFeatures {
}

class DefaultVectorFeatures @Inject constructor(
private val stringArrayProvider: StringArrayProvider,
private val booleanProvider: BooleanProvider
) : VectorFeatures {
override fun tchapIsVoipSupported() = booleanProvider.getBoolean(R.bool.tchap_is_voip_supported)
override fun tchapIsVoipSupported(homeServerUrl: String) = booleanProvider.getBoolean(R.bool.tchap_is_voip_supported) &&
stringArrayProvider.getStringArray(R.array.tchap_is_voip_supported_homeservers).let { homeServerUrls ->
homeServerUrls.isEmpty() || homeServerUrls.any { homeServerUrl.contains(it) }
}
override fun tchapIsCrossSigningEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_cross_signing_enabled)
override fun tchapIsKeyBackupEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_key_backup_enabled)
override fun tchapIsThreadEnabled() = booleanProvider.getBoolean(R.bool.tchap_is_thread_enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ class TimelineViewModel @AssistedInject constructor(
R.id.invite -> state.canInvite
R.id.open_matrix_apps -> false // Tchap: there are no matrix apps
// Tchap: check if voip is enabled
R.id.video_call -> vectorPreferences.developerMode() && vectorFeatures.tchapIsVoipSupported()
R.id.voice_call -> (session.sessionParams.homeServerUrl.contains("agent.dinum.tchap.gouv.fr") || vectorPreferences.developerMode()) &&
vectorFeatures.tchapIsVoipSupported() && (state.isCallOptionAvailable() || state.hasActiveElementCallWidget())
R.id.video_call -> vectorPreferences.developerMode() && vectorFeatures.tchapIsVoipSupported(session.sessionParams.homeServerUrl)
R.id.voice_call -> vectorFeatures.tchapIsVoipSupported(session.sessionParams.homeServerUrl) &&
(state.isCallOptionAvailable() || state.hasActiveElementCallWidget())
// Show Join conference button only if there is an active conf id not joined. Otherwise fallback to default video disabled. ^
R.id.join_conference -> vectorFeatures.tchapIsVoipSupported() && !state.isCallOptionAvailable() &&
R.id.join_conference -> vectorFeatures.tchapIsVoipSupported(session.sessionParams.homeServerUrl) && !state.isCallOptionAvailable() &&
state.jitsiState.confId != null && !state.jitsiState.hasJoined
R.id.search -> state.isSearchAvailable()
R.id.menu_timeline_thread_list -> vectorPreferences.areThreadMessagesEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CallItemFactory @Inject constructor(
val userOfInterest = roomSummary.toMatrixItem()
val attributes = messageItemAttributesFactory.create(null, informationData, callback, reactionsSummaryEvents).let {
CallTileTimelineItem.Attributes(
isVoipSupported = vectorFeatures.tchapIsVoipSupported(),
isVoipSupported = vectorFeatures.tchapIsVoipSupported(session.sessionParams.homeServerUrl),
callId = callId,
callKind = callKind,
callStatus = callStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.JitsiWidgetEvents
import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory
import im.vector.app.features.home.room.detail.timeline.item.CallTileTimelineItem
import im.vector.app.features.home.room.detail.timeline.item.CallTileTimelineItem_
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.widgets.model.WidgetContent
import org.matrix.android.sdk.api.session.widgets.model.WidgetType
Expand All @@ -34,6 +35,7 @@ import javax.inject.Inject

class WidgetItemFactory @Inject constructor(
private val vectorFeatures: VectorFeatures,
private val session: Session,
private val informationDataFactory: MessageInformationDataFactory,
private val noticeItemFactory: NoticeItemFactory,
private val avatarSizeProvider: AvatarSizeProvider,
Expand Down Expand Up @@ -78,7 +80,7 @@ class WidgetItemFactory @Inject constructor(
CallTileTimelineItem.CallStatus.ENDED
}
val attributes = CallTileTimelineItem.Attributes(
isVoipSupported = vectorFeatures.tchapIsVoipSupported(),
isVoipSupported = vectorFeatures.tchapIsVoipSupported(session.sessionParams.homeServerUrl),
callId = jitsiWidgetEventsGroup.callId,
callKind = CallTileTimelineItem.CallKind.CONFERENCE,
callStatus = callStatus,
Expand Down

0 comments on commit 013666e

Please sign in to comment.