Merge branch 'develop' into feature/bma/consent

This commit is contained in:
Benoit Marty 2020-11-16 13:43:02 +01:00 committed by GitHub
commit 4c6996bc09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 229 additions and 102 deletions

View file

@ -7,11 +7,13 @@ Features ✨:
Improvements 🙌:
- Open an existing DM instead of creating a new one (#2319)
- Ask for explicit user consent to send their contact details to the identity server (#2375)
- Handle events of type "m.room.server_acl" (#890)
Bugfix 🐛:
- Fix issue when restoring draft after sharing (#2287)
- Fix issue when updating the avatar of a room (new avatar vanishing)
- Discard change dialog displayed by mistake when avatar has been updated
- Registration: annoying error message scares every new user when they add an email (#2391)
Translations 🗣:
-

View file

@ -68,8 +68,8 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
if (encryptedRoom) {
val room = aliceSession.getRoom(roomId)!!
mTestHelper.doSync<Unit> {
room.enableEncryption(callback = it)
mTestHelper.runBlockingTest {
room.enableEncryption()
}
}

View file

@ -22,3 +22,8 @@ fun CharSequence.ensurePrefix(prefix: CharSequence): CharSequence {
else -> "$prefix$this"
}
}
/**
* Append a new line and then the provided string
*/
fun StringBuilder.appendNl(str: String) = append("\n").append(str)

View file

@ -56,6 +56,7 @@ object EventType {
const val STATE_ROOM_RELATED_GROUPS = "m.room.related_groups"
const val STATE_ROOM_PINNED_EVENT = "m.room.pinned_events"
const val STATE_ROOM_ENCRYPTION = "m.room.encryption"
const val STATE_ROOM_SERVER_ACL = "m.room.server_acl"
// Call Events
const val CALL_INVITE = "m.call.invite"

View file

@ -16,7 +16,6 @@
package org.matrix.android.sdk.api.session.room.crypto
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
interface RoomCryptoService {
@ -30,6 +29,5 @@ interface RoomCryptoService {
/**
* Enable encryption of the room
*/
fun enableEncryption(algorithm: String = MXCRYPTO_ALGORITHM_MEGOLM,
callback: MatrixCallback<Unit>)
suspend fun enableEncryption(algorithm: String = MXCRYPTO_ALGORITHM_MEGOLM)
}

View file

@ -0,0 +1,59 @@
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* 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 org.matrix.android.sdk.api.session.room.model
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* Class representing the EventType.STATE_ROOM_SERVER_ACL state event content
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-server-acl
*/
@JsonClass(generateAdapter = true)
data class RoomServerAclContent(
/**
* True to allow server names that are IP address literals. False to deny.
* Defaults to true if missing or otherwise not a boolean.
* This is strongly recommended to be set to false as servers running with IP literal names are strongly
* discouraged in order to require legitimate homeservers to be backed by a valid registered domain name.
*/
@Json(name = "allow_ip_literals")
val allowIpLiterals: Boolean = true,
/**
* The server names to allow in the room, excluding any port information. Wildcards may be used to cover
* a wider range of hosts, where * matches zero or more characters and ? matches exactly one character.
*
* This defaults to an empty list when not provided, effectively disallowing every server.
*/
@Json(name = "allow")
val allowList: List<String> = emptyList(),
/**
* The server names to disallow in the room, excluding any port information. Wildcards may be used to cover
* a wider range of hosts, where * matches zero or more characters and ? matches exactly one character.
*
* This defaults to an empty list when not provided.
*/
@Json(name = "deny")
val denyList: List<String> = emptyList()
) {
companion object {
const val ALL = "*"
}
}

View file

@ -17,12 +17,10 @@
package org.matrix.android.sdk.api.session.room.notification
import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable
interface RoomPushRuleService {
fun getLiveRoomNotificationState(): LiveData<RoomNotificationState>
fun setRoomNotificationState(roomNotificationState: RoomNotificationState, matrixCallback: MatrixCallback<Unit>): Cancelable
suspend fun setRoomNotificationState(roomNotificationState: RoomNotificationState)
}

View file

@ -16,9 +16,6 @@
package org.matrix.android.sdk.api.session.room.reporting
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable
/**
* This interface defines methods to report content of an event.
*/
@ -28,5 +25,5 @@ interface ReportingService {
* Report content
* Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
*/
fun reportContent(eventId: String, score: Int, reason: String, callback: MatrixCallback<Unit>): Cancelable
suspend fun reportContent(eventId: String, score: Int, reason: String)
}

View file

@ -16,9 +16,6 @@
package org.matrix.android.sdk.api.session.room.tags
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable
/**
* This interface defines methods to handle tags of a room. It's implemented at the room level.
*/
@ -26,10 +23,10 @@ interface TagsService {
/**
* Add a tag to a room
*/
fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable
suspend fun addTag(tag: String, order: Double?)
/**
* Remove tag from a room
*/
fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable
suspend fun deleteTag(tag: String)
}

View file

@ -101,13 +101,13 @@ internal class DefaultRoom @Inject constructor(override val roomId: String,
return cryptoService.shouldEncryptForInvitedMembers(roomId)
}
override fun enableEncryption(algorithm: String, callback: MatrixCallback<Unit>) {
override suspend fun enableEncryption(algorithm: String) {
when {
isEncrypted() -> {
callback.onFailure(IllegalStateException("Encryption is already enabled for this room"))
throw IllegalStateException("Encryption is already enabled for this room")
}
algorithm != MXCRYPTO_ALGORITHM_MEGOLM -> {
callback.onFailure(InvalidParameterException("Only MXCRYPTO_ALGORITHM_MEGOLM algorithm is supported"))
throw InvalidParameterException("Only MXCRYPTO_ALGORITHM_MEGOLM algorithm is supported")
}
else -> {
val params = SendStateTask.Params(
@ -118,11 +118,7 @@ internal class DefaultRoom @Inject constructor(override val roomId: String,
"algorithm" to algorithm
))
sendStateTask
.configureWith(params) {
this.callback = callback
}
.executeBy(taskExecutor)
sendStateTask.execute(params)
}
}
}

View file

@ -21,21 +21,16 @@ import androidx.lifecycle.Transformations
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.pushrules.RuleScope
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
import org.matrix.android.sdk.api.session.room.notification.RoomPushRuleService
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.internal.database.model.PushRuleEntity
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
internal class DefaultRoomPushRuleService @AssistedInject constructor(@Assisted private val roomId: String,
private val setRoomNotificationStateTask: SetRoomNotificationStateTask,
@SessionDatabase private val monarchy: Monarchy,
private val taskExecutor: TaskExecutor)
@SessionDatabase private val monarchy: Monarchy)
: RoomPushRuleService {
@AssistedInject.Factory
@ -49,12 +44,8 @@ internal class DefaultRoomPushRuleService @AssistedInject constructor(@Assisted
}
}
override fun setRoomNotificationState(roomNotificationState: RoomNotificationState, matrixCallback: MatrixCallback<Unit>): Cancelable {
return setRoomNotificationStateTask
.configureWith(SetRoomNotificationStateTask.Params(roomId, roomNotificationState)) {
this.callback = matrixCallback
}
.executeBy(taskExecutor)
override suspend fun setRoomNotificationState(roomNotificationState: RoomNotificationState) {
setRoomNotificationStateTask.execute(SetRoomNotificationStateTask.Params(roomId, roomNotificationState))
}
private fun getPushRuleForRoom(): LiveData<RoomPushRule?> {

View file

@ -18,14 +18,9 @@ package org.matrix.android.sdk.internal.session.room.reporting
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.room.reporting.ReportingService
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
internal class DefaultReportingService @AssistedInject constructor(@Assisted private val roomId: String,
private val taskExecutor: TaskExecutor,
private val reportContentTask: ReportContentTask
) : ReportingService {
@ -34,13 +29,8 @@ internal class DefaultReportingService @AssistedInject constructor(@Assisted pri
fun create(roomId: String): ReportingService
}
override fun reportContent(eventId: String, score: Int, reason: String, callback: MatrixCallback<Unit>): Cancelable {
override suspend fun reportContent(eventId: String, score: Int, reason: String) {
val params = ReportContentTask.Params(roomId, eventId, score, reason)
return reportContentTask
.configureWith(params) {
this.callback = callback
}
.executeBy(taskExecutor)
reportContentTask.execute(params)
}
}

View file

@ -18,15 +18,10 @@ package org.matrix.android.sdk.internal.session.room.tags
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.room.tags.TagsService
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
internal class DefaultTagsService @AssistedInject constructor(
@Assisted private val roomId: String,
private val taskExecutor: TaskExecutor,
private val addTagToRoomTask: AddTagToRoomTask,
private val deleteTagFromRoomTask: DeleteTagFromRoomTask
) : TagsService {
@ -36,21 +31,13 @@ internal class DefaultTagsService @AssistedInject constructor(
fun create(roomId: String): TagsService
}
override fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable {
override suspend fun addTag(tag: String, order: Double?) {
val params = AddTagToRoomTask.Params(roomId, tag, order)
return addTagToRoomTask
.configureWith(params) {
this.callback = callback
}
.executeBy(taskExecutor)
addTagToRoomTask.execute(params)
}
override fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable {
override suspend fun deleteTag(tag: String) {
val params = DeleteTagFromRoomTask.Params(roomId, tag)
return deleteTagFromRoomTask
.configureWith(params) {
this.callback = callback
}
.executeBy(taskExecutor)
deleteTagFromRoomTask.execute(params)
}
}

View file

@ -72,6 +72,23 @@
<string name="notice_room_update_by_you">You upgraded this room.</string>
<string name="notice_direct_room_update">%s upgraded here.</string>
<string name="notice_direct_room_update_by_you">You upgraded here.</string>
<string name="notice_room_server_acl_set_title">%s set the server ACLs for this room.</string>
<string name="notice_room_server_acl_set_title_by_you">You set the server ACLs for this room.</string>
<string name="notice_room_server_acl_set_banned">• Server matching %s are banned.</string>
<string name="notice_room_server_acl_set_allowed">• Server matching %s are allowed.</string>
<string name="notice_room_server_acl_set_ip_literals_allowed">• Server matching IP literals are allowed.</string>
<string name="notice_room_server_acl_set_ip_literals_not_allowed">• Server matching IP literals are banned.</string>
<string name="notice_room_server_acl_updated_title">%s changed the server ACLs for this room.</string>
<string name="notice_room_server_acl_updated_title_by_you">You changed the server ACLs for this room.</string>
<string name="notice_room_server_acl_updated_banned">• Server matching %s are now banned.</string>
<string name="notice_room_server_acl_updated_was_banned">• Server matching %s were removed from the ban list.</string>
<string name="notice_room_server_acl_updated_allowed">• Server matching %s are now allowed.</string>
<string name="notice_room_server_acl_updated_was_allowed">• Server matching %s were removed from the allowed list.</string>
<string name="notice_room_server_acl_updated_ip_literals_allowed">• Server matching IP literals are now allowed.</string>
<string name="notice_room_server_acl_updated_ip_literals_not_allowed">• Server matching IP literals are now banned.</string>
<string name="notice_room_server_acl_updated_no_change">No change.</string>
<string name="notice_room_server_acl_allow_is_empty">🎉 All servers are banned from participating! This room can no longer be used.</string>
<string name="notice_requested_voip_conference">%1$s requested a VoIP conference</string>
<string name="notice_requested_voip_conference_by_you">You requested a VoIP conference</string>

View file

@ -99,6 +99,7 @@ import org.matrix.android.sdk.rx.rx
import org.matrix.android.sdk.rx.unwrap
import timber.log.Timber
import java.io.File
import java.lang.Exception
import java.util.UUID
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
@ -1112,15 +1113,15 @@ class RoomDetailViewModel @AssistedInject constructor(
}
private fun handleReportContent(action: RoomDetailAction.ReportContent) {
room.reportContent(action.eventId, -100, action.reason, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
_viewEvents.post(RoomDetailViewEvents.ActionSuccess(action))
viewModelScope.launch {
val event = try {
room.reportContent(action.eventId, -100, action.reason)
RoomDetailViewEvents.ActionSuccess(action)
} catch (failure: Exception) {
RoomDetailViewEvents.ActionFailure(action, failure)
}
override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
}
})
_viewEvents.post(event)
}
}
private fun handleIgnoreUser(action: RoomDetailAction.IgnoreUser) {

View file

@ -186,6 +186,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
EventType.STATE_ROOM_ALIASES,
EventType.STATE_ROOM_CANONICAL_ALIAS,
EventType.STATE_ROOM_HISTORY_VISIBILITY,
EventType.STATE_ROOM_SERVER_ACL,
EventType.CALL_INVITE,
EventType.CALL_CANDIDATES,
EventType.CALL_HANGUP,

View file

@ -57,6 +57,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
EventType.STATE_ROOM_CANONICAL_ALIAS,
EventType.STATE_ROOM_JOIN_RULES,
EventType.STATE_ROOM_HISTORY_VISIBILITY,
EventType.STATE_ROOM_SERVER_ACL,
EventType.STATE_ROOM_GUEST_ACCESS,
EventType.STATE_ROOM_WIDGET_LEGACY,
EventType.STATE_ROOM_WIDGET,

View file

@ -19,6 +19,8 @@ package im.vector.app.features.home.room.detail.timeline.format
import im.vector.app.ActiveSessionDataSource
import im.vector.app.R
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.extensions.appendNl
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
@ -35,6 +37,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
import org.matrix.android.sdk.api.session.room.model.RoomNameContent
import org.matrix.android.sdk.api.session.room.model.RoomServerAclContent
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.RoomThirdPartyInviteContent
import org.matrix.android.sdk.api.session.room.model.RoomTopicContent
@ -48,9 +51,12 @@ import org.matrix.android.sdk.internal.crypto.model.event.EncryptionEventContent
import timber.log.Timber
import javax.inject.Inject
class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource,
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
private val sp: StringProvider) {
class NoticeEventFormatter @Inject constructor(
private val activeSessionDataSource: ActiveSessionDataSource,
private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter,
private val vectorPreferences: VectorPreferences,
private val sp: StringProvider
) {
private val currentUserId: String?
get() = activeSessionDataSource.currentValue?.orNull()?.myUserId
@ -72,6 +78,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
EventType.STATE_ROOM_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_HISTORY_VISIBILITY ->
formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs)
EventType.STATE_ROOM_SERVER_ACL -> formatRoomServerAclEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs)
EventType.STATE_ROOM_ENCRYPTION -> formatRoomEncryptionEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_WIDGET,
@ -383,6 +390,79 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
}
}
private fun formatRoomServerAclEvent(event: Event, senderName: String?): String? {
val eventContent = event.getClearContent().toModel<RoomServerAclContent>() ?: return null
val prevEventContent = event.resolvedPrevContent()?.toModel<RoomServerAclContent>()
return buildString {
// Title
append(if (prevEventContent == null) {
if (event.isSentByCurrentUser()) {
sp.getString(R.string.notice_room_server_acl_set_title_by_you)
} else {
sp.getString(R.string.notice_room_server_acl_set_title, senderName)
}
} else {
if (event.isSentByCurrentUser()) {
sp.getString(R.string.notice_room_server_acl_updated_title_by_you)
} else {
sp.getString(R.string.notice_room_server_acl_updated_title, senderName)
}
})
if (eventContent.allowList.isEmpty()) {
// Special case for stuck room
appendNl(sp.getString(R.string.notice_room_server_acl_allow_is_empty))
} else if (vectorPreferences.developerMode()) {
// Details, only in developer mode
appendAclDetails(eventContent, prevEventContent)
}
}
}
private fun StringBuilder.appendAclDetails(eventContent: RoomServerAclContent, prevEventContent: RoomServerAclContent?) {
if (prevEventContent == null) {
eventContent.allowList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_allowed, it)) }
eventContent.denyList.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_set_banned, it)) }
if (eventContent.allowIpLiterals) {
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_allowed))
} else {
appendNl(sp.getString(R.string.notice_room_server_acl_set_ip_literals_not_allowed))
}
} else {
// Display only diff
var hasChanged = false
// New allowed servers
(eventContent.allowList - prevEventContent.allowList)
.also { hasChanged = hasChanged || it.isNotEmpty() }
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_allowed, it)) }
// Removed allowed servers
(prevEventContent.allowList - eventContent.allowList)
.also { hasChanged = hasChanged || it.isNotEmpty() }
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_allowed, it)) }
// New denied servers
(eventContent.denyList - prevEventContent.denyList)
.also { hasChanged = hasChanged || it.isNotEmpty() }
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_banned, it)) }
// Removed denied servers
(prevEventContent.denyList - eventContent.denyList)
.also { hasChanged = hasChanged || it.isNotEmpty() }
.forEach { appendNl(sp.getString(R.string.notice_room_server_acl_updated_was_banned, it)) }
if (prevEventContent.allowIpLiterals != eventContent.allowIpLiterals) {
hasChanged = true
if (eventContent.allowIpLiterals) {
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_allowed))
} else {
appendNl(sp.getString(R.string.notice_room_server_acl_updated_ip_literals_not_allowed))
}
}
if (!hasChanged) {
appendNl(sp.getString(R.string.notice_room_server_acl_updated_no_change))
}
}
}
private fun formatRoomCanonicalAliasEvent(event: Event, senderName: String?): String? {
val eventContent: RoomCanonicalAliasContent? = event.getClearContent().toModel()
val canonicalAlias = eventContent?.canonicalAlias

View file

@ -33,6 +33,7 @@ object TimelineDisplayableEvents {
EventType.STATE_ROOM_ALIASES,
EventType.STATE_ROOM_CANONICAL_ALIAS,
EventType.STATE_ROOM_HISTORY_VISIBILITY,
EventType.STATE_ROOM_SERVER_ACL,
EventType.STATE_ROOM_POWER_LEVELS,
EventType.CALL_INVITE,
EventType.CALL_HANGUP,

View file

@ -33,9 +33,9 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
import org.matrix.android.sdk.internal.util.awaitCallback
import org.matrix.android.sdk.rx.rx
import timber.log.Timber
import java.lang.Exception
import javax.inject.Inject
class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
@ -169,11 +169,16 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
}
private fun handleChangeNotificationMode(action: RoomListAction.ChangeRoomNotificationState) {
session.getRoom(action.roomId)?.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure))
val room = session.getRoom(action.roomId)
if (room != null) {
viewModelScope.launch {
try {
room.setRoomNotificationState(action.notificationState)
} catch (failure: Exception) {
_viewEvents.post(RoomListViewEvents.Failure(failure))
}
}
})
}
}
private fun handleToggleTag(action: RoomListAction.ToggleTag) {
@ -185,17 +190,13 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState,
action.tag.otherTag()
?.takeIf { room.roomSummary()?.hasTag(it).orFalse() }
?.let { tagToRemove ->
awaitCallback<Unit> { room.deleteTag(tagToRemove, it) }
room.deleteTag(tagToRemove)
}
// Set the tag. We do not handle the order for the moment
awaitCallback<Unit> {
room.addTag(action.tag, 0.5, it)
}
room.addTag(action.tag, 0.5)
} else {
awaitCallback<Unit> {
room.deleteTag(action.tag, it)
}
room.deleteTag(action.tag)
}
} catch (failure: Throwable) {
_viewEvents.post(RoomListViewEvents.Failure(failure))

View file

@ -69,6 +69,11 @@ abstract class AbstractLoginFragment : VectorBaseFragment(), OnBackPressed {
}
override fun showFailure(throwable: Throwable) {
// Only the resumed Fragment can eventually show the error, to avoid multiple dialog display
if (!isResumed) {
return
}
when (throwable) {
is Failure.Cancelled ->
/* Ignore this error, user has cancelled the action */

View file

@ -207,7 +207,6 @@ class LoginViewModel @AssistedInject constructor(
private fun handleCheckIfEmailHasBeenValidated(action: LoginAction.CheckIfEmailHasBeenValidated) {
// We do not want the common progress bar to be displayed, so we do not change asyncRegistration value in the state
currentTask?.cancel()
currentTask = null
currentTask = registrationWizard?.checkIfEmailHasBeenValidated(action.delayMillis, registrationCallback)
}

View file

@ -102,11 +102,13 @@ class RoomProfileViewModel @AssistedInject constructor(
}
private fun handleChangeNotificationMode(action: RoomProfileAction.ChangeRoomNotificationState) {
room.setRoomNotificationState(action.notificationState, object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
viewModelScope.launch {
try {
room.setRoomNotificationState(action.notificationState)
} catch (failure: Throwable) {
_viewEvents.post(RoomProfileViewEvents.Failure(failure))
}
})
}
}
private fun handleLeaveRoom() {

View file

@ -17,6 +17,7 @@
package im.vector.app.features.roomprofile.settings
import androidx.core.net.toFile
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext
@ -27,7 +28,7 @@ import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
import io.reactivex.Completable
import io.reactivex.Observable
import org.matrix.android.sdk.api.MatrixCallback
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.Session
@ -228,16 +229,13 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
private fun handleEnableEncryption() {
postLoading(true)
room.enableEncryption(callback = object : MatrixCallback<Unit> {
override fun onFailure(failure: Throwable) {
postLoading(false)
viewModelScope.launch {
val result = runCatching { room.enableEncryption() }
postLoading(false)
result.onFailure { failure ->
_viewEvents.post(RoomSettingsViewEvents.Failure(failure))
}
override fun onSuccess(data: Unit) {
postLoading(false)
}
})
}
}
private fun postLoading(isLoading: Boolean) {