From 24fcb3f58f3866cd259c48feae9eec09698d2063 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 28 Sep 2020 11:18:51 +0300 Subject: [PATCH 01/18] Differentiate wordings for direct rooms. --- .../src/main/res/values/strings.xml | 22 +++ .../home/room/detail/RoomDetailFragment.kt | 12 +- .../timeline/factory/EncryptionItemFactory.kt | 11 +- .../factory/MergedHeaderItemFactory.kt | 18 +- .../timeline/format/NoticeEventFormatter.kt | 183 ++++++++++++------ .../detail/timeline/item/BasedMergedItem.kt | 3 +- .../timeline/item/MergedRoomCreationItem.kt | 18 +- vector/src/main/res/values/strings.xml | 7 + 8 files changed, 206 insertions(+), 68 deletions(-) diff --git a/matrix-sdk-android/src/main/res/values/strings.xml b/matrix-sdk-android/src/main/res/values/strings.xml index f64ec9926e..70a7461fe9 100644 --- a/matrix-sdk-android/src/main/res/values/strings.xml +++ b/matrix-sdk-android/src/main/res/values/strings.xml @@ -10,13 +10,19 @@ Your invitation %1$s created the room You created the room + %1$s joined + You joined %1$s invited %2$s You invited %1$s %1$s invited you %1$s joined the room You joined the room + %1$s joined + You joined %1$s left the room You left the room + %1$s left the room + You left the room %1$s rejected the invitation You rejected the invitation %1$s kicked %2$s @@ -53,6 +59,8 @@ You ended the call. %1$s made future room history visible to %2$s You made future room history visible to %1$s + %1$s made future messages visible to %2$s + You made future messages visible to %1$s all room members, from the point they are invited. all room members, from the point they joined. all room members. @@ -62,6 +70,8 @@ You turned on end-to-end encryption (%1$s) %s upgraded this room. You upgraded this room. + %s upgraded here. + You upgraded here. %1$s requested a VoIP conference You requested a VoIP conference @@ -83,8 +93,12 @@ You updated your profile %1$s %1$s sent an invitation to %2$s to join the room You sent an invitation to %1$s to join the room + %1$s invited %2$s + You invited %1$s %1$s revoked the invitation for %2$s to join the room You revoked the invitation for %1$s to join the room + %1$s revoked the invitation for %2$s + You revoked the invitation for %1$s %1$s accepted the invitation for %2$s You accepted the invitation for %1$s @@ -171,8 +185,12 @@ %1$s invited you. Reason: %2$s %1$s joined the room. Reason: %2$s You joined the room. Reason: %1$s + %1$s joined. Reason: %2$s + You joined. Reason: %1$s %1$s left the room. Reason: %2$s You left the room. Reason: %1$s + %1$s left. Reason: %2$s + You left. Reason: %1$s %1$s rejected the invitation. Reason: %2$s You rejected the invitation. Reason: %1$s %1$s kicked %2$s. Reason: %3$s @@ -220,8 +238,12 @@ "%1$s has allowed guests to join the room." "You have allowed guests to join the room." + "%1$s has allowed guests to join here." + "You have allowed guests to join here." "%1$s has prevented guests from joining the room." "You have prevented guests from joining the room." + "%1$s has prevented guests from joining the room." + "You have prevented guests from joining the room." %1$s turned on end-to-end encryption. You turned on end-to-end encryption. diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index e7140f06f4..b31af30609 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -704,7 +704,11 @@ class RoomDetailFragment @Inject constructor( // safeStartCall(it, isVideoCall) // } } else if (!state.isAllowedToStartWebRTCCall) { - showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call)) + if (session.getRoom(state.roomId)?.roomSummary()?.isDirect == true) { + showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call_in_direct_room)) + } else { + showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call)) + } } else { safeStartCall(isVideoCall) } @@ -714,7 +718,11 @@ class RoomDetailFragment @Inject constructor( // can you add widgets?? if (!state.isAllowedToManageWidgets) { // You do not have permission to start a conference call in this room - showDialogWithMessage(getString(R.string.no_permissions_to_start_conf_call)) + if (session.getRoom(state.roomId)?.roomSummary()?.isDirect == true) { + showDialogWithMessage(getString(R.string.no_permissions_to_start_conf_call_in_direct_room)) + } else { + showDialogWithMessage(getString(R.string.no_permissions_to_start_conf_call)) + } } else { if (state.activeRoomWidgets()?.filter { it.type == WidgetType.Jitsi }?.any() == true) { // A conference is already in progress! diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt index 5374b4792a..2ed88cbae9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt @@ -25,6 +25,8 @@ import im.vector.app.features.home.room.detail.timeline.helper.MessageInformatio import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory import im.vector.app.features.home.room.detail.timeline.item.StatusTileTimelineItem import im.vector.app.features.home.room.detail.timeline.item.StatusTileTimelineItem_ +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.toModel import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM @@ -36,7 +38,8 @@ class EncryptionItemFactory @Inject constructor( private val messageColorProvider: MessageColorProvider, private val stringProvider: StringProvider, private val informationDataFactory: MessageInformationDataFactory, - private val avatarSizeProvider: AvatarSizeProvider) { + private val avatarSizeProvider: AvatarSizeProvider, + private val session: Session) { fun create(event: TimelineEvent, highlight: Boolean, @@ -51,7 +54,11 @@ class EncryptionItemFactory @Inject constructor( val shield: StatusTileTimelineItem.ShieldUIState if (isSafeAlgorithm) { title = stringProvider.getString(R.string.encryption_enabled) - description = stringProvider.getString(R.string.encryption_enabled_tile_description) + description = if (session.getRoomSummary(event.root.roomId ?: "")?.isDirect.orFalse()) { + stringProvider.getString(R.string.direct_room_encryption_enabled_tile_description) + } else { + stringProvider.getString(R.string.encryption_enabled_tile_description) + } shield = StatusTileTimelineItem.ShieldUIState.BLACK } else { title = stringProvider.getString(R.string.encryption_not_enabled) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt index 0ba3b4d47e..41a961dee0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt @@ -33,6 +33,7 @@ import im.vector.app.features.home.room.detail.timeline.item.MergedRoomCreationI import im.vector.app.features.home.room.detail.timeline.item.MergedUTDItem import im.vector.app.features.home.room.detail.timeline.item.MergedUTDItem_ import im.vector.app.features.settings.VectorPreferences +import org.matrix.android.sdk.api.extensions.orFalse 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.model.create.RoomCreateContent @@ -78,6 +79,12 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde } } + private fun isDirectRoom(roomId: String?): Boolean { + return roomId?.let { + activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)?.roomSummary()?.isDirect + }.orFalse() + } + private fun buildMembershipEventsMergedSummary(currentPosition: Int, items: List, event: TimelineEvent, @@ -100,7 +107,8 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde avatarUrl = mergedEvent.senderInfo.avatarUrl, memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, - eventId = mergedEvent.root.eventId ?: "" + eventId = mergedEvent.root.eventId ?: "", + isDirectRoom = isDirectRoom(mergedEvent.root.roomId) ) mergedData.add(data) } @@ -157,7 +165,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde items: List, event: TimelineEvent, eventIdToHighlight: String?, - // requestModelBuild: () -> Unit, + // requestModelBuild: () -> Unit, callback: TimelineEventController.Callback?): MergedUTDItem_? { Timber.v("## MERGE: buildUTDMergedSummary from position $currentPosition") var prevEvent = items.prevOrNull(currentPosition) @@ -187,7 +195,8 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde avatarUrl = senderAvatar, memberName = senderName, localId = mergedEvent.localId, - eventId = mergedEvent.root.eventId ?: "" + eventId = mergedEvent.root.eventId ?: "", + isDirectRoom = isDirectRoom(mergedEvent.root.roomId) ) mergedData.add(data) } @@ -247,7 +256,8 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde avatarUrl = mergedEvent.senderInfo.avatarUrl, memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, - eventId = mergedEvent.root.eventId ?: "" + eventId = mergedEvent.root.eventId ?: "", + isDirectRoom = isDirectRoom(mergedEvent.root.roomId) ) mergedData.add(data) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 9a4729abee..64d0fdd127 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -16,6 +16,7 @@ package im.vector.app.features.home.room.detail.timeline.format +import androidx.annotation.StringRes import im.vector.app.ActiveSessionDataSource import im.vector.app.R import im.vector.app.core.resources.StringProvider @@ -56,6 +57,27 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId + private fun isDirectRoom(roomId: String?): Boolean { + return roomId?.let { + activeSessionDataSource.currentValue?.orNull()?.getRoom(roomId)?.roomSummary()?.isDirect + }.orFalse() + } + + private fun chooseResourceByRoomType(event: Event, + @StringRes directRoomResId: Int, + @StringRes directRoomByUserResId: Int, + @StringRes publicRoomResId: Int, + @StringRes publicRoomByUserResId: Int, + userResArgs: Any? = null, + vararg thirdPartyResArgs: Any? + ): String { + return if (isDirectRoom(event.roomId)) { + if (event.isSentByCurrentUser()) sp.getString(directRoomByUserResId, userResArgs) else sp.getString(directRoomResId, *thirdPartyResArgs) + } else { + if (event.isSentByCurrentUser()) sp.getString(publicRoomByUserResId, userResArgs) else sp.getString(publicRoomResId, *thirdPartyResArgs) + } + } + fun format(timelineEvent: TimelineEvent): CharSequence? { return when (val type = timelineEvent.root.getClearType()) { EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) @@ -179,11 +201,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return event.getClearContent().toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { - if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_created_by_you) - } else { - sp.getString(R.string.notice_room_created, it.creator) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_room_created_by_you, + directRoomByUserResId = R.string.notice_direct_room_created_by_you, + publicRoomResId = R.string.notice_room_created, + publicRoomByUserResId = R.string.notice_room_created_by_you, + thirdPartyResArgs = *arrayOf(it.creator) + ) } } @@ -205,11 +230,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } private fun formatRoomTombstoneEvent(event: Event, senderName: String?): CharSequence? { - return if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_update_by_you) - } else { - sp.getString(R.string.notice_room_update, senderName) - } + return chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_update, + directRoomByUserResId = R.string.notice_direct_room_update_by_you, + publicRoomResId = R.string.notice_room_update, + publicRoomByUserResId = R.string.notice_room_update_by_you, + thirdPartyResArgs = *arrayOf(senderName) + ) } private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? { @@ -250,11 +278,15 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) - return if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_made_future_room_visibility_by_you, formattedVisibility) - } else { - sp.getString(R.string.notice_made_future_room_visibility, senderName, formattedVisibility) - } + return chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_made_future_direct_room_visibility, + directRoomByUserResId = R.string.notice_made_future_direct_room_visibility_by_you, + publicRoomResId = R.string.notice_made_future_room_visibility, + publicRoomByUserResId = R.string.notice_made_future_room_visibility_by_you, + userResArgs = formattedVisibility, + thirdPartyResArgs = *arrayOf(senderName, formattedVisibility) + ) } private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? { @@ -264,19 +296,27 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return when { prevContent != null -> { // Revoke case - if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_third_party_revoked_invite_by_you, prevContent.displayName) - } else { - sp.getString(R.string.notice_room_third_party_revoked_invite, senderName, prevContent.displayName) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_third_party_revoked_invite, + directRoomByUserResId = R.string.notice_direct_room_third_party_revoked_invite_by_you, + publicRoomResId = R.string.notice_room_third_party_revoked_invite, + publicRoomByUserResId = R.string.notice_room_third_party_revoked_invite_by_you, + userResArgs = prevContent.displayName, + thirdPartyResArgs = *arrayOf(senderName, prevContent.displayName) + ) } content != null -> { // Invitation case - if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_third_party_invite_by_you, content.displayName) - } else { - sp.getString(R.string.notice_room_third_party_invite, senderName, content.displayName) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_third_party_invite, + directRoomByUserResId = R.string.notice_direct_room_third_party_invite_by_you, + publicRoomResId = R.string.notice_room_third_party_invite, + publicRoomByUserResId = R.string.notice_room_third_party_invite_by_you, + userResArgs = content.displayName, + thirdPartyResArgs = *arrayOf(senderName, content.displayName) + ) } else -> null } @@ -391,17 +431,23 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> - if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_guest_access_can_join_by_you) - } else { - sp.getString(R.string.notice_room_guest_access_can_join, senderName) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_guest_access_can_join, + directRoomByUserResId = R.string.notice_direct_room_guest_access_can_join_by_you, + publicRoomResId = R.string.notice_room_guest_access_can_join, + publicRoomByUserResId = R.string.notice_room_guest_access_can_join_by_you, + thirdPartyResArgs = *arrayOf(senderName) + ) GuestAccess.Forbidden -> - if (event.isSentByCurrentUser()) { - sp.getString(R.string.notice_room_guest_access_forbidden_by_you) - } else { - sp.getString(R.string.notice_room_guest_access_forbidden, senderName) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_guest_access_forbidden, + directRoomByUserResId = R.string.notice_direct_room_guest_access_forbidden_by_you, + publicRoomResId = R.string.notice_room_guest_access_forbidden, + publicRoomByUserResId = R.string.notice_room_guest_access_forbidden_by_you, + thirdPartyResArgs = *arrayOf(senderName) + ) else -> null } } @@ -524,14 +570,25 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } Membership.JOIN -> - if (event.isSentByCurrentUser()) { - eventContent.safeReason?.let { reason -> - sp.getString(R.string.notice_room_join_with_reason_by_you, reason) - } ?: sp.getString(R.string.notice_room_join_by_you) - } else { - eventContent.safeReason?.let { reason -> - sp.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason) - } ?: sp.getString(R.string.notice_room_join, senderDisplayName) + eventContent.safeReason?.let { reason -> + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_join_with_reason, + directRoomByUserResId = R.string.notice_direct_room_join_with_reason_by_you, + publicRoomResId = R.string.notice_room_join_with_reason, + publicRoomByUserResId = R.string.notice_room_join_with_reason_by_you, + userResArgs = reason, + thirdPartyResArgs = *arrayOf(senderDisplayName, reason) + ) + } ?: run { + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_join, + directRoomByUserResId = R.string.notice_direct_room_join_by_you, + publicRoomResId = R.string.notice_room_join, + publicRoomByUserResId = R.string.notice_room_join_by_you, + thirdPartyResArgs = *arrayOf(senderDisplayName) + ) } Membership.LEAVE -> // 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked @@ -548,14 +605,25 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } ?: sp.getString(R.string.notice_room_reject, senderDisplayName) } else -> - if (event.isSentByCurrentUser()) { - eventContent.safeReason?.let { reason -> - sp.getString(R.string.notice_room_leave_with_reason_by_you, reason) - } ?: sp.getString(R.string.notice_room_leave_by_you) - } else { - eventContent.safeReason?.let { reason -> - sp.getString(R.string.notice_room_leave_with_reason, senderDisplayName, reason) - } ?: sp.getString(R.string.notice_room_leave, senderDisplayName) + eventContent.safeReason?.let { reason -> + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_leave_with_reason, + directRoomByUserResId = R.string.notice_direct_room_leave_with_reason_by_you, + publicRoomResId = R.string.notice_room_leave_with_reason, + publicRoomByUserResId = R.string.notice_room_leave_with_reason_by_you, + userResArgs = reason, + thirdPartyResArgs = *arrayOf(senderDisplayName, reason) + ) + } ?: run { + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.notice_direct_room_leave, + directRoomByUserResId = R.string.notice_direct_room_leave_by_you, + publicRoomResId = R.string.notice_room_leave, + publicRoomByUserResId = R.string.notice_room_leave_by_you, + thirdPartyResArgs = *arrayOf(senderDisplayName) + ) } } } else { @@ -622,11 +690,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val content = event.getClearContent().toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> - if (event.isSentByCurrentUser()) { - sp.getString(R.string.room_join_rules_invite_by_you) - } else { - sp.getString(R.string.room_join_rules_invite, senderName) - } + chooseResourceByRoomType( + event = event, + directRoomResId = R.string.direct_room_join_rules_invite, + directRoomByUserResId = R.string.direct_room_join_rules_invite_by_you, + publicRoomResId = R.string.room_join_rules_invite, + publicRoomByUserResId = R.string.room_join_rules_invite_by_you, + thirdPartyResArgs = *arrayOf(senderName) + ) RoomJoinRules.PUBLIC -> if (event.isSentByCurrentUser()) { sp.getString(R.string.room_join_rules_public_by_you) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt index d9dcc98ed1..1f8ad3df1b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/BasedMergedItem.kt @@ -62,7 +62,8 @@ abstract class BasedMergedItem : BaseEventItem() val eventId: String, val userId: String, val memberName: String, - val avatarUrl: String? + val avatarUrl: String?, + val isDirectRoom: Boolean ) fun Data.toMatrixItem() = MatrixItem.UserItem(userId, memberName, avatarUrl) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt index dad5f99eeb..1896a812fc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MergedRoomCreationItem.kt @@ -48,9 +48,17 @@ abstract class MergedRoomCreationItem : BasedMergedItem"Due to missing permissions, this action is not possible. You need permission to invite to start a conference in this room You do not have permission to start a conference call in this room + You do not have permission to start a conference call You do not have permission to start a call in this room + You do not have permission to start a call A conference is already in progress! Start video meeting Start audio meeting @@ -1881,6 +1883,8 @@ You made the room public to whoever knows the link. %1$s made the room invite only. You made the room invite only. + %1$s made this invite only. + You made this invite only. Unread messages It\'s your conversation. Own it. @@ -2355,11 +2359,14 @@ Encryption enabled Messages in this room are end-to-end encrypted. Learn more & verify users in their profile. + Messages in this room are end-to-end encrypted. Encryption not enabled The encryption used by this room is not supported %s created and configured the room. You created and configured the room. + %s joined. + You joined. Almost there! Is the other device showing the same shield? Almost there! Waiting for confirmation… From 3a9e6fa97fbbfa034889ec25fd8645fa7992ed10 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 28 Sep 2020 11:21:07 +0300 Subject: [PATCH 02/18] Changelog added. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index fd076e27ea..1a01d46964 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -59,6 +59,7 @@ Changes in Element 1.0.7 (2020-09-17) Improvements 🙌: - Handle date formatting properly (show time am/pm if needed, display year when needed) - Improve F-Droid Notification (#2055) + - Wording differentiation for direct rooms (#2176) Bugfix 🐛: - Clear the notification when the event is read elsewhere (#1822) From 2a96b2c68e9a142587a237f2d721c08bd993a352 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 28 Sep 2020 11:35:02 +0300 Subject: [PATCH 03/18] Differentiate wordings for the room profile screen. --- .../features/roomprofile/RoomProfileController.kt | 12 +++++++++--- vector/src/main/res/values/strings.xml | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt index 815478b46b..13efaf0d10 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt @@ -57,7 +57,7 @@ class RoomProfileController @Inject constructor( // Security buildProfileSection(stringProvider.getString(R.string.room_profile_section_security)) val learnMoreSubtitle = if (roomSummary.isEncrypted) { - R.string.room_profile_encrypted_subtitle + if (roomSummary.isDirect) R.string.direct_room_profile_encrypted_subtitle else R.string.room_profile_encrypted_subtitle } else { R.string.room_profile_not_encrypted_subtitle } @@ -71,7 +71,10 @@ class RoomProfileController @Inject constructor( buildProfileSection(stringProvider.getString(R.string.room_profile_section_more)) buildProfileAction( id = "settings", - title = stringProvider.getString(R.string.room_profile_section_more_settings), + title = if (roomSummary.isDirect) + stringProvider.getString(R.string.direct_room_profile_section_more_settings) + else + stringProvider.getString(R.string.room_profile_section_more_settings), dividerColor = dividerColor, icon = R.drawable.ic_room_profile_settings, action = { callback?.onSettingsClicked() } @@ -112,7 +115,10 @@ class RoomProfileController @Inject constructor( ) buildProfileAction( id = "leave", - title = stringProvider.getString(R.string.room_profile_section_more_leave), + title = if (roomSummary.isDirect) + stringProvider.getString(R.string.direct_room_profile_section_more_leave) + else + stringProvider.getString(R.string.room_profile_section_more_leave), dividerColor = dividerColor, divider = false, destructive = true, diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 887e78d102..d71195bf13 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2118,11 +2118,13 @@ For extra security, verify %s by checking a one-time code on both your devices.\n\nFor maximum security, do this in person. Messages in this room are not end-to-end encrypted. Messages in this room are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them. + Messages here are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them. Security Learn more More Admin Actions Room settings + Settings Notifications "One person" @@ -2130,6 +2132,7 @@ Uploads Leave Room + Leave "Leaving the room…" Admins From 07976988d9dad7eb4ad50d63ca2636363910f63e Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 28 Sep 2020 11:37:17 +0300 Subject: [PATCH 04/18] Use RoomSummary to check if the room is direct. --- .../home/room/detail/timeline/format/NoticeEventFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 64d0fdd127..4b95fd4436 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -59,7 +59,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun isDirectRoom(roomId: String?): Boolean { return roomId?.let { - activeSessionDataSource.currentValue?.orNull()?.getRoom(roomId)?.roomSummary()?.isDirect + activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(roomId)?.isDirect }.orFalse() } From 5d18a7cc829426aae44e592e5e1cb3e5a181864f Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Mon, 28 Sep 2020 12:27:06 +0300 Subject: [PATCH 05/18] Lint fixes. --- .../features/roomprofile/RoomProfileController.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt index 13efaf0d10..2c71a11136 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt @@ -71,10 +71,11 @@ class RoomProfileController @Inject constructor( buildProfileSection(stringProvider.getString(R.string.room_profile_section_more)) buildProfileAction( id = "settings", - title = if (roomSummary.isDirect) + title = if (roomSummary.isDirect) { stringProvider.getString(R.string.direct_room_profile_section_more_settings) - else - stringProvider.getString(R.string.room_profile_section_more_settings), + } else { + stringProvider.getString(R.string.room_profile_section_more_settings) + }, dividerColor = dividerColor, icon = R.drawable.ic_room_profile_settings, action = { callback?.onSettingsClicked() } @@ -115,10 +116,11 @@ class RoomProfileController @Inject constructor( ) buildProfileAction( id = "leave", - title = if (roomSummary.isDirect) + title = if (roomSummary.isDirect) { stringProvider.getString(R.string.direct_room_profile_section_more_leave) - else - stringProvider.getString(R.string.room_profile_section_more_leave), + } else { + stringProvider.getString(R.string.room_profile_section_more_leave) + }, dividerColor = dividerColor, divider = false, destructive = true, From d225fb7df02f285ce65512abdb9b10c7c9c730ef Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 10:08:26 +0200 Subject: [PATCH 06/18] Update Changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 1a01d46964..9348717fb5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Features ✨: - Improvements 🙌: + - Wording differentiation for direct rooms (#2176) - PIN code: request PIN code if phone has been locked - Small optimisation of scrolling experience in timeline (#2114) @@ -59,7 +60,6 @@ Changes in Element 1.0.7 (2020-09-17) Improvements 🙌: - Handle date formatting properly (show time am/pm if needed, display year when needed) - Improve F-Droid Notification (#2055) - - Wording differentiation for direct rooms (#2176) Bugfix 🐛: - Clear the notification when the event is read elsewhere (#1822) From b5311aa3df8a483b4ab71d14b05b692181c902fe Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 11:42:07 +0200 Subject: [PATCH 07/18] Simple code --- .../timeline/format/NoticeEventFormatter.kt | 188 ++++++------------ 1 file changed, 66 insertions(+), 122 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 4b95fd4436..baa00ef3e5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.detail.timeline.format -import androidx.annotation.StringRes import im.vector.app.ActiveSessionDataSource import im.vector.app.R import im.vector.app.core.resources.StringProvider @@ -57,26 +56,9 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId - private fun isDirectRoom(roomId: String?): Boolean { - return roomId?.let { - activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(roomId)?.isDirect - }.orFalse() - } - - private fun chooseResourceByRoomType(event: Event, - @StringRes directRoomResId: Int, - @StringRes directRoomByUserResId: Int, - @StringRes publicRoomResId: Int, - @StringRes publicRoomByUserResId: Int, - userResArgs: Any? = null, - vararg thirdPartyResArgs: Any? - ): String { - return if (isDirectRoom(event.roomId)) { - if (event.isSentByCurrentUser()) sp.getString(directRoomByUserResId, userResArgs) else sp.getString(directRoomResId, *thirdPartyResArgs) - } else { - if (event.isSentByCurrentUser()) sp.getString(publicRoomByUserResId, userResArgs) else sp.getString(publicRoomResId, *thirdPartyResArgs) - } - } + private fun Event.isDm() = roomId?.let { + activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect + }.orFalse() fun format(timelineEvent: TimelineEvent): CharSequence? { return when (val type = timelineEvent.root.getClearType()) { @@ -201,14 +183,10 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return event.getClearContent().toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_room_created_by_you, - directRoomByUserResId = R.string.notice_direct_room_created_by_you, - publicRoomResId = R.string.notice_room_created, - publicRoomByUserResId = R.string.notice_room_created_by_you, - thirdPartyResArgs = *arrayOf(it.creator) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_room_created_by_you else R.string.notice_room_created, it.creator) } } @@ -230,14 +208,10 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } private fun formatRoomTombstoneEvent(event: Event, senderName: String?): CharSequence? { - return chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_update, - directRoomByUserResId = R.string.notice_direct_room_update_by_you, - publicRoomResId = R.string.notice_room_update, - publicRoomByUserResId = R.string.notice_room_update_by_you, - thirdPartyResArgs = *arrayOf(senderName) - ) + return if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) } private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? { @@ -278,15 +252,12 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) - return chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_made_future_direct_room_visibility, - directRoomByUserResId = R.string.notice_made_future_direct_room_visibility_by_you, - publicRoomResId = R.string.notice_made_future_room_visibility, - publicRoomByUserResId = R.string.notice_made_future_room_visibility_by_you, - userResArgs = formattedVisibility, - thirdPartyResArgs = *arrayOf(senderName, formattedVisibility) - ) + return if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, + formattedVisibility) + else + sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, + senderName, formattedVisibility) } private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? { @@ -296,27 +267,21 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return when { prevContent != null -> { // Revoke case - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_third_party_revoked_invite, - directRoomByUserResId = R.string.notice_direct_room_third_party_revoked_invite_by_you, - publicRoomResId = R.string.notice_room_third_party_revoked_invite, - publicRoomByUserResId = R.string.notice_room_third_party_revoked_invite_by_you, - userResArgs = prevContent.displayName, - thirdPartyResArgs = *arrayOf(senderName, prevContent.displayName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite_by_you else R.string.notice_room_third_party_revoked_invite_by_you, + prevContent.displayName) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, + senderName, prevContent.displayName) } content != null -> { // Invitation case - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_third_party_invite, - directRoomByUserResId = R.string.notice_direct_room_third_party_invite_by_you, - publicRoomResId = R.string.notice_room_third_party_invite, - publicRoomByUserResId = R.string.notice_room_third_party_invite_by_you, - userResArgs = content.displayName, - thirdPartyResArgs = *arrayOf(senderName, content.displayName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, + content.displayName) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, + senderName, content.displayName) } else -> null } @@ -431,23 +396,17 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_guest_access_can_join, - directRoomByUserResId = R.string.notice_direct_room_guest_access_can_join_by_you, - publicRoomResId = R.string.notice_room_guest_access_can_join, - publicRoomByUserResId = R.string.notice_room_guest_access_can_join_by_you, - thirdPartyResArgs = *arrayOf(senderName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, + senderName) GuestAccess.Forbidden -> - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_guest_access_forbidden, - directRoomByUserResId = R.string.notice_direct_room_guest_access_forbidden_by_you, - publicRoomResId = R.string.notice_room_guest_access_forbidden, - publicRoomByUserResId = R.string.notice_room_guest_access_forbidden_by_you, - thirdPartyResArgs = *arrayOf(senderName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, + senderName) else -> null } } @@ -571,24 +530,18 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } Membership.JOIN -> eventContent.safeReason?.let { reason -> - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_join_with_reason, - directRoomByUserResId = R.string.notice_direct_room_join_with_reason_by_you, - publicRoomResId = R.string.notice_room_join_with_reason, - publicRoomByUserResId = R.string.notice_room_join_with_reason_by_you, - userResArgs = reason, - thirdPartyResArgs = *arrayOf(senderDisplayName, reason) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, + reason) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, + senderDisplayName, reason) } ?: run { - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_join, - directRoomByUserResId = R.string.notice_direct_room_join_by_you, - publicRoomResId = R.string.notice_room_join, - publicRoomByUserResId = R.string.notice_room_join_by_you, - thirdPartyResArgs = *arrayOf(senderDisplayName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, + senderDisplayName) } Membership.LEAVE -> // 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked @@ -606,24 +559,18 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } else -> eventContent.safeReason?.let { reason -> - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_leave_with_reason, - directRoomByUserResId = R.string.notice_direct_room_leave_with_reason_by_you, - publicRoomResId = R.string.notice_room_leave_with_reason, - publicRoomByUserResId = R.string.notice_room_leave_with_reason_by_you, - userResArgs = reason, - thirdPartyResArgs = *arrayOf(senderDisplayName, reason) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason_by_you else R.string.notice_room_leave_with_reason_by_you, + reason) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, + senderDisplayName, reason) } ?: run { - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.notice_direct_room_leave, - directRoomByUserResId = R.string.notice_direct_room_leave_by_you, - publicRoomResId = R.string.notice_room_leave, - publicRoomByUserResId = R.string.notice_room_leave_by_you, - thirdPartyResArgs = *arrayOf(senderDisplayName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) + else + sp.getString(if (event.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, + senderDisplayName) } } } else { @@ -690,14 +637,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val content = event.getClearContent().toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> - chooseResourceByRoomType( - event = event, - directRoomResId = R.string.direct_room_join_rules_invite, - directRoomByUserResId = R.string.direct_room_join_rules_invite_by_you, - publicRoomResId = R.string.room_join_rules_invite, - publicRoomByUserResId = R.string.room_join_rules_invite_by_you, - thirdPartyResArgs = *arrayOf(senderName) - ) + if (event.isSentByCurrentUser()) + sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) + else + sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, + senderName) RoomJoinRules.PUBLIC -> if (event.isSentByCurrentUser()) { sp.getString(R.string.room_join_rules_public_by_you) From 2f054cd438579bb6c66c4a5117e5298b08f5a086 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 11:45:21 +0200 Subject: [PATCH 08/18] Fix mistake --- .../home/room/detail/timeline/format/NoticeEventFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index baa00ef3e5..866058c8ba 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -186,7 +186,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour if (event.isSentByCurrentUser()) sp.getString(if (event.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) else - sp.getString(if (event.isDm()) R.string.notice_room_created_by_you else R.string.notice_room_created, it.creator) + sp.getString(if (event.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) } } From 14162ecaa0ef94565abf1f0772b2a938a9a275b8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 11:47:37 +0200 Subject: [PATCH 09/18] Add missing case --- .../im/vector/app/features/roomprofile/RoomProfileController.kt | 2 +- vector/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt index 2c71a11136..0d88563be9 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt @@ -59,7 +59,7 @@ class RoomProfileController @Inject constructor( val learnMoreSubtitle = if (roomSummary.isEncrypted) { if (roomSummary.isDirect) R.string.direct_room_profile_encrypted_subtitle else R.string.room_profile_encrypted_subtitle } else { - R.string.room_profile_not_encrypted_subtitle + if (roomSummary.isDirect) R.string.direct_room_profile_not_encrypted_subtitle else R.string.room_profile_not_encrypted_subtitle } genericFooterItem { id("e2e info") diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index d71195bf13..68d42e8356 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2117,6 +2117,7 @@ Waiting for %s… For extra security, verify %s by checking a one-time code on both your devices.\n\nFor maximum security, do this in person. Messages in this room are not end-to-end encrypted. + Messages here are not end-to-end encrypted. Messages in this room are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them. Messages here are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them. Security From 07446d2d41d0d16d578bfa1b160df77bece5ee16 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 11:50:07 +0200 Subject: [PATCH 10/18] Embedded if --- .../roomprofile/RoomProfileController.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt index 0d88563be9..ccfbf6d4fa 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt @@ -18,7 +18,6 @@ package im.vector.app.features.roomprofile import com.airbnb.epoxy.TypedEpoxyController -import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel import im.vector.app.R import im.vector.app.core.epoxy.profiles.buildProfileAction import im.vector.app.core.epoxy.profiles.buildProfileSection @@ -26,6 +25,7 @@ import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider import im.vector.app.core.ui.list.genericFooterItem import im.vector.app.features.settings.VectorPreferences +import org.matrix.android.sdk.api.crypto.RoomEncryptionTrustLevel import javax.inject.Inject class RoomProfileController @Inject constructor( @@ -71,11 +71,11 @@ class RoomProfileController @Inject constructor( buildProfileSection(stringProvider.getString(R.string.room_profile_section_more)) buildProfileAction( id = "settings", - title = if (roomSummary.isDirect) { - stringProvider.getString(R.string.direct_room_profile_section_more_settings) + title = stringProvider.getString(if (roomSummary.isDirect) { + R.string.direct_room_profile_section_more_settings } else { - stringProvider.getString(R.string.room_profile_section_more_settings) - }, + R.string.room_profile_section_more_settings + }), dividerColor = dividerColor, icon = R.drawable.ic_room_profile_settings, action = { callback?.onSettingsClicked() } @@ -116,11 +116,11 @@ class RoomProfileController @Inject constructor( ) buildProfileAction( id = "leave", - title = if (roomSummary.isDirect) { - stringProvider.getString(R.string.direct_room_profile_section_more_leave) + title = stringProvider.getString(if (roomSummary.isDirect) { + R.string.direct_room_profile_section_more_leave } else { - stringProvider.getString(R.string.room_profile_section_more_leave) - }, + R.string.room_profile_section_more_leave + }), dividerColor = dividerColor, divider = false, destructive = true, From 84202adc5b3a85aa2418e51d580b5f318ad84ea5 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 11:54:23 +0200 Subject: [PATCH 11/18] Add braces to multiline if else --- .../timeline/format/NoticeEventFormatter.kt | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 866058c8ba..84cb1d7817 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -183,10 +183,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return event.getClearContent().toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) + } } } @@ -208,10 +209,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } private fun formatRoomTombstoneEvent(event: Event, senderName: String?): CharSequence? { - return if (event.isSentByCurrentUser()) + return if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) + } } private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? { @@ -252,12 +254,13 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) - return if (event.isSentByCurrentUser()) + return if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, formattedVisibility) - else + } else { sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, senderName, formattedVisibility) + } } private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? { @@ -267,21 +270,23 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return when { prevContent != null -> { // Revoke case - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite_by_you else R.string.notice_room_third_party_revoked_invite_by_you, prevContent.displayName) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, senderName, prevContent.displayName) + } } content != null -> { // Invitation case - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, content.displayName) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, senderName, content.displayName) + } } else -> null } @@ -396,17 +401,19 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, senderName) + } GuestAccess.Forbidden -> - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, senderName) + } else -> null } } @@ -530,18 +537,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } Membership.JOIN -> eventContent.safeReason?.let { reason -> - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, reason) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, senderDisplayName, reason) + } } ?: run { - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, senderDisplayName) + } } Membership.LEAVE -> // 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked @@ -559,18 +568,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } else -> eventContent.safeReason?.let { reason -> - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason_by_you else R.string.notice_room_leave_with_reason_by_you, reason) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, senderDisplayName, reason) + } } ?: run { - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, senderDisplayName) + } } } } else { @@ -637,11 +648,12 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour val content = event.getClearContent().toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> - if (event.isSentByCurrentUser()) + if (event.isSentByCurrentUser()) { sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) - else + } else { sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, senderName) + } RoomJoinRules.PUBLIC -> if (event.isSentByCurrentUser()) { sp.getString(R.string.room_join_rules_public_by_you) From 1986de36a697c01aabcac4bc409956dd79880ef6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 12:12:44 +0200 Subject: [PATCH 12/18] Better wording for DM creation (note: this event is hidden in the timeline by default) --- matrix-sdk-android/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/res/values/strings.xml b/matrix-sdk-android/src/main/res/values/strings.xml index 70a7461fe9..3f75b715f6 100644 --- a/matrix-sdk-android/src/main/res/values/strings.xml +++ b/matrix-sdk-android/src/main/res/values/strings.xml @@ -10,8 +10,8 @@ Your invitation %1$s created the room You created the room - %1$s joined - You joined + %1$s created the discussion + You created the discussion %1$s invited %2$s You invited %1$s %1$s invited you From 42a3a64b0d596e3765222eeb02685a279ece3435 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 12:26:25 +0200 Subject: [PATCH 13/18] Better way to get direct state of the room (using view state) --- .../home/room/detail/RoomDetailFragment.kt | 24 +++++++++++-------- .../home/room/detail/RoomDetailViewState.kt | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index b31af30609..3b4795b965 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -704,11 +704,13 @@ class RoomDetailFragment @Inject constructor( // safeStartCall(it, isVideoCall) // } } else if (!state.isAllowedToStartWebRTCCall) { - if (session.getRoom(state.roomId)?.roomSummary()?.isDirect == true) { - showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call_in_direct_room)) - } else { - showDialogWithMessage(getString(R.string.no_permissions_to_start_webrtc_call)) - } + showDialogWithMessage(getString( + if (state.isDm()) { + R.string.no_permissions_to_start_webrtc_call_in_direct_room + } else { + R.string.no_permissions_to_start_webrtc_call + }) + ) } else { safeStartCall(isVideoCall) } @@ -718,11 +720,13 @@ class RoomDetailFragment @Inject constructor( // can you add widgets?? if (!state.isAllowedToManageWidgets) { // You do not have permission to start a conference call in this room - if (session.getRoom(state.roomId)?.roomSummary()?.isDirect == true) { - showDialogWithMessage(getString(R.string.no_permissions_to_start_conf_call_in_direct_room)) - } else { - showDialogWithMessage(getString(R.string.no_permissions_to_start_conf_call)) - } + showDialogWithMessage(getString( + if (state.isDm()) { + R.string.no_permissions_to_start_conf_call_in_direct_room + } else { + R.string.no_permissions_to_start_conf_call + } + )) } else { if (state.activeRoomWidgets()?.filter { it.type == WidgetType.Jitsi }?.any() == true) { // A conference is already in progress! diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt index 16a7379b6a..36acc35148 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewState.kt @@ -77,4 +77,6 @@ data class RoomDetailViewState( // Also highlight the target event, if any highlightedEventId = args.eventId ) + + fun isDm() = asyncRoomSummary()?.isDirect == true } From f58829130a4526d084d0a6ad3af3b8744438aa82 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 12:30:21 +0200 Subject: [PATCH 14/18] More cleanup --- .../detail/timeline/factory/EncryptionItemFactory.kt | 12 +++++++----- .../detail/timeline/factory/TimelineItemFactory.kt | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt index 2ed88cbae9..4f2c8ea63a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/EncryptionItemFactory.kt @@ -54,11 +54,13 @@ class EncryptionItemFactory @Inject constructor( val shield: StatusTileTimelineItem.ShieldUIState if (isSafeAlgorithm) { title = stringProvider.getString(R.string.encryption_enabled) - description = if (session.getRoomSummary(event.root.roomId ?: "")?.isDirect.orFalse()) { - stringProvider.getString(R.string.direct_room_encryption_enabled_tile_description) - } else { - stringProvider.getString(R.string.encryption_enabled_tile_description) - } + description = stringProvider.getString( + if (session.getRoomSummary(event.root.roomId ?: "")?.isDirect.orFalse()) { + R.string.direct_room_encryption_enabled_tile_description + } else { + R.string.encryption_enabled_tile_description + } + ) shield = StatusTileTimelineItem.ShieldUIState.BLACK } else { title = stringProvider.getString(R.string.encryption_not_enabled) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt index 1f99efd08e..a2e01e63cd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt @@ -64,9 +64,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me EventType.STATE_ROOM_POWER_LEVELS, EventType.REACTION, EventType.REDACTION -> noticeItemFactory.create(event, highlight, callback) - EventType.STATE_ROOM_ENCRYPTION -> { - encryptionItemFactory.create(event, highlight, callback) - } + EventType.STATE_ROOM_ENCRYPTION -> encryptionItemFactory.create(event, highlight, callback) // State room create EventType.STATE_ROOM_CREATE -> roomCreateItemFactory.create(event, callback) // Crypto From c5459cdde4b537e3df54b0a9472e085b83b4e9eb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 12:39:36 +0200 Subject: [PATCH 15/18] Use RoomSummaryHolder if available --- .../timeline/factory/MergedHeaderItemFactory.kt | 14 ++++++-------- .../timeline/format/NoticeEventFormatter.kt | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt index 41a961dee0..08f93b23cd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MergedHeaderItemFactory.kt @@ -22,6 +22,7 @@ import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider import im.vector.app.features.home.room.detail.timeline.helper.MergedTimelineEventVisibilityStateChangedListener +import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder import im.vector.app.features.home.room.detail.timeline.helper.canBeMerged import im.vector.app.features.home.room.detail.timeline.helper.isRoomConfiguration import im.vector.app.features.home.room.detail.timeline.helper.prevSameTypeEvents @@ -46,6 +47,7 @@ import javax.inject.Inject class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolder: ActiveSessionHolder, private val avatarRenderer: AvatarRenderer, private val avatarSizeProvider: AvatarSizeProvider, + private val roomSummaryHolder: RoomSummaryHolder, private val vectorPreferences: VectorPreferences) { private val collapsedEventIds = linkedSetOf() @@ -79,11 +81,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde } } - private fun isDirectRoom(roomId: String?): Boolean { - return roomId?.let { - activeSessionHolder.getSafeActiveSession()?.getRoom(roomId)?.roomSummary()?.isDirect - }.orFalse() - } + private fun isDirectRoom() = roomSummaryHolder.roomSummary?.isDirect.orFalse() private fun buildMembershipEventsMergedSummary(currentPosition: Int, items: List, @@ -108,7 +106,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } @@ -196,7 +194,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = senderName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } @@ -257,7 +255,7 @@ class MergedHeaderItemFactory @Inject constructor(private val activeSessionHolde memberName = mergedEvent.senderInfo.disambiguatedDisplayName, localId = mergedEvent.localId, eventId = mergedEvent.root.eventId ?: "", - isDirectRoom = isDirectRoom(mergedEvent.root.roomId) + isDirectRoom = isDirectRoom() ) mergedData.add(data) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 84cb1d7817..34b4cac5b4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -19,6 +19,7 @@ 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.home.room.detail.timeline.helper.RoomSummaryHolder 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 @@ -49,6 +50,7 @@ import javax.inject.Inject class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, + private val roomSummaryHolder: RoomSummaryHolder, private val sp: StringProvider) { private val currentUserId: String? @@ -56,9 +58,16 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId - private fun Event.isDm() = roomId?.let { - activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect - }.orFalse() + private fun Event.isDm(): Boolean { + return roomSummaryHolder.roomSummary?.isDirect + ?: run { + // RoomSummaryHolder does not have any RoomSummary (not in the timeline) + roomId?.let { + activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect + } + } + .orFalse() + } fun format(timelineEvent: TimelineEvent): CharSequence? { return when (val type = timelineEvent.root.getClearType()) { From 5e2f65ab7abdd15e734bf2f87b797c085e2ed0ba Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 12:46:28 +0200 Subject: [PATCH 16/18] Split long lines --- .../timeline/format/NoticeEventFormatter.kt | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 34b4cac5b4..45567196f9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -280,7 +280,12 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour prevContent != null -> { // Revoke case if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite_by_you else R.string.notice_room_third_party_revoked_invite_by_you, + sp.getString( + if (event.isDm()) { + R.string.notice_direct_room_third_party_revoked_invite_by_you + } else { + R.string.notice_room_third_party_revoked_invite_by_you + }, prevContent.displayName) } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, @@ -411,14 +416,18 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you) + sp.getString( + if (event.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you + ) } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, senderName) } GuestAccess.Forbidden -> if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you) + sp.getString( + if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you + ) } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, senderName) @@ -578,8 +587,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour else -> eventContent.safeReason?.let { reason -> if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason_by_you else R.string.notice_room_leave_with_reason_by_you, - reason) + sp.getString( + if (event.isDm()) { + R.string.notice_direct_room_leave_with_reason_by_you + } else { + R.string.notice_room_leave_with_reason_by_you + }, + reason + ) } else { sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, senderDisplayName, reason) From 7f26dbe260f624a0779cf4000dc7494c775cdcea Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 15:19:23 +0200 Subject: [PATCH 17/18] Fix compil issue --- .../action/MessageActionsViewModel.kt | 2 +- .../timeline/factory/MessageItemFactory.kt | 6 +- .../timeline/factory/NoticeItemFactory.kt | 4 +- .../timeline/factory/RoomCreateItemFactory.kt | 4 +- .../timeline/factory/TimelineItemFactory.kt | 6 +- .../factory/VerificationItemFactory.kt | 4 +- .../format/DisplayableEventFormatter.kt | 5 +- .../timeline/format/NoticeEventFormatter.kt | 108 ++++++++---------- .../home/room/list/RoomSummaryItemFactory.kt | 2 +- .../notifications/NotifiableEventResolver.kt | 6 +- 10 files changed, 74 insertions(+), 73 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index a49b74c243..8a25e5fc93 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -190,7 +190,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted EventType.CALL_CANDIDATES, EventType.CALL_HANGUP, EventType.CALL_ANSWER -> { - noticeEventFormatter.format(timelineEvent) + noticeEventFormatter.format(timelineEvent, room?.roomSummary()) } else -> null } ?: "" diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 97bc693f26..1e809d9ab5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -38,6 +38,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadSt import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory +import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder import im.vector.app.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider import im.vector.app.features.home.room.detail.timeline.item.AbsMessageItem import im.vector.app.features.home.room.detail.timeline.item.MessageBlockCodeItem @@ -101,6 +102,7 @@ class MessageItemFactory @Inject constructor( private val messageItemAttributesFactory: MessageItemAttributesFactory, private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder, private val contentDownloadStateTrackerBinder: ContentDownloadStateTrackerBinder, + private val roomSummaryHolder: RoomSummaryHolder, private val defaultItemFactory: DefaultItemFactory, private val noticeItemFactory: NoticeItemFactory, private val avatarSizeProvider: AvatarSizeProvider, @@ -130,7 +132,7 @@ class MessageItemFactory @Inject constructor( || event.isEncrypted() && event.root.content.toModel()?.relatesTo?.type == RelationType.REPLACE ) { // This is an edit event, we should display it when debugging as a notice event - return noticeItemFactory.create(event, highlight, callback) + return noticeItemFactory.create(event, highlight, roomSummaryHolder.roomSummary, callback) } val attributes = messageItemAttributesFactory.create(messageContent, informationData, callback) @@ -146,7 +148,7 @@ class MessageItemFactory @Inject constructor( is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, highlight, attributes) is MessageVerificationRequestContent -> buildVerificationRequestMessageItem(messageContent, informationData, highlight, callback, attributes) is MessageOptionsContent -> buildOptionsMessageItem(messageContent, informationData, highlight, callback, attributes) - is MessagePollResponseContent -> noticeItemFactory.create(event, highlight, callback) + is MessagePollResponseContent -> noticeItemFactory.create(event, highlight, roomSummaryHolder.roomSummary, callback) else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/NoticeItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/NoticeItemFactory.kt index cd8c682f39..ec065543f5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/NoticeItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/NoticeItemFactory.kt @@ -24,6 +24,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvide import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory import im.vector.app.features.home.room.detail.timeline.item.NoticeItem import im.vector.app.features.home.room.detail.timeline.item.NoticeItem_ +import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import javax.inject.Inject @@ -34,8 +35,9 @@ class NoticeItemFactory @Inject constructor(private val eventFormatter: NoticeEv fun create(event: TimelineEvent, highlight: Boolean, + roomSummary: RoomSummary?, callback: TimelineEventController.Callback?): NoticeItem? { - val formattedText = eventFormatter.format(event) ?: return null + val formattedText = eventFormatter.format(event, roomSummary) ?: return null val informationData = informationDataFactory.create(event, null) val attributes = NoticeItem.Attributes( avatarRenderer = avatarRenderer, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt index 31adbdb8a6..25b5fd718b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/RoomCreateItemFactory.kt @@ -21,6 +21,7 @@ import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.UserPreferencesProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController +import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder import im.vector.app.features.home.room.detail.timeline.item.RoomCreateItem_ import me.gujun.android.span.span import org.matrix.android.sdk.api.session.Session @@ -32,6 +33,7 @@ import javax.inject.Inject class RoomCreateItemFactory @Inject constructor(private val stringProvider: StringProvider, private val userPreferencesProvider: UserPreferencesProvider, private val session: Session, + private val roomSummaryHolder: RoomSummaryHolder, private val noticeItemFactory: NoticeItemFactory) { fun create(event: TimelineEvent, callback: TimelineEventController.Callback?): VectorEpoxyModel<*>? { @@ -52,7 +54,7 @@ class RoomCreateItemFactory @Inject constructor(private val stringProvider: Stri private fun defaultRendering(event: TimelineEvent, callback: TimelineEventController.Callback?): VectorEpoxyModel<*>? { return if (userPreferencesProvider.shouldShowHiddenEvents()) { - noticeItemFactory.create(event, false, callback) + noticeItemFactory.create(event, false, roomSummaryHolder.roomSummary, callback) } else { null } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt index a2e01e63cd..40286678c8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineItemFactory.kt @@ -20,6 +20,7 @@ import im.vector.app.core.epoxy.EmptyItem_ import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.resources.UserPreferencesProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController +import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import timber.log.Timber @@ -31,6 +32,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me private val defaultItemFactory: DefaultItemFactory, private val encryptionItemFactory: EncryptionItemFactory, private val roomCreateItemFactory: RoomCreateItemFactory, + private val roomSummaryHolder: RoomSummaryHolder, private val verificationConclusionItemFactory: VerificationItemFactory, private val userPreferencesProvider: UserPreferencesProvider) { @@ -63,7 +65,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me EventType.CALL_ANSWER, EventType.STATE_ROOM_POWER_LEVELS, EventType.REACTION, - EventType.REDACTION -> noticeItemFactory.create(event, highlight, callback) + EventType.REDACTION -> noticeItemFactory.create(event, highlight, roomSummaryHolder.roomSummary, callback) EventType.STATE_ROOM_ENCRYPTION -> encryptionItemFactory.create(event, highlight, callback) // State room create EventType.STATE_ROOM_CREATE -> roomCreateItemFactory.create(event, callback) @@ -85,7 +87,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me // TODO These are not filtered out by timeline when encrypted // For now manually ignore if (userPreferencesProvider.shouldShowHiddenEvents()) { - noticeItemFactory.create(event, highlight, callback) + noticeItemFactory.create(event, highlight, roomSummaryHolder.roomSummary, callback) } else { null } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt index 0b623d78f1..59daf5a0a0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/VerificationItemFactory.kt @@ -24,6 +24,7 @@ import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory +import im.vector.app.features.home.room.detail.timeline.helper.RoomSummaryHolder import im.vector.app.features.home.room.detail.timeline.item.StatusTileTimelineItem import im.vector.app.features.home.room.detail.timeline.item.StatusTileTimelineItem_ import org.matrix.android.sdk.api.session.Session @@ -50,6 +51,7 @@ class VerificationItemFactory @Inject constructor( private val avatarSizeProvider: AvatarSizeProvider, private val noticeItemFactory: NoticeItemFactory, private val userPreferencesProvider: UserPreferencesProvider, + private val roomSummaryHolder: RoomSummaryHolder, private val stringProvider: StringProvider, private val session: Session ) { @@ -151,7 +153,7 @@ class VerificationItemFactory @Inject constructor( highlight: Boolean, callback: TimelineEventController.Callback? ): VectorEpoxyModel<*>? { - if (userPreferencesProvider.shouldShowHiddenEvents()) return noticeItemFactory.create(event, highlight, callback) + if (userPreferencesProvider.shouldShowHiddenEvents()) return noticeItemFactory.create(event, highlight, roomSummaryHolder.roomSummary, callback) return null } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt index cb9f583a2a..78d9a49c9c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/DisplayableEventFormatter.kt @@ -23,6 +23,7 @@ import im.vector.app.core.resources.StringProvider import me.gujun.android.span.span 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.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent import org.matrix.android.sdk.api.session.room.model.message.MessageType import org.matrix.android.sdk.api.session.room.model.message.OPTION_TYPE_BUTTONS @@ -40,7 +41,7 @@ class DisplayableEventFormatter @Inject constructor( private val noticeEventFormatter: NoticeEventFormatter ) { - fun format(timelineEvent: TimelineEvent, appendAuthor: Boolean): CharSequence { + fun format(timelineEvent: TimelineEvent, appendAuthor: Boolean, roomSummary: RoomSummary?): CharSequence { if (timelineEvent.root.isRedacted()) { return noticeEventFormatter.formatRedactedEvent(timelineEvent.root) } @@ -130,7 +131,7 @@ class DisplayableEventFormatter @Inject constructor( } else -> { return span { - text = noticeEventFormatter.format(timelineEvent) ?: "" + text = noticeEventFormatter.format(timelineEvent, roomSummary) ?: "" textStyle = "italic" } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 45567196f9..1d20bc3ad5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -19,7 +19,6 @@ 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.home.room.detail.timeline.helper.RoomSummaryHolder 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 @@ -36,6 +35,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.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomThirdPartyInviteContent import org.matrix.android.sdk.api.session.room.model.RoomTopicContent import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent @@ -50,7 +50,6 @@ import javax.inject.Inject class NoticeEventFormatter @Inject constructor(private val activeSessionDataSource: ActiveSessionDataSource, private val roomHistoryVisibilityFormatter: RoomHistoryVisibilityFormatter, - private val roomSummaryHolder: RoomSummaryHolder, private val sp: StringProvider) { private val currentUserId: String? @@ -58,34 +57,25 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun Event.isSentByCurrentUser() = senderId != null && senderId == currentUserId - private fun Event.isDm(): Boolean { - return roomSummaryHolder.roomSummary?.isDirect - ?: run { - // RoomSummaryHolder does not have any RoomSummary (not in the timeline) - roomId?.let { - activeSessionDataSource.currentValue?.orNull()?.getRoomSummary(it)?.isDirect - } - } - .orFalse() - } + private fun RoomSummary?.isDm() = this?.isDirect.orFalse() - fun format(timelineEvent: TimelineEvent): CharSequence? { + fun format(timelineEvent: TimelineEvent, roomSummary: RoomSummary?): CharSequence? { return when (val type = timelineEvent.root.getClearType()) { - EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_CREATE -> formatRoomCreateEvent(timelineEvent.root) + EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) + EventType.STATE_ROOM_CREATE -> formatRoomCreateEvent(timelineEvent.root, roomSummary) EventType.STATE_ROOM_NAME -> formatRoomNameEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_AVATAR -> formatRoomAvatarEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) + EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) + EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary ) EventType.STATE_ROOM_ALIASES -> formatRoomAliasesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) + EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) + EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) EventType.STATE_ROOM_ENCRYPTION -> formatRoomEncryptionEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_WIDGET, EventType.STATE_ROOM_WIDGET_LEGACY -> formatWidgetEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) + EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) EventType.STATE_ROOM_POWER_LEVELS -> formatRoomPowerLevels(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.CALL_INVITE, EventType.CALL_CANDIDATES, @@ -164,19 +154,19 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - fun format(event: Event, senderName: String?): CharSequence? { + fun format(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { return when (val type = event.getClearType()) { - EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName) + EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName, roomSummary) EventType.STATE_ROOM_NAME -> formatRoomNameEvent(event, senderName) EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(event, senderName) EventType.STATE_ROOM_AVATAR -> formatRoomAvatarEvent(event, senderName) - EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(event, senderName) - EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(event, senderName) - EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(event, senderName) + EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(event, senderName, roomSummary) + EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(event, senderName, roomSummary) + EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(event, senderName, roomSummary) EventType.CALL_INVITE, EventType.CALL_HANGUP, EventType.CALL_ANSWER -> formatCallEvent(type, event, senderName) - EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(event, senderName) + EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(event, senderName, roomSummary) else -> { Timber.v("Type $type not handled by this formatter") null @@ -188,14 +178,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return "{ \"type\": ${event.getClearType()} }" } - private fun formatRoomCreateEvent(event: Event): CharSequence? { + private fun formatRoomCreateEvent(event: Event, roomSummary: RoomSummary?): CharSequence? { return event.getClearContent().toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) } } } @@ -217,11 +207,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomTombstoneEvent(event: Event, senderName: String?): CharSequence? { + private fun formatRoomTombstoneEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { return if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) } } @@ -259,20 +249,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? { + private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) return if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, + sp.getString(if (roomSummary.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, formattedVisibility) } else { - sp.getString(if (event.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, + sp.getString(if (roomSummary.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, senderName, formattedVisibility) } } - private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? { + private fun formatRoomThirdPartyInvite(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { val content = event.getClearContent().toModel() val prevContent = event.resolvedPrevContent()?.toModel() @@ -281,24 +271,24 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour // Revoke case if (event.isSentByCurrentUser()) { sp.getString( - if (event.isDm()) { + if (roomSummary.isDm()) { R.string.notice_direct_room_third_party_revoked_invite_by_you } else { R.string.notice_room_third_party_revoked_invite_by_you }, prevContent.displayName) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, senderName, prevContent.displayName) } } content != null -> { // Invitation case if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, content.displayName) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, senderName, content.displayName) } } @@ -347,13 +337,13 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomMemberEvent(event: Event, senderName: String?): String? { + private fun formatRoomMemberEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): String? { val eventContent: RoomMemberContent? = event.getClearContent().toModel() val prevEventContent: RoomMemberContent? = event.resolvedPrevContent().toModel() val isMembershipEvent = prevEventContent?.membership != eventContent?.membership || eventContent?.membership == Membership.LEAVE return if (isMembershipEvent) { - buildMembershipNotice(event, senderName, eventContent, prevEventContent) + buildMembershipNotice(event, senderName, eventContent, prevEventContent, roomSummary) } else { buildProfileNotice(event, senderName, eventContent, prevEventContent) } @@ -411,25 +401,25 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomGuestAccessEvent(event: Event, senderName: String?): String? { + private fun formatRoomGuestAccessEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): String? { val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> if (event.isSentByCurrentUser()) { sp.getString( - if (event.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you + if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you ) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, senderName) } GuestAccess.Forbidden -> if (event.isSentByCurrentUser()) { sp.getString( - if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you + if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you ) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, senderName) } else -> null @@ -506,7 +496,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return displayText.toString() } - private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMemberContent?, prevEventContent: RoomMemberContent?): String? { + private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMemberContent?, prevEventContent: RoomMemberContent?, roomSummary: RoomSummary?): String? { val senderDisplayName = senderName ?: event.senderId ?: "" val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: event.stateKey ?: "" return when (eventContent?.membership) { @@ -556,17 +546,17 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour Membership.JOIN -> eventContent.safeReason?.let { reason -> if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, reason) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, senderDisplayName, reason) } } ?: run { if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, senderDisplayName) } } @@ -588,7 +578,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour eventContent.safeReason?.let { reason -> if (event.isSentByCurrentUser()) { sp.getString( - if (event.isDm()) { + if (roomSummary.isDm()) { R.string.notice_direct_room_leave_with_reason_by_you } else { R.string.notice_room_leave_with_reason_by_you @@ -596,14 +586,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour reason ) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, senderDisplayName, reason) } } ?: run { if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) } else { - sp.getString(if (event.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, + sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, senderDisplayName) } } @@ -668,14 +658,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatJoinRulesEvent(event: Event, senderName: String?): CharSequence? { + private fun formatJoinRulesEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { val content = event.getClearContent().toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> if (event.isSentByCurrentUser()) { - sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) + sp.getString(if (roomSummary.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) } else { - sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, + sp.getString(if (roomSummary.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, senderName) } RoomJoinRules.PUBLIC -> diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 06cb0172d0..7bb9940ec4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -86,7 +86,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor var latestEventTime: CharSequence = "" val latestEvent = roomSummary.latestPreviewableEvent if (latestEvent != null) { - latestFormattedEvent = displayableEventFormatter.format(latestEvent, roomSummary.isDirect.not()) + latestFormattedEvent = displayableEventFormatter.format(latestEvent, roomSummary.isDirect.not(), roomSummary) latestEventTime = dateFormatter.format(latestEvent.root.originServerTs, DateFormatKind.ROOM_LIST) } val typingMessage = typingHelper.getTypingMessage(roomSummary.typingUsers) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt index 649dbd89f9..0740295191 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt @@ -91,7 +91,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St if (room == null) { Timber.e("## Unable to resolve room for eventId [$event]") // Ok room is not known in store, but we can still display something - val body = displayableEventFormatter.format(event, false) + val body = displayableEventFormatter.format(event, false, null) val roomName = stringProvider.getString(R.string.notification_unknown_room_name) val senderDisplayName = event.senderInfo.disambiguatedDisplayName @@ -124,7 +124,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St } } - val body = displayableEventFormatter.format(event, false).toString() + val body = displayableEventFormatter.format(event, false, room.roomSummary()).toString() val roomName = room.roomSummary()?.displayName ?: "" val senderDisplayName = event.senderInfo.disambiguatedDisplayName @@ -165,7 +165,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St val roomId = event.roomId ?: return null val dName = event.senderId?.let { session.getUser(it)?.displayName } if (Membership.INVITE == content.membership) { - val body = noticeEventFormatter.format(event, dName) + val body = noticeEventFormatter.format(event, dName, session.getRoomSummary(roomId)) ?: stringProvider.getString(R.string.notification_new_invitation) return InviteNotifiableEvent( session.myUserId, From 108a31eca338ffe975a490053df95d6cc3096550 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 30 Sep 2020 15:31:33 +0200 Subject: [PATCH 18/18] Avoid long lines --- .../timeline/format/NoticeEventFormatter.kt | 99 ++++++++++--------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index 1d20bc3ad5..e26472feb0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -59,23 +59,24 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour private fun RoomSummary?.isDm() = this?.isDirect.orFalse() - fun format(timelineEvent: TimelineEvent, roomSummary: RoomSummary?): CharSequence? { + fun format(timelineEvent: TimelineEvent, rs: RoomSummary?): CharSequence? { return when (val type = timelineEvent.root.getClearType()) { - EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) - EventType.STATE_ROOM_CREATE -> formatRoomCreateEvent(timelineEvent.root, roomSummary) + EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs) + EventType.STATE_ROOM_CREATE -> formatRoomCreateEvent(timelineEvent.root, rs) EventType.STATE_ROOM_NAME -> formatRoomNameEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_AVATAR -> formatRoomAvatarEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) - EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary ) + EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs) + EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs) EventType.STATE_ROOM_ALIASES -> formatRoomAliasesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.STATE_ROOM_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) - EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) + EventType.STATE_ROOM_HISTORY_VISIBILITY -> + formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs) + 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, EventType.STATE_ROOM_WIDGET_LEGACY -> formatWidgetEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) - EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, roomSummary) + EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, rs) EventType.STATE_ROOM_POWER_LEVELS -> formatRoomPowerLevels(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) EventType.CALL_INVITE, EventType.CALL_CANDIDATES, @@ -154,19 +155,19 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - fun format(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { + fun format(event: Event, senderName: String?, rs: RoomSummary?): CharSequence? { return when (val type = event.getClearType()) { - EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName, roomSummary) + EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName, rs) EventType.STATE_ROOM_NAME -> formatRoomNameEvent(event, senderName) EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(event, senderName) EventType.STATE_ROOM_AVATAR -> formatRoomAvatarEvent(event, senderName) - EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(event, senderName, roomSummary) - EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(event, senderName, roomSummary) - EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(event, senderName, roomSummary) + EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(event, senderName, rs) + EventType.STATE_ROOM_THIRD_PARTY_INVITE -> formatRoomThirdPartyInvite(event, senderName, rs) + EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(event, senderName, rs) EventType.CALL_INVITE, EventType.CALL_HANGUP, EventType.CALL_ANSWER -> formatCallEvent(type, event, senderName) - EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(event, senderName, roomSummary) + EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(event, senderName, rs) else -> { Timber.v("Type $type not handled by this formatter") null @@ -178,14 +179,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return "{ \"type\": ${event.getClearType()} }" } - private fun formatRoomCreateEvent(event: Event, roomSummary: RoomSummary?): CharSequence? { + private fun formatRoomCreateEvent(event: Event, rs: RoomSummary?): CharSequence? { return event.getClearContent().toModel() ?.takeIf { it.creator.isNullOrBlank().not() } ?.let { if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_created_by_you else R.string.notice_room_created_by_you) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_created else R.string.notice_room_created, it.creator) } } } @@ -207,11 +208,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomTombstoneEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { + private fun formatRoomTombstoneEvent(event: Event, senderName: String?, rs: RoomSummary?): CharSequence? { return if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_update_by_you else R.string.notice_room_update_by_you) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_update else R.string.notice_room_update, senderName) } } @@ -249,20 +250,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { + private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?, rs: RoomSummary?): CharSequence? { val historyVisibility = event.getClearContent().toModel()?.historyVisibility ?: return null val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) return if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, + sp.getString(if (rs.isDm()) R.string.notice_made_future_direct_room_visibility_by_you else R.string.notice_made_future_room_visibility_by_you, formattedVisibility) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, + sp.getString(if (rs.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility, senderName, formattedVisibility) } } - private fun formatRoomThirdPartyInvite(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { + private fun formatRoomThirdPartyInvite(event: Event, senderName: String?, rs: RoomSummary?): CharSequence? { val content = event.getClearContent().toModel() val prevContent = event.resolvedPrevContent()?.toModel() @@ -271,24 +272,24 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour // Revoke case if (event.isSentByCurrentUser()) { sp.getString( - if (roomSummary.isDm()) { + if (rs.isDm()) { R.string.notice_direct_room_third_party_revoked_invite_by_you } else { R.string.notice_room_third_party_revoked_invite_by_you }, prevContent.displayName) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_third_party_revoked_invite else R.string.notice_room_third_party_revoked_invite, senderName, prevContent.displayName) } } content != null -> { // Invitation case if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_third_party_invite_by_you else R.string.notice_room_third_party_invite_by_you, content.displayName) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite, senderName, content.displayName) } } @@ -337,13 +338,13 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomMemberEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): String? { + private fun formatRoomMemberEvent(event: Event, senderName: String?, rs: RoomSummary?): String? { val eventContent: RoomMemberContent? = event.getClearContent().toModel() val prevEventContent: RoomMemberContent? = event.resolvedPrevContent().toModel() val isMembershipEvent = prevEventContent?.membership != eventContent?.membership || eventContent?.membership == Membership.LEAVE return if (isMembershipEvent) { - buildMembershipNotice(event, senderName, eventContent, prevEventContent, roomSummary) + buildMembershipNotice(event, senderName, eventContent, prevEventContent, rs) } else { buildProfileNotice(event, senderName, eventContent, prevEventContent) } @@ -401,25 +402,25 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatRoomGuestAccessEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): String? { + private fun formatRoomGuestAccessEvent(event: Event, senderName: String?, rs: RoomSummary?): String? { val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() return when (eventContent?.guestAccess) { GuestAccess.CanJoin -> if (event.isSentByCurrentUser()) { sp.getString( - if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you + if (rs.isDm()) R.string.notice_direct_room_guest_access_can_join_by_you else R.string.notice_room_guest_access_can_join_by_you ) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join, senderName) } GuestAccess.Forbidden -> if (event.isSentByCurrentUser()) { sp.getString( - if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you + if (rs.isDm()) R.string.notice_direct_room_guest_access_forbidden_by_you else R.string.notice_room_guest_access_forbidden_by_you ) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden, senderName) } else -> null @@ -496,7 +497,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour return displayText.toString() } - private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMemberContent?, prevEventContent: RoomMemberContent?, roomSummary: RoomSummary?): String? { + private fun buildMembershipNotice(event: Event, + senderName: String?, + eventContent: RoomMemberContent?, + prevEventContent: RoomMemberContent?, + rs: RoomSummary?): String? { val senderDisplayName = senderName ?: event.senderId ?: "" val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: event.stateKey ?: "" return when (eventContent?.membership) { @@ -546,17 +551,17 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour Membership.JOIN -> eventContent.safeReason?.let { reason -> if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_join_with_reason_by_you else R.string.notice_room_join_with_reason_by_you, reason) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason, senderDisplayName, reason) } } ?: run { if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_join_by_you else R.string.notice_room_join_by_you) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join, senderDisplayName) } } @@ -578,7 +583,7 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour eventContent.safeReason?.let { reason -> if (event.isSentByCurrentUser()) { sp.getString( - if (roomSummary.isDm()) { + if (rs.isDm()) { R.string.notice_direct_room_leave_with_reason_by_you } else { R.string.notice_room_leave_with_reason_by_you @@ -586,14 +591,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour reason ) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason, senderDisplayName, reason) } } ?: run { if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) + sp.getString(if (rs.isDm()) R.string.notice_direct_room_leave_by_you else R.string.notice_room_leave_by_you) } else { - sp.getString(if (roomSummary.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, + sp.getString(if (rs.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave, senderDisplayName) } } @@ -658,14 +663,14 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour } } - private fun formatJoinRulesEvent(event: Event, senderName: String?, roomSummary: RoomSummary?): CharSequence? { + private fun formatJoinRulesEvent(event: Event, senderName: String?, rs: RoomSummary?): CharSequence? { val content = event.getClearContent().toModel() ?: return null return when (content.joinRules) { RoomJoinRules.INVITE -> if (event.isSentByCurrentUser()) { - sp.getString(if (roomSummary.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) + sp.getString(if (rs.isDm()) R.string.direct_room_join_rules_invite_by_you else R.string.room_join_rules_invite_by_you) } else { - sp.getString(if (roomSummary.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, + sp.getString(if (rs.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite, senderName) } RoomJoinRules.PUBLIC ->