diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt index 930e41e0d9..024d84f27b 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt @@ -21,12 +21,15 @@ import android.view.MenuItem import android.widget.Toast import androidx.core.view.isVisible import androidx.core.widget.doOnTextChanged +import com.airbnb.mvrx.viewModel +import com.airbnb.mvrx.withState import im.vector.app.R import im.vector.app.core.di.ScreenComponent import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityBugReportBinding import timber.log.Timber +import javax.inject.Inject /** * Form to send a bug report @@ -39,6 +42,10 @@ class BugReportActivity : VectorBaseActivity() { override fun getBinding() = ActivityBugReportBinding.inflate(layoutInflater) + @Inject lateinit var bugReportViewModelFactory: BugReportViewModel.Factory + + private val viewModel: BugReportViewModel by viewModel() + private var forSuggestion: Boolean = false override fun initUiAndData() { @@ -114,7 +121,7 @@ class BugReportActivity : VectorBaseActivity() { /** * Send the bug report */ - private fun sendBugReport() { + private fun sendBugReport() = withState(viewModel) { state -> views.bugReportScrollview.alpha = 0.3f views.bugReportMaskView.isVisible = true @@ -133,6 +140,7 @@ class BugReportActivity : VectorBaseActivity() { views.bugReportButtonIncludeKeyShareHistory.isChecked, views.bugReportButtonIncludeScreenshot.isChecked, views.bugReportEditText.text.toString(), + state.serverVersion, object : BugReporter.IMXBugReportListener { override fun onUploadFailed(reason: String?) { try { diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportState.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportState.kt new file mode 100644 index 0000000000..1dc316a5e2 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportState.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.rageshake + +import com.airbnb.mvrx.MvRxState + +data class BugReportState( + val serverVersion: String = "" +) : MvRxState + diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportViewModel.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportViewModel.kt new file mode 100644 index 0000000000..c71a89553e --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportViewModel.kt @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.rageshake + +import androidx.lifecycle.viewModelScope +import com.airbnb.mvrx.ActivityViewModelContext +import com.airbnb.mvrx.MvRxViewModelFactory +import com.airbnb.mvrx.ViewModelContext +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.platform.EmptyAction +import im.vector.app.core.platform.EmptyViewEvents +import im.vector.app.core.platform.VectorViewModel +import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.extensions.tryOrNull + +class BugReportViewModel @AssistedInject constructor( + @Assisted initialState: BugReportState, + val activeSessionHolder: ActiveSessionHolder +) : VectorViewModel(initialState) { + + @AssistedFactory + interface Factory { + fun create(initialState: BugReportState): BugReportViewModel + } + + companion object : MvRxViewModelFactory { + + @JvmStatic + override fun create(viewModelContext: ViewModelContext, state: BugReportState): BugReportViewModel? { + val activity: BugReportActivity = (viewModelContext as ActivityViewModelContext).activity() + return activity.bugReportViewModelFactory.create(state) + } + } + + init { + fetchHomeserverVersion() + } + + private fun fetchHomeserverVersion() { + viewModelScope.launch { + val version = tryOrNull { + activeSessionHolder.getSafeActiveSession() + ?.federationService() + ?.getFederationVersion() + ?.let { "${it.name} - ${it.version}" } + } ?: "undefined" + + setState { + copy( + serverVersion = version + ) + } + } + } + + override fun handle(action: EmptyAction) { + // No op + } +} diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt index a43aca488d..15fd18039b 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt @@ -165,6 +165,7 @@ class BugReporter @Inject constructor( withKeyRequestHistory: Boolean, withScreenshot: Boolean, theBugDescription: String, + serverVersion: String, listener: IMXBugReportListener?) { // enumerate files to delete val mBugReportFiles: MutableList = ArrayList() @@ -273,6 +274,7 @@ class BugReporter @Inject constructor( .addFormDataPart("app_language", VectorLocale.applicationLocale.toString()) .addFormDataPart("default_app_language", systemLocaleProvider.getSystemLocale().toString()) .addFormDataPart("theme", ThemeUtils.getApplicationTheme(context)) + .addFormDataPart("server_version", serverVersion) val buildNumber = context.getString(R.string.build_number) if (buildNumber.isNotEmpty() && buildNumber != "0") {