Skip to content

Commit e0c51bd

Browse files
authored
Merge pull request #8749 from element-hq/feature/bma/locationAvatar
Location avatar
2 parents d75ca51 + e340678 commit e0c51bd

File tree

22 files changed

+121
-68
lines changed

22 files changed

+121
-68
lines changed

changelog.d/8749.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issues about location Event avatar rendering.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/SessionExtensions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.matrix.android.sdk.api.session
1919
import org.matrix.android.sdk.api.session.room.Room
2020
import org.matrix.android.sdk.api.session.room.model.RoomSummary
2121
import org.matrix.android.sdk.api.session.user.model.User
22+
import timber.log.Timber
2223

2324
/**
2425
* Get a room using the RoomService of a Session.
@@ -41,4 +42,5 @@ fun Session.getUser(userId: String): User? = userService().getUser(userId)
4142
/**
4243
* Similar to [getUser], but fallback to a User without details if the User is not known by the SDK, or if Session is null.
4344
*/
44-
fun Session?.getUserOrDefault(userId: String): User = this?.userService()?.getUser(userId) ?: User(userId)
45+
fun Session?.getUserOrDefault(userId: String): User = this?.userService()?.getUser(userId)
46+
?: User(userId).also { Timber.w("User $userId not found in local cache, fallback to default") }

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/livelocation/LiveLocationShareAggregatedSummary.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocati
2222
* Aggregation info concerning a live location share.
2323
*/
2424
data class LiveLocationShareAggregatedSummary(
25+
val roomId: String?,
2526
val userId: String?,
2627
/**
2728
* Indicate whether the live is currently running.

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/LiveLocationShareAggregatedSummaryMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal class LiveLocationShareAggregatedSummaryMapper @Inject constructor() :
2828

2929
override fun map(entity: LiveLocationShareAggregatedSummaryEntity): LiveLocationShareAggregatedSummary {
3030
return LiveLocationShareAggregatedSummary(
31+
roomId = entity.roomId,
3132
userId = entity.userId,
3233
isActive = entity.isActive,
3334
endOfLiveTimestampMillis = entity.endOfLiveTimestampMillis,

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/mapper/LiveLocationShareAggregatedSummaryMapperTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.session.room.model.message.LocationInfo
2424
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
2525
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
2626

27+
private const val ANY_ROOM_ID = "a-room-id"
2728
private const val ANY_USER_ID = "a-user-id"
2829
private const val ANY_ACTIVE_STATE = true
2930
private const val ANY_TIMEOUT = 123L
@@ -40,6 +41,7 @@ class LiveLocationShareAggregatedSummaryMapperTest {
4041
val summary = mapper.map(entity)
4142

4243
summary shouldBeEqualTo LiveLocationShareAggregatedSummary(
44+
roomId = ANY_ROOM_ID,
4345
userId = ANY_USER_ID,
4446
isActive = ANY_ACTIVE_STATE,
4547
endOfLiveTimestampMillis = ANY_TIMEOUT,
@@ -48,6 +50,7 @@ class LiveLocationShareAggregatedSummaryMapperTest {
4850
}
4951

5052
private fun anEntity(content: MessageBeaconLocationDataContent) = LiveLocationShareAggregatedSummaryEntity(
53+
roomId = ANY_ROOM_ID,
5154
userId = ANY_USER_ID,
5255
isActive = ANY_ACTIVE_STATE,
5356
endOfLiveTimestampMillis = ANY_TIMEOUT,

matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/location/DefaultLocationSharingServiceTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ internal class DefaultLocationSharingServiceTest {
229229
fun `livedata of live summaries is correctly computed`() {
230230
val entity = LiveLocationShareAggregatedSummaryEntity()
231231
val summary = LiveLocationShareAggregatedSummary(
232+
roomId = A_ROOM_ID,
232233
userId = "",
233234
isActive = true,
234235
endOfLiveTimestampMillis = 123,
@@ -255,6 +256,7 @@ internal class DefaultLocationSharingServiceTest {
255256
fun `given an event id when getting livedata on corresponding live summary then it is correctly computed`() {
256257
val entity = LiveLocationShareAggregatedSummaryEntity()
257258
val summary = LiveLocationShareAggregatedSummary(
259+
roomId = A_ROOM_ID,
258260
userId = "",
259261
isActive = true,
260262
endOfLiveTimestampMillis = 123,

vector/src/main/java/im/vector/app/core/epoxy/bottomsheet/BottomSheetMessagePreviewItem.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
103103
.apply(RequestOptions.centerCropTransform())
104104
.into(holder.staticMapImageView)
105105

106-
safeLocationUiData.locationPinProvider.create(safeLocationUiData.locationOwnerId) { pinDrawable ->
107-
GlideApp.with(holder.staticMapPinImageView)
108-
.load(pinDrawable)
109-
.into(holder.staticMapPinImageView)
106+
val pinMatrixItem = matrixItem.takeIf { safeLocationUiData.locationOwnerId != null }
107+
safeLocationUiData.locationPinProvider.create(pinMatrixItem) { pinDrawable ->
108+
// we are not using Glide since it does not display it correctly when there is no user photo
109+
holder.staticMapPinImageView.setImageDrawable(pinDrawable)
110110
}
111111
}
112112
}

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsEpoxyController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class MessageActionsEpoxyController @Inject constructor(
238238
val locationUrl = locationContent.toLocationData()
239239
?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) }
240240
?: return null
241-
val locationOwnerId = if (locationContent.isSelfLocation()) state.informationData.matrixItem.id else null
241+
val locationOwnerId = if (locationContent.isSelfLocation()) state.informationData.senderId else null
242242

243243
return LocationUiData(
244244
locationUrl = locationUrl,

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/LiveLocationShareMessageItemFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class LiveLocationShareMessageItemFactory @Inject constructor(
114114
.locationUrl(locationUrl)
115115
.mapWidth(width)
116116
.mapHeight(height)
117-
.locationUserId(attributes.informationData.senderId)
117+
.pinMatrixItem(attributes.informationData.matrixItem)
118118
.locationPinProvider(locationPinProvider)
119119
.highlighted(highlight)
120120
.leftGuideline(avatarSizeProvider.leftGuideline)

vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ class MessageItemFactory @Inject constructor(
233233
urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, width, height)
234234
}
235235

236-
val locationUserId = if (locationContent.isSelfLocation()) informationData.senderId else null
236+
val pinMatrixItem = if (locationContent.isSelfLocation()) informationData.matrixItem else null
237237

238238
return MessageLocationItem_()
239239
.attributes(attributes)
240240
.locationUrl(locationUrl)
241241
.mapWidth(width)
242242
.mapHeight(height)
243-
.locationUserId(locationUserId)
243+
.pinMatrixItem(pinMatrixItem)
244244
.locationPinProvider(locationPinProvider)
245245
.highlighted(highlight)
246246
.leftGuideline(avatarSizeProvider.leftGuideline)

0 commit comments

Comments
 (0)