Improve code

This commit is contained in:
Benoit Marty 2021-10-04 16:16:13 +02:00
parent 9802ed08e3
commit 5076369173
4 changed files with 16 additions and 9 deletions

View file

@ -49,7 +49,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler, false), SPOILER("/spoiler", "<message>", R.string.command_description_spoiler, false),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false), POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false),
SHRUG("/shrug", "<message>", R.string.command_description_shrug, false), SHRUG("/shrug", "<message>", R.string.command_description_shrug, false),
LENNY("/lenny", "[<message>]", R.string.command_description_lenny, false), LENNY("/lenny", "<message>", R.string.command_description_lenny, false),
PLAIN("/plain", "<message>", R.string.command_description_plain, false), PLAIN("/plain", "<message>", R.string.command_description_plain, false),
WHOIS("/whois", "<user-id>", R.string.command_description_whois, false), WHOIS("/whois", "<user-id>", R.string.command_description_whois, false),
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false), DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false),

View file

@ -48,7 +48,6 @@ import im.vector.app.features.createdirect.DirectRoomHelper
import im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy import im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy
import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider
import im.vector.app.features.home.room.detail.composer.VoiceMessageHelper import im.vector.app.features.home.room.detail.composer.VoiceMessageHelper
import im.vector.app.features.home.room.detail.composer.rainbow.RainbowGenerator
import im.vector.app.features.home.room.detail.sticker.StickerPickerActionHandler import im.vector.app.features.home.room.detail.sticker.StickerPickerActionHandler
import im.vector.app.features.home.room.detail.timeline.factory.TimelineFactory import im.vector.app.features.home.room.detail.timeline.factory.TimelineFactory
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever

View file

@ -19,7 +19,6 @@ package im.vector.app.features.home.room.detail.composer
import androidx.annotation.StringRes import androidx.annotation.StringRes
import im.vector.app.core.platform.VectorViewEvents import im.vector.app.core.platform.VectorViewEvents
import im.vector.app.features.command.Command import im.vector.app.features.command.Command
import im.vector.app.features.home.room.detail.RoomDetailViewEvents
sealed class TextComposerViewEvents : VectorViewEvents { sealed class TextComposerViewEvents : VectorViewEvents {

View file

@ -45,7 +45,6 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
@ -607,15 +606,20 @@ class TextComposerViewModel @AssistedInject constructor(
} }
} }
private fun getLastMemberEvent(): RoomMemberContent { private fun getMyRoomMemberContent(): RoomMemberContent? {
return room.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(session.myUserId)) return room.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(session.myUserId))
?.content?.toModel<RoomMemberContent>() ?.content
?: RoomMemberContent(membership = Membership.JOIN) ?.toModel<RoomMemberContent>()
} }
private fun handleChangeDisplayNameForRoomSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayNameForRoom) { private fun handleChangeDisplayNameForRoomSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayNameForRoom) {
launchSlashCommandFlowSuspendable { launchSlashCommandFlowSuspendable {
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, getLastMemberEvent().copy(displayName = changeDisplayName.displayName).toContent()) getMyRoomMemberContent()
?.copy(displayName = changeDisplayName.displayName)
?.toContent()
?.let {
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, it)
}
} }
} }
@ -627,7 +631,12 @@ class TextComposerViewModel @AssistedInject constructor(
private fun handleChangeAvatarForRoomSlashCommand(changeAvatar: ParsedCommand.ChangeAvatarForRoom) { private fun handleChangeAvatarForRoomSlashCommand(changeAvatar: ParsedCommand.ChangeAvatarForRoom) {
launchSlashCommandFlowSuspendable { launchSlashCommandFlowSuspendable {
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, getLastMemberEvent().copy(avatarUrl = changeAvatar.url).toContent()) getMyRoomMemberContent()
?.copy(avatarUrl = changeAvatar.url)
?.toContent()
?.let {
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, it)
}
} }
} }