mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Fix other potential issue when using Session.getUser()
This commit is contained in:
parent
032fa37b64
commit
7699628959
@ -29,7 +29,7 @@ import im.vector.app.core.di.ActiveSessionHolder
|
|||||||
import im.vector.app.core.glide.GlideApp
|
import im.vector.app.core.glide.GlideApp
|
||||||
import im.vector.app.core.utils.DimensionConverter
|
import im.vector.app.core.utils.DimensionConverter
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -67,9 +67,9 @@ class LocationPinProvider @Inject constructor(
|
|||||||
|
|
||||||
activeSessionHolder
|
activeSessionHolder
|
||||||
.getActiveSession()
|
.getActiveSession()
|
||||||
.getUser(userId)
|
.getUserOrDefault(userId)
|
||||||
?.toMatrixItem()
|
.toMatrixItem()
|
||||||
?.let { userItem ->
|
.let { userItem ->
|
||||||
val size = dimensionConverter.dpToPx(44)
|
val size = dimensionConverter.dpToPx(44)
|
||||||
val bgTintColor = matrixItemColorProvider.getColor(userItem)
|
val bgTintColor = matrixItemColorProvider.getColor(userItem)
|
||||||
avatarRenderer.render(glideRequests, userItem, object : CustomTarget<Drawable>(size, size) {
|
avatarRenderer.render(glideRequests, userItem, object : CustomTarget<Drawable>(size, size) {
|
||||||
|
@ -27,7 +27,7 @@ import im.vector.app.core.glide.GlideApp
|
|||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import io.noties.markwon.core.spans.LinkSpan
|
import io.noties.markwon.core.spans.LinkSpan
|
||||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
@ -101,7 +101,7 @@ class PillsPostProcessor @AssistedInject constructor(
|
|||||||
|
|
||||||
private fun PermalinkData.UserLink.toMatrixItem(roomId: String?): MatrixItem? =
|
private fun PermalinkData.UserLink.toMatrixItem(roomId: String?): MatrixItem? =
|
||||||
if (roomId == null) {
|
if (roomId == null) {
|
||||||
sessionHolder.getSafeActiveSession()?.getUser(userId)?.toMatrixItem()
|
sessionHolder.getSafeActiveSession()?.getUserOrDefault(userId)?.toMatrixItem()
|
||||||
} else {
|
} else {
|
||||||
sessionHolder.getSafeActiveSession()?.roomService()?.getRoomMember(userId, roomId)?.toMatrixItem()
|
sessionHolder.getSafeActiveSession()?.roomService()?.getRoomMember(userId, roomId)?.toMatrixItem()
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import org.matrix.android.sdk.api.extensions.orFalse
|
|||||||
import org.matrix.android.sdk.api.session.Session
|
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.getRoom
|
import org.matrix.android.sdk.api.session.getRoom
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -101,7 +101,7 @@ class LocationSharingViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setUserItem() {
|
private fun setUserItem() {
|
||||||
setState { copy(userItem = session.getUser(session.myUserId)?.toMatrixItem()) }
|
setState { copy(userItem = session.getUserOrDefault(session.myUserId).toMatrixItem()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePin(isUserPin: Boolean? = true) {
|
private fun updatePin(isUserPin: Boolean? = true) {
|
||||||
|
@ -20,7 +20,7 @@ import im.vector.app.core.di.ActiveSessionHolder
|
|||||||
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
|
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
|
||||||
import im.vector.app.features.location.toLocationData
|
import im.vector.app.features.location.toLocationData
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -45,19 +45,17 @@ class UserLiveLocationViewStateMapper @Inject constructor(
|
|||||||
else -> {
|
else -> {
|
||||||
locationPinProvider.create(userId) { pinDrawable ->
|
locationPinProvider.create(userId) { pinDrawable ->
|
||||||
val session = activeSessionHolder.getActiveSession()
|
val session = activeSessionHolder.getActiveSession()
|
||||||
session.getUser(userId)?.toMatrixItem()?.let { matrixItem ->
|
val locationTimestampMillis = liveLocationShareAggregatedSummary.lastLocationDataContent?.getBestTimestampMillis()
|
||||||
val locationTimestampMillis = liveLocationShareAggregatedSummary.lastLocationDataContent?.getBestTimestampMillis()
|
val viewState = UserLiveLocationViewState(
|
||||||
val viewState = UserLiveLocationViewState(
|
matrixItem = session.getUserOrDefault(userId).toMatrixItem(),
|
||||||
matrixItem = matrixItem,
|
pinDrawable = pinDrawable,
|
||||||
pinDrawable = pinDrawable,
|
locationData = locationData,
|
||||||
locationData = locationData,
|
endOfLiveTimestampMillis = liveLocationShareAggregatedSummary.endOfLiveTimestampMillis,
|
||||||
endOfLiveTimestampMillis = liveLocationShareAggregatedSummary.endOfLiveTimestampMillis,
|
locationTimestampMillis = locationTimestampMillis,
|
||||||
locationTimestampMillis = locationTimestampMillis,
|
showStopSharingButton = userId == session.myUserId
|
||||||
showStopSharingButton = userId == session.myUserId
|
)
|
||||||
)
|
continuation.resume(viewState) {
|
||||||
continuation.resume(viewState) {
|
// do nothing on cancellation
|
||||||
// do nothing on cancellation
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ import org.matrix.android.sdk.api.session.events.model.supportsNotification
|
|||||||
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.getRoom
|
import org.matrix.android.sdk.api.session.getRoom
|
||||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.room.getTimelineEvent
|
import org.matrix.android.sdk.api.session.room.getTimelineEvent
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
@ -112,7 +112,7 @@ class NotifiableEventResolver @Inject constructor(
|
|||||||
val notificationAction = actions.toNotificationAction()
|
val notificationAction = actions.toNotificationAction()
|
||||||
|
|
||||||
return if (notificationAction.shouldNotify) {
|
return if (notificationAction.shouldNotify) {
|
||||||
val user = session.getUser(event.senderId!!) ?: return null
|
val user = session.getUserOrDefault(event.senderId!!)
|
||||||
|
|
||||||
val timelineEvent = TimelineEvent(
|
val timelineEvent = TimelineEvent(
|
||||||
root = event,
|
root = event,
|
||||||
|
@ -27,7 +27,7 @@ import im.vector.app.features.displayname.getBestName
|
|||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -186,11 +186,11 @@ class NotificationDrawerManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderEvents(session: Session, eventsToRender: List<ProcessedEvent<NotifiableEvent>>) {
|
private fun renderEvents(session: Session, eventsToRender: List<ProcessedEvent<NotifiableEvent>>) {
|
||||||
val user = session.getUser(session.myUserId)
|
val user = session.getUserOrDefault(session.myUserId)
|
||||||
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
|
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
|
||||||
val myUserDisplayName = user?.toMatrixItem()?.getBestName() ?: session.myUserId
|
val myUserDisplayName = user.toMatrixItem().getBestName()
|
||||||
val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(
|
val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(
|
||||||
contentUrl = user?.avatarUrl,
|
contentUrl = user.avatarUrl,
|
||||||
width = avatarSize,
|
width = avatarSize,
|
||||||
height = avatarSize,
|
height = avatarSize,
|
||||||
method = ContentUrlResolver.ThumbnailMethod.SCALE
|
method = ContentUrlResolver.ThumbnailMethod.SCALE
|
||||||
|
@ -32,6 +32,7 @@ import im.vector.app.core.di.SingletonEntryPoint
|
|||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.extensions.hasUnsavedKeys
|
import im.vector.app.core.extensions.hasUnsavedKeys
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
import im.vector.app.features.displayname.getBestName
|
||||||
import im.vector.app.features.login.LoginMode
|
import im.vector.app.features.login.LoginMode
|
||||||
import im.vector.app.features.login.toSsoState
|
import im.vector.app.features.login.toSsoState
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -39,7 +40,8 @@ import org.matrix.android.sdk.api.auth.AuthenticationService
|
|||||||
import org.matrix.android.sdk.api.auth.LoginType
|
import org.matrix.android.sdk.api.auth.LoginType
|
||||||
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
|
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
|
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class SoftLogoutViewModel @AssistedInject constructor(
|
class SoftLogoutViewModel @AssistedInject constructor(
|
||||||
@ -68,7 +70,7 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||||||
homeServerUrl = session.sessionParams.homeServerUrl,
|
homeServerUrl = session.sessionParams.homeServerUrl,
|
||||||
userId = userId,
|
userId = userId,
|
||||||
deviceId = session.sessionParams.deviceId.orEmpty(),
|
deviceId = session.sessionParams.deviceId.orEmpty(),
|
||||||
userDisplayName = session.getUser(userId)?.displayName ?: userId,
|
userDisplayName = session.getUserOrDefault(userId).toMatrixItem().getBestName(),
|
||||||
hasUnsavedKeys = session.hasUnsavedKeys(),
|
hasUnsavedKeys = session.hasUnsavedKeys(),
|
||||||
loginType = session.sessionParams.loginType,
|
loginType = session.sessionParams.loginType,
|
||||||
)
|
)
|
||||||
|
@ -34,7 +34,7 @@ import kotlinx.coroutines.launch
|
|||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
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.RoomSummary
|
||||||
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
import org.matrix.android.sdk.api.session.room.peeking.PeekResult
|
||||||
@ -49,7 +49,7 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
|||||||
session.getRoomSummary(initialState.spaceId)?.let { roomSummary ->
|
session.getRoomSummary(initialState.spaceId)?.let { roomSummary ->
|
||||||
val knownMembers = roomSummary.otherMemberIds.filter {
|
val knownMembers = roomSummary.otherMemberIds.filter {
|
||||||
session.roomService().getExistingDirectRoomWithUser(it) != null
|
session.roomService().getExistingDirectRoomWithUser(it) != null
|
||||||
}.mapNotNull { session.getUser(it) }
|
}.map { session.getUserOrDefault(it) }
|
||||||
// put one with avatar first, and take 5
|
// put one with avatar first, and take 5
|
||||||
val peopleYouKnow = (knownMembers.filter { it.avatarUrl != null } + knownMembers.filter { it.avatarUrl == null })
|
val peopleYouKnow = (knownMembers.filter { it.avatarUrl != null } + knownMembers.filter { it.avatarUrl == null })
|
||||||
.take(5)
|
.take(5)
|
||||||
@ -57,7 +57,7 @@ class SpaceInviteBottomSheetViewModel @AssistedInject constructor(
|
|||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
summary = Success(roomSummary),
|
summary = Success(roomSummary),
|
||||||
inviterUser = roomSummary.inviterId?.let { session.getUser(it) }?.let { Success(it) } ?: Uninitialized,
|
inviterUser = roomSummary.inviterId?.let { session.getUserOrDefault(it) }?.let { Success(it) } ?: Uninitialized,
|
||||||
peopleYouKnow = Success(peopleYouKnow)
|
peopleYouKnow = Success(peopleYouKnow)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.getUser
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkData
|
||||||
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser
|
||||||
import org.matrix.android.sdk.api.session.user.model.User
|
import org.matrix.android.sdk.api.session.user.model.User
|
||||||
@ -46,10 +46,10 @@ class UserCodeSharedViewModel @AssistedInject constructor(
|
|||||||
companion object : MavericksViewModelFactory<UserCodeSharedViewModel, UserCodeState> by hiltMavericksViewModelFactory()
|
companion object : MavericksViewModelFactory<UserCodeSharedViewModel, UserCodeState> by hiltMavericksViewModelFactory()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val user = session.getUser(initialState.userId)
|
val user = session.getUserOrDefault(initialState.userId)
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
matrixItem = user?.toMatrixItem(),
|
matrixItem = user.toMatrixItem(),
|
||||||
shareLink = session.permalinkService().createPermalink(initialState.userId)
|
shareLink = session.permalinkService().createPermalink(initialState.userId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user