diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt index 76faad279f..163296e71c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/MessageInformationDataFactory.kt @@ -35,6 +35,8 @@ import org.matrix.android.sdk.api.extensions.orFalse 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.toModel +import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams +import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.ReferencesAggregatedContent import org.matrix.android.sdk.api.session.room.model.message.MessageVerificationRequestContent import org.matrix.android.sdk.api.session.room.send.SendState @@ -76,6 +78,27 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses val time = dateFormatter.format(event.root.originServerTs, DateFormatKind.MESSAGE_SIMPLE) val e2eDecoration = getE2EDecoration(event) + var isEffectivelyDirect = false + var dmOtherMemberId: String? = null + if ((roomSummaryHolder.roomSummary?.isDirect == true) && event.root.roomId != null) { + val members = session.getRoom(event.root.roomId!!) + ?.getRoomMembers(roomMemberQueryParams { memberships = listOf(Membership.JOIN) }) + ?.map { it.userId } + .orEmpty() + .toSet() + if (members.size == 2) { + var foundSelf = false + for (member in members) { + if (member == session.myUserId) { + foundSelf = true + } else { + dmOtherMemberId = member + } + } + isEffectivelyDirect = foundSelf && (dmOtherMemberId != null) + } + } + return MessageInformationData( eventId = eventId, senderId = event.root.senderId ?: "", @@ -127,7 +150,8 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses } else { AnonymousReadReceipt.PROCESSING }, - isDirect = roomSummaryHolder.roomSummary?.isDirect ?: false, + isDirect = isEffectivelyDirect, + dmChatPartnerId = dmOtherMemberId, e2eDecoration = e2eDecoration ) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index 0fb0cf9ffb..e068d0d345 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -242,7 +242,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem } override fun ignoreMessageGuideline(context: Context): Boolean { - return infoInBubbles(context) && (attributes.informationData.sentByMe || attributes.informationData.isDirect) + return infoInBubbles(context) && canHideAvatars() } open fun getViewStubMinimumWidth(holder: H, contentInBubble: Boolean, showInformation: Boolean): Int { @@ -303,7 +303,8 @@ abstract class AbsMessageItem : AbsBaseMessageItem } open fun canHideAvatars(): Boolean { - return attributes.informationData.sentByMe || attributes.informationData.isDirect + return attributes.informationData.sentByMe || + (attributes.informationData.isDirect && attributes.informationData.senderId == attributes.informationData.dmChatPartnerId) } override fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt index 307b91dee6..6354b201f5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageInformationData.kt @@ -44,6 +44,7 @@ data class MessageInformationData( val sentByMe : Boolean, val readReceiptAnonymous: AnonymousReadReceipt, val isDirect: Boolean, + val dmChatPartnerId: String?, val e2eDecoration: E2EDecoration = E2EDecoration.NONE ) : Parcelable {