From 06cc2f527e61d6d0153dab17ba7e546c29a66878 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 2 Jun 2020 19:02:21 +0200 Subject: [PATCH] Clean after Benoit's review --- .../IntegrationManagerConfig.kt | 15 +++++ .../IntegrationManagerService.kt | 61 +++++++++++++++++- .../widgets/WidgetManagementFailure.kt | 2 +- .../api/session/widgets/WidgetService.kt | 63 +++++++++++++++++++ .../api/session/widgets/WidgetURLFormatter.kt | 6 ++ .../api/session/widgets/model/WidgetType.kt | 26 ++++---- .../database/mapper/AccountDataMapper.kt | 2 +- .../DefaultGetHomeServerCapabilitiesTask.kt | 13 +++- .../AllowedWidgetsContent.kt | 2 +- .../DefaultIntegrationManagerService.kt | 4 +- .../integrationmanager/IntegrationManager.kt | 22 +------ .../IntegrationManagerModule.kt | 2 +- .../IntegrationManagerWidgetData.kt | 2 +- .../IntegrationProvisioningContent.kt | 2 +- .../internal/session/room/DefaultRoom.kt | 1 + .../room/send/LocalEchoEventFactory.kt | 2 +- .../session/room/state/DefaultStateService.kt | 1 + .../session/room/state/SendStateTask.kt | 2 +- .../session/widgets/RegisterWidgetResponse.kt | 2 +- .../internal/session/widgets/WidgetManager.kt | 1 + .../internal/session/widgets/WidgetModule.kt | 6 +- .../widgets/WidgetPostMessageAPIProvider.kt | 2 +- .../internal/session/widgets/WidgetsAPI.kt | 2 +- .../widgets/token/GetScalarTokenTask.kt | 2 +- .../vector/riotx/core/di/ScreenComponent.kt | 2 +- .../home/room/detail/RoomDetailFragment.kt | 5 +- .../home/room/detail/RoomDetailViewState.kt | 1 - .../home/room/detail/widget/RoomWidgetItem.kt | 6 +- .../features/widgets/WidgetAPICallback.kt | 2 - .../riotx/features/widgets/WidgetActivity.kt | 8 ++- .../riotx/features/widgets/WidgetViewModel.kt | 2 +- .../RoomWidgetPermissionBottomSheet.kt | 26 +++----- .../bottom_sheet_room_widget_permission.xml | 25 ++++---- .../main/res/layout/fragment_room_widget.xml | 2 +- .../main/res/xml/vector_settings_general.xml | 1 + 35 files changed, 225 insertions(+), 98 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/{internal => api}/session/widgets/WidgetManagementFailure.kt (94%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerConfig.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerConfig.kt index 14942f6d58..6bc3d9a853 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerConfig.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerConfig.kt @@ -15,6 +15,9 @@ */ package im.vector.matrix.android.api.session.integrationmanager +/** + * This class holds configuration of integration manager. + */ data class IntegrationManagerConfig( val uiUrl: String, val apiUrl: String, @@ -22,9 +25,21 @@ data class IntegrationManagerConfig( ) { // Order matters, first is preferred + /** + * The kind of config, it will reflect where the data is coming from. + */ enum class Kind { + /** + * Defined in UserAccountData + */ ACCOUNT, + /** + * Defined in Wellknown + */ HOMESERVER, + /** + * Fallback value, hardcoded by the SDK + */ DEFAULT } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerService.kt index 259dca9b10..b5b34e2f30 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/integrationmanager/IntegrationManagerService.kt @@ -19,39 +19,98 @@ package im.vector.matrix.android.api.session.integrationmanager import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.util.Cancelable +/** + * This is the entry point to manage integration. You can grab an instance of this service through an active session. + */ interface IntegrationManagerService { + /** + * This listener allow you to observe change related to integrations. + */ interface Listener { + /** + * Is called whenever integration is enabled or disabled, comes from user account data. + */ fun onIsEnabledChanged(enabled: Boolean) { // No-op } + /** + * Is called whenever configs from user account data or wellknown are updated. + */ fun onConfigurationChanged(configs: List) { // No-op } + /** + * Is called whenever widget permissions from user account data are updated. + */ fun onWidgetPermissionsChanged(widgets: Map) { // No-op } } + /** + * Adds a listener to observe changes. + */ fun addListener(listener: Listener) + /** + * Removes a previously added listener. + */ fun removeListener(listener: Listener) + /** + * Return the list of current configurations, sorted by kind. First one is preferred. + * See [IntegrationManagerConfig.Kind] + */ fun getOrderedConfigs(): List + /** + * Return the preferred current configuration. + * See [IntegrationManagerConfig.Kind] + */ fun getPreferredConfig(): IntegrationManagerConfig + /** + * Returns true if integration is enabled, false otherwise. + */ fun isIntegrationEnabled(): Boolean + /** + * Offers to enable or disable the integration. + * @param enable the param to change + * @param callback the matrix callback to listen for result. + * @return Cancelable + */ fun setIntegrationEnabled(enable: Boolean, callback: MatrixCallback): Cancelable + /** + * Offers to allow or disallow a widget. + * @param stateEventId the eventId of the state event defining the widget. + * @param allowed the param to change + * @param callback the matrix callback to listen for result. + * @return Cancelable + */ fun setWidgetAllowed(stateEventId: String, allowed: Boolean, callback: MatrixCallback): Cancelable + /** + * Returns true if the widget is allowed, false otherwise. + * @param stateEventId the eventId of the state event defining the widget. + */ fun isWidgetAllowed(stateEventId: String): Boolean + /** + * Offers to allow or disallow a native widget domain. + * @param widgetType the widget type to check for + * @param domain the domain to check for + */ fun setNativeWidgetDomainAllowed(widgetType: String, domain: String, allowed: Boolean, callback: MatrixCallback): Cancelable - fun isNativeWidgetAllowed(widgetType: String, domain: String?): Boolean + /** + * Returns true if the widget domain is allowed, false otherwise. + * @param widgetType the widget type to check for + * @param domain the domain to check for + */ + fun isNativeWidgetDomainAllowed(widgetType: String, domain: String): Boolean } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManagementFailure.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetManagementFailure.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManagementFailure.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetManagementFailure.kt index 030a8db5c9..cd3bdb57ba 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManagementFailure.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetManagementFailure.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.session.widgets +package im.vector.matrix.android.api.session.widgets import im.vector.matrix.android.api.failure.Failure diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetService.kt index 372ec1a3de..9131a3a5b6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetService.kt @@ -23,12 +23,32 @@ import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.session.widgets.model.Widget + +/** + * This is the entry point to manage widgets. You can grab an instance of this service through an active session. + */ interface WidgetService { + /** + * Returns an instance of [WidgetURLFormatter]. + */ fun getWidgetURLFormatter(): WidgetURLFormatter + /** + * Returns an instance of [WidgetPostAPIMediator]. + * This is to be used for "admin" widgets so you can interact through JS. + */ fun getWidgetPostAPIMediator(): WidgetPostAPIMediator + /** + * Returns the current room widgets defined through state events. + * Some widgets can be deactivated, so be sure to check for isActive if needed. + * + * @param roomId the room where you want to fetch widgets + * @param widgetId if you want to fetch for some particular widget + * @param widgetTypes if you want to filter some widget type. + * @param excludedTypes if you want to exclude some widget type. + */ fun getRoomWidgets( roomId: String, widgetId: QueryStringValue = QueryStringValue.NoCondition, @@ -36,6 +56,15 @@ interface WidgetService { excludedTypes: Set? = null ): List + /** + * Returns the live room widgets so you can listen to them. + * Some widgets can be deactivated, so be sure to check for isActive. + * + * @param roomId the room where you want to fetch widgets + * @param widgetId if you want to fetch for some particular widget + * @param widgetTypes if you want to filter some widget type. + * @param excludedTypes if you want to exclude some widget type. + */ fun getRoomWidgetsLive( roomId: String, widgetId: QueryStringValue = QueryStringValue.NoCondition, @@ -43,19 +72,53 @@ interface WidgetService { excludedTypes: Set? = null ): LiveData> + /** + * Returns the current user widgets. + * Some widgets can be deactivated, so be sure to check for isActive. + * + * @param widgetTypes if you want to filter some widget type. + * @param excludedTypes if you want to exclude some widget type. + */ fun getUserWidgets( widgetTypes: Set? = null, excludedTypes: Set? = null ): List + /** + * Returns the live user widgets so you can listen to them. + * Some widgets can be deactivated, so be sure to check for isActive. + * + * @param widgetTypes if you want to filter some widget type. + * @param excludedTypes if you want to exclude some widget type. + */ fun getUserWidgetsLive( widgetTypes: Set? = null, excludedTypes: Set? = null ): LiveData> + /** + * Creates a new widget in a room. It makes sure you have the rights to handle this. + * + * @param roomId: the room where you want to deactivate the widget. + * @param widgetId: the widget to deactivate. + * @param callback the matrix callback to listen for result. + * @return Cancelable + */ fun createRoomWidget(roomId: String, widgetId: String, content: Content, callback: MatrixCallback): Cancelable + /** + * Deactivate a widget in a room. It makes sure you have the rights to handle this. + * + * @param roomId: the room where you want to deactivate the widget. + * @param widgetId: the widget to deactivate. + * @param callback the matrix callback to listen for result. + * @return Cancelable + */ fun destroyRoomWidget(roomId: String, widgetId: String, callback: MatrixCallback): Cancelable + /** + * Returns true if you can add/remove widgets. It goes through + * @param roomId the room where you want to administrate widgets. + */ fun hasPermissionsToHandleWidgets(roomId: String): Boolean } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetURLFormatter.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetURLFormatter.kt index f837b2542d..f2ba40c344 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetURLFormatter.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/WidgetURLFormatter.kt @@ -20,6 +20,12 @@ interface WidgetURLFormatter { /** * Takes care of fetching a scalar token if required and build the final url. * This methods can throw, you should take care of handling failure. + * + * @param baseUrl the baseUrl which will be checked for scalar token + * @param params additional params you want to append to the base url. + * @param forceFetchScalarToken if true, you will force to fetch a new scalar token + * from the server (only if the base url is whitelisted) + * @param bypassWhitelist if true, the base url will be considered as whitelisted */ suspend fun format( baseUrl: String, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/model/WidgetType.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/model/WidgetType.kt index 86d2354cb3..4a265d71b7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/model/WidgetType.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/widgets/model/WidgetType.kt @@ -16,19 +16,19 @@ package im.vector.matrix.android.api.session.widgets.model -sealed class WidgetType(open val preferred: String, open val legacy: String) { +sealed class WidgetType(open val preferred: String, open val legacy: String = preferred) { object Jitsi : WidgetType("m.jitsi", "jitsi") - object TradingView : WidgetType("m.tradingview", "m.tradingview") - object Spotify : WidgetType("m.spotify", "m.spotify") - object Video : WidgetType("m.video", "m.video") - object GoogleDoc : WidgetType("m.googledoc", "m.googledoc") - object GoogleCalendar : WidgetType("m.googlecalendar", "m.googlecalendar") - object Etherpad : WidgetType("m.etherpad", "m.etherpad") - object StickerPicker : WidgetType("m.stickerpicker", "m.stickerpicker") - object Grafana : WidgetType("m.grafana", "m.grafana") - object Custom : WidgetType("m.custom", "m.custom") - object IntegrationManager : WidgetType("m.integration_manager", "m.integration_manager") - data class Fallback(override val preferred: String, override val legacy: String) : WidgetType(preferred, legacy) + object TradingView : WidgetType("m.tradingview") + object Spotify : WidgetType("m.spotify") + object Video : WidgetType("m.video") + object GoogleDoc : WidgetType("m.googledoc") + object GoogleCalendar : WidgetType("m.googlecalendar") + object Etherpad : WidgetType("m.etherpad") + object StickerPicker : WidgetType("m.stickerpicker") + object Grafana : WidgetType("m.grafana") + object Custom : WidgetType("m.custom") + object IntegrationManager : WidgetType("m.integration_manager") + data class Fallback(override val preferred: String) : WidgetType(preferred) fun matches(type: String?): Boolean { return type == preferred || type == legacy @@ -58,7 +58,7 @@ sealed class WidgetType(open val preferred: String, open val legacy: String) { val matchingType = DEFINED_TYPES.firstOrNull { it.matches(type) } - return matchingType ?: Fallback(type, type) + return matchingType ?: Fallback(type) } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt index ebeeb144d3..528712b731 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt @@ -29,7 +29,7 @@ internal class AccountDataMapper @Inject constructor(moshi: Moshi) { fun map(entity: UserAccountDataEntity): UserAccountDataEvent { return UserAccountDataEvent( type = entity.type ?: "", - content = entity.contentStr?.let { adapter.fromJson(it) } ?: emptyMap() + content = entity.contentStr?.let { adapter.fromJson(it) }.orEmpty() ) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt index be5b0d3949..56b9dfc294 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/homeserver/DefaultGetHomeServerCapabilitiesTask.kt @@ -21,14 +21,16 @@ import im.vector.matrix.android.api.auth.data.Versions import im.vector.matrix.android.api.auth.data.isLoginAndRegistrationSupportedBySdk import im.vector.matrix.android.api.auth.wellknown.WellknownResult import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities -import im.vector.matrix.android.internal.wellknown.GetWellknownTask import im.vector.matrix.android.internal.database.model.HomeServerCapabilitiesEntity import im.vector.matrix.android.internal.database.query.getOrCreate import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest +import im.vector.matrix.android.internal.session.integrationmanager.IntegrationManagerConfigExtractor import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.util.awaitTransaction +import im.vector.matrix.android.internal.wellknown.GetWellknownTask import org.greenrobot.eventbus.EventBus +import timber.log.Timber import java.util.Date import javax.inject.Inject @@ -39,6 +41,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( private val monarchy: Monarchy, private val eventBus: EventBus, private val getWellknownTask: GetWellknownTask, + private val configExtractor: IntegrationManagerConfigExtractor, @UserId private val userId: String ) : GetHomeServerCapabilitiesTask { @@ -102,8 +105,14 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor( if (getWellknownResult != null && getWellknownResult is WellknownResult.Prompt) { homeServerCapabilitiesEntity.defaultIdentityServerUrl = getWellknownResult.identityServerUrl - } + // We are also checking for integration manager configurations + val config = configExtractor.extract(getWellknownResult.wellKnown) + if (config != null) { + Timber.v("Extracted integration config : $config") + realm.insertOrUpdate(config) + } + } homeServerCapabilitiesEntity.lastUpdatedTimestamp = Date().time } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/AllowedWidgetsContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/AllowedWidgetsContent.kt index 0ef6fad8e7..99959f9514 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/AllowedWidgetsContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/AllowedWidgetsContent.kt @@ -20,7 +20,7 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class AllowedWidgetsContent( +internal data class AllowedWidgetsContent( /** * Map of stateEventId to Allowed */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/DefaultIntegrationManagerService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/DefaultIntegrationManagerService.kt index aad8a04aa5..4de4a24738 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/DefaultIntegrationManagerService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/DefaultIntegrationManagerService.kt @@ -60,7 +60,7 @@ internal class DefaultIntegrationManagerService @Inject constructor(private val return integrationManager.setNativeWidgetDomainAllowed(widgetType, domain, allowed, callback) } - override fun isNativeWidgetAllowed(widgetType: String, domain: String?): Boolean { - return integrationManager.isNativeWidgetAllowed(widgetType, domain) + override fun isNativeWidgetDomainAllowed(widgetType: String, domain: String): Boolean { + return integrationManager.isNativeWidgetDomainAllowed(widgetType, domain) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt index 3186b4bcd0..0e866412d7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt @@ -90,7 +90,6 @@ internal class IntegrationManager @Inject constructor(@UserId private val userId } fun start() { - refreshWellknown() lifecycleRegistry.currentState = Lifecycle.State.STARTED observeWellknownConfig() accountDataDataSource @@ -209,7 +208,7 @@ internal class IntegrationManager @Inject constructor(@UserId private val userId .executeBy(taskExecutor) } - fun isNativeWidgetAllowed(widgetType: String, domain: String?): Boolean { + fun isNativeWidgetDomainAllowed(widgetType: String, domain: String?): Boolean { val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) val currentContent = currentAllowedWidgets?.content?.toModel() return currentContent?.native?.get(widgetType)?.get(domain) ?: false @@ -273,25 +272,6 @@ internal class IntegrationManager @Inject constructor(@UserId private val userId .firstOrNull()?.widgetContent } - private fun refreshWellknown() { - taskExecutor.executorScope.launch { - val params = GetWellknownTask.Params(matrixId = userId) - val wellknownResult = try { - getWellknownTask.execute(params) - } catch (failure: Throwable) { - Timber.v("Get wellknown failed: $failure") - null - } - if (wellknownResult != null && wellknownResult is WellknownResult.Prompt) { - val config = configExtractor.extract(wellknownResult.wellKnown) ?: return@launch - Timber.v("Extracted config: $config") - monarchy.awaitTransaction { - it.insertOrUpdate(config) - } - } - } - } - private fun observeWellknownConfig() { val liveData = monarchy.findAllMappedWithChanges( { it.where(WellknownIntegrationManagerConfigEntity::class.java) }, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerModule.kt index 69ac94b47a..1c29f9c38c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerModule.kt @@ -24,5 +24,5 @@ import im.vector.matrix.android.api.session.integrationmanager.IntegrationManage internal abstract class IntegrationManagerModule { @Binds - abstract fun bindIntegrationManagerService(integrationManagerService: DefaultIntegrationManagerService): IntegrationManagerService + abstract fun bindIntegrationManagerService(service: DefaultIntegrationManagerService): IntegrationManagerService } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerWidgetData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerWidgetData.kt index a6e69319a3..1b77b21bc2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerWidgetData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManagerWidgetData.kt @@ -20,6 +20,6 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class IntegrationManagerWidgetData( +internal data class IntegrationManagerWidgetData( @Json(name = "api_url") val apiUrl: String? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationProvisioningContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationProvisioningContent.kt index 55c93b6ec7..51485df762 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationProvisioningContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationProvisioningContent.kt @@ -20,6 +20,6 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class IntegrationProvisioningContent( +internal data class IntegrationProvisioningContent( @Json(name = "enabled") val enabled: Boolean ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt index a441d70f5d..575b040ffe 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt @@ -118,6 +118,7 @@ internal class DefaultRoom @Inject constructor(override val roomId: String, else -> { val params = SendStateTask.Params( roomId = roomId, + stateKey = null, eventType = EventType.STATE_ROOM_ENCRYPTION, body = mapOf( "algorithm" to algorithm diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index ae7c20ec35..9f95696fba 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -346,7 +346,7 @@ internal class LocalEchoEventFactory @Inject constructor( return createMessageEvent(roomId, content) } - private fun createMessageEvent(roomId: String, content: Any? = null): Event { + private fun createMessageEvent(roomId: String, content: MessageContent? = null): Event { return createEvent(roomId, EventType.MESSAGE, content.toContent()) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt index f9f8d5e6b9..6646f08c2d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/DefaultStateService.kt @@ -65,6 +65,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private ): Cancelable { val params = SendStateTask.Params( roomId = roomId, + stateKey = stateKey, eventType = eventType, body = body ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt index d632ca4126..5c1cddc2e7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/state/SendStateTask.kt @@ -26,7 +26,7 @@ import javax.inject.Inject internal interface SendStateTask : Task { data class Params( val roomId: String, - val stateKey: String? = null, + val stateKey: String?, val eventType: String, val body: JsonDict ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/RegisterWidgetResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/RegisterWidgetResponse.kt index d84e36ce95..af62525822 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/RegisterWidgetResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/RegisterWidgetResponse.kt @@ -20,6 +20,6 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class RegisterWidgetResponse( +internal data class RegisterWidgetResponse( @Json(name = "scalar_token") val scalarToken: String? ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManager.kt index eefdff8004..3c9985de1b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetManager.kt @@ -30,6 +30,7 @@ import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerService import im.vector.matrix.android.api.session.room.model.PowerLevelsContent import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper +import im.vector.matrix.android.api.session.widgets.WidgetManagementFailure import im.vector.matrix.android.api.session.widgets.model.Widget import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.internal.di.UserId diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetModule.kt index fdb744ec67..79c2ac0dbb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetModule.kt @@ -39,13 +39,13 @@ internal abstract class WidgetModule { } @Binds - abstract fun bindWidgetService(widgetService: DefaultWidgetService): WidgetService + abstract fun bindWidgetService(service: DefaultWidgetService): WidgetService @Binds - abstract fun bindWidgetURLBuilder(widgetURLBuilder: DefaultWidgetURLFormatter): WidgetURLFormatter + abstract fun bindWidgetURLBuilder(formatter: DefaultWidgetURLFormatter): WidgetURLFormatter @Binds - abstract fun bindWidgetPostAPIMediator(widgetPostMessageAPIProvider: DefaultWidgetPostAPIMediator): WidgetPostAPIMediator + abstract fun bindWidgetPostAPIMediator(mediator: DefaultWidgetPostAPIMediator): WidgetPostAPIMediator @Binds abstract fun bindCreateWidgetTask(task: DefaultCreateWidgetTask): CreateWidgetTask diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetPostMessageAPIProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetPostMessageAPIProvider.kt index e33b4cdcb8..4f34960f4b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetPostMessageAPIProvider.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetPostMessageAPIProvider.kt @@ -20,7 +20,7 @@ import android.content.Context import timber.log.Timber import javax.inject.Inject -class WidgetPostMessageAPIProvider @Inject constructor(private val context: Context) { +internal class WidgetPostMessageAPIProvider @Inject constructor(private val context: Context) { private var postMessageAPIString: String? = null diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetsAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetsAPI.kt index da9992d971..922234a0b1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetsAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetsAPI.kt @@ -30,7 +30,7 @@ internal interface WidgetsAPI { * @param requestOpenIdTokenResponse the body content (Ref: https://github.com/matrix-org/matrix-doc/pull/1961) */ @POST("register") - fun register(@Body requestOpenIdTokenResponse: RequestOpenIdTokenResponse, @Query("v") version: String?): Call + fun register(@Body body: RequestOpenIdTokenResponse, @Query("v") version: String?): Call @GET("account") fun validateToken(@Query("scalar_token") scalarToken: String?, @Query("v") version: String?): Call diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/token/GetScalarTokenTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/token/GetScalarTokenTask.kt index bba0ede13e..f6d1ecb23b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/token/GetScalarTokenTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/token/GetScalarTokenTask.kt @@ -21,7 +21,7 @@ import im.vector.matrix.android.api.failure.MatrixError import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.openid.GetOpenIdTokenTask import im.vector.matrix.android.internal.session.widgets.RegisterWidgetResponse -import im.vector.matrix.android.internal.session.widgets.WidgetManagementFailure +import im.vector.matrix.android.api.session.widgets.WidgetManagementFailure import im.vector.matrix.android.internal.session.widgets.WidgetsAPI import im.vector.matrix.android.internal.session.widgets.WidgetsAPIProvider import im.vector.matrix.android.internal.task.Task diff --git a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt index 532b42cad1..c5dc67e38d 100644 --- a/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt +++ b/vector/src/main/java/im/vector/riotx/core/di/ScreenComponent.kt @@ -123,7 +123,7 @@ interface ScreenComponent { fun inject(activity: BigImageViewerActivity) fun inject(activity: InviteUsersToRoomActivity) fun inject(activity: ReviewTermsActivity) - fun inject(widgetActivity: WidgetActivity) + fun inject(activity: WidgetActivity) /* ========================================================================================== * BottomSheets diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 6058fe9ec6..a77969c44b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -202,7 +202,8 @@ class RoomDetailFragment @Inject constructor( VectorInviteView.Callback, JumpToReadMarkerView.Callback, AttachmentTypeSelectorView.Callback, - AttachmentsHelper.Callback, RoomWidgetsBannerView.Callback { + AttachmentsHelper.Callback, + RoomWidgetsBannerView.Callback { companion object { @@ -327,8 +328,6 @@ class RoomDetailFragment @Inject constructor( private fun displayPromptForIntegrationManager() { // The Sticker picker widget is not installed yet. Propose the user to install it val builder = AlertDialog.Builder(requireContext()) - // Use the builder context - // Use the builder context val v: View = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_no_sticker_pack, null) builder .setView(v) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt index 3079059b8f..51d7108a9a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewState.kt @@ -66,7 +66,6 @@ data class RoomDetailViewState( val syncState: SyncState = SyncState.Idle, val highlightedEventId: String? = null, val unreadState: UnreadState = UnreadState.Unknown, - val menuItemsVisibility: SparseArray = SparseArray(4), val canShowJumpToReadMarker: Boolean = true ) : MvRxState { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/widget/RoomWidgetItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/widget/RoomWidgetItem.kt index f6dd2ab361..8b7d32bb99 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/widget/RoomWidgetItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/widget/RoomWidgetItem.kt @@ -22,17 +22,19 @@ import com.airbnb.epoxy.EpoxyModelClass import com.airbnb.epoxy.EpoxyModelWithHolder import im.vector.matrix.android.api.session.widgets.model.Widget import im.vector.riotx.R +import im.vector.riotx.core.epoxy.ClickListener import im.vector.riotx.core.epoxy.VectorEpoxyHolder +import im.vector.riotx.core.epoxy.onClick @EpoxyModelClass(layout = R.layout.item_room_widget) abstract class RoomWidgetItem : EpoxyModelWithHolder() { @EpoxyAttribute lateinit var widget: Widget - @EpoxyAttribute var widgetClicked: (() -> Unit)? = null + @EpoxyAttribute var widgetClicked: ClickListener? = null override fun bind(holder: Holder) { holder.widgetName.text = widget.name - holder.view.setOnClickListener { widgetClicked?.invoke() } + holder.view.onClick(widgetClicked) } class Holder : VectorEpoxyHolder() { diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetAPICallback.kt b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetAPICallback.kt index 88f379dd5f..3549ce979c 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetAPICallback.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetAPICallback.kt @@ -27,12 +27,10 @@ class WidgetAPICallback(private val postAPIMediator: WidgetPostAPIMediator, private val stringProvider: StringProvider) : MatrixCallback { override fun onFailure(failure: Throwable) { - super.onFailure(failure) postAPIMediator.sendError(stringProvider.getString(R.string.widget_integration_failed_to_send_request), eventData) } override fun onSuccess(data: Any) { - super.onSuccess(data) postAPIMediator.sendSuccess(eventData) } } diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetActivity.kt b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetActivity.kt index c750e0774a..a8153a65d8 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetActivity.kt @@ -80,9 +80,11 @@ class WidgetActivity : VectorBaseActivity(), ToolbarConfigurable, WidgetViewMode } override fun initUiAndData() { - val widgetArgs: WidgetArgs = intent?.extras?.getParcelable(MvRx.KEY_ARG) - ?: return - + val widgetArgs: WidgetArgs? = intent?.extras?.getParcelable(MvRx.KEY_ARG) + if (widgetArgs == null) { + finish() + return + } configure(toolbar) toolbar.isVisible = widgetArgs.kind.nameRes != 0 viewModel.observeViewEvents { diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetViewModel.kt b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetViewModel.kt index 1a7ca0c885..a503387f05 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetViewModel.kt @@ -34,7 +34,7 @@ import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerService import im.vector.matrix.android.api.session.room.model.PowerLevelsContent import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper -import im.vector.matrix.android.internal.session.widgets.WidgetManagementFailure +import im.vector.matrix.android.api.session.widgets.WidgetManagementFailure import im.vector.matrix.android.internal.util.awaitCallback import im.vector.matrix.rx.mapOptional import im.vector.matrix.rx.rx diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt index 4fcc0d7472..2cff3b555d 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/permissions/RoomWidgetPermissionBottomSheet.kt @@ -34,6 +34,7 @@ import im.vector.riotx.core.extensions.withArgs import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.riotx.features.home.AvatarRenderer import im.vector.riotx.features.widgets.WidgetArgs +import kotlinx.android.synthetic.main.bottom_sheet_room_widget_permission.* import javax.inject.Inject class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() { @@ -42,18 +43,6 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() { private val viewModel: RoomWidgetPermissionViewModel by activityViewModel() - @BindView(R.id.bottom_sheet_widget_permission_shared_info) - lateinit var sharedInfoTextView: TextView - - @BindView(R.id.bottom_sheet_widget_permission_owner_id) - lateinit var authorIdText: TextView - - @BindView(R.id.bottom_sheet_widget_permission_owner_display_name) - lateinit var authorNameText: TextView - - @BindView(R.id.bottom_sheet_widget_permission_owner_avatar) - lateinit var authorAvatarView: ImageView - @Inject lateinit var avatarRenderer: AvatarRenderer override val showExpanded = true @@ -65,10 +54,10 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() { override fun invalidate() = withState(viewModel) { state -> super.invalidate() val permissionData = state.permissionData() ?: return@withState - authorIdText.text = permissionData.widget.senderInfo?.userId ?: "" - authorNameText.text = permissionData.widget.senderInfo?.disambiguatedDisplayName + widgetPermissionOwnerId.text = permissionData.widget.senderInfo?.userId ?: "" + widgetPermissionOwnerDisplayName.text = permissionData.widget.senderInfo?.disambiguatedDisplayName permissionData.widget.senderInfo?.toMatrixItem()?.also { - avatarRenderer.render(it, authorAvatarView) + avatarRenderer.render(it, widgetPermissionOwnerAvatar) } val domain = permissionData.widgetDomain ?: "" @@ -96,18 +85,17 @@ class RoomWidgetPermissionBottomSheet : VectorBaseBottomSheetDialogFragment() { } } infoBuilder.append("\n") - - sharedInfoTextView.text = infoBuilder + widgetPermissionSharedInfo.text = infoBuilder } - @OnClick(R.id.bottom_sheet_widget_permission_decline_button) + @OnClick(R.id.widgetPermissionDecline) fun doDecline() { viewModel.handle(RoomWidgetPermissionActions.BlockWidget) // optimistic dismiss dismiss() } - @OnClick(R.id.bottom_sheet_widget_permission_continue_button) + @OnClick(R.id.widgetPermissionContinue) fun doAccept() { viewModel.handle(RoomWidgetPermissionActions.AllowWidget) // optimistic dismiss diff --git a/vector/src/main/res/layout/bottom_sheet_room_widget_permission.xml b/vector/src/main/res/layout/bottom_sheet_room_widget_permission.xml index 1bbf539656..1aa77a6c3b 100644 --- a/vector/src/main/res/layout/bottom_sheet_room_widget_permission.xml +++ b/vector/src/main/res/layout/bottom_sheet_room_widget_permission.xml @@ -17,17 +17,18 @@ android:layout_marginBottom="8dp" android:text="@string/room_widget_permission_title" android:textSize="20sp" + android:textColor="?riotx_text_primary" android:textStyle="bold" /> @@ -91,16 +94,16 @@ android:gravity="end" android:orientation="horizontal"> -