Several fixes on room creation collpasing events (Fixes #1309)

- do not collapse room member events
- collapse other type of event: topic, alias, canonical alias, powel level
- Use correct user name for collapsed version (should be fixed twice due to the previous change of excluding some room member events)
- align "join" and "left" string with Riot-Web
This commit is contained in:
Benoit Marty 2020-04-30 12:52:21 +02:00
parent 7322144dc8
commit f6cbc15cf7
4 changed files with 24 additions and 9 deletions

View File

@ -7,8 +7,8 @@
<string name="notice_room_invite_no_invitee">%s\'s invitation</string> <string name="notice_room_invite_no_invitee">%s\'s invitation</string>
<string name="notice_room_invite">%1$s invited %2$s</string> <string name="notice_room_invite">%1$s invited %2$s</string>
<string name="notice_room_invite_you">%1$s invited you</string> <string name="notice_room_invite_you">%1$s invited you</string>
<string name="notice_room_join">%1$s joined</string> <string name="notice_room_join">%1$s joined the room</string>
<string name="notice_room_leave">%1$s left</string> <string name="notice_room_leave">%1$s left the room</string>
<string name="notice_room_reject">%1$s rejected the invitation</string> <string name="notice_room_reject">%1$s rejected the invitation</string>
<string name="notice_room_kick">%1$s kicked %2$s</string> <string name="notice_room_kick">%1$s kicked %2$s</string>
<string name="notice_room_unban">%1$s unbanned %2$s</string> <string name="notice_room_unban">%1$s unbanned %2$s</string>
@ -246,8 +246,8 @@
<string name="notice_room_invite_no_invitee_with_reason">%1$s\'s invitation. Reason: %2$s</string> <string name="notice_room_invite_no_invitee_with_reason">%1$s\'s invitation. Reason: %2$s</string>
<string name="notice_room_invite_with_reason">%1$s invited %2$s. Reason: %3$s</string> <string name="notice_room_invite_with_reason">%1$s invited %2$s. Reason: %3$s</string>
<string name="notice_room_invite_you_with_reason">%1$s invited you. Reason: %2$s</string> <string name="notice_room_invite_you_with_reason">%1$s invited you. Reason: %2$s</string>
<string name="notice_room_join_with_reason">%1$s joined. Reason: %2$s</string> <string name="notice_room_join_with_reason">%1$s joined the room. Reason: %2$s</string>
<string name="notice_room_leave_with_reason">%1$s left. Reason: %2$s</string> <string name="notice_room_leave_with_reason">%1$s left the room. Reason: %2$s</string>
<string name="notice_room_reject_with_reason">%1$s rejected the invitation. Reason: %2$s</string> <string name="notice_room_reject_with_reason">%1$s rejected the invitation. Reason: %2$s</string>
<string name="notice_room_kick_with_reason">%1$s kicked %2$s. Reason: %3$s</string> <string name="notice_room_kick_with_reason">%1$s kicked %2$s. Reason: %3$s</string>
<string name="notice_room_unban_with_reason">%1$s unbanned %2$s. Reason: %3$s</string> <string name="notice_room_unban_with_reason">%1$s unbanned %2$s. Reason: %3$s</string>

View File

@ -18,6 +18,7 @@ package im.vector.riotx.features.home.room.detail.timeline.factory
import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.create.RoomCreateContent
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
import im.vector.matrix.android.internal.crypto.model.event.EncryptionEventContent import im.vector.matrix.android.internal.crypto.model.event.EncryptionEventContent
@ -43,6 +44,9 @@ class MergedHeaderItemFactory @Inject constructor(private val sessionHolder: Act
private val collapsedEventIds = linkedSetOf<Long>() private val collapsedEventIds = linkedSetOf<Long>()
private val mergeItemCollapseStates = HashMap<Long, Boolean>() private val mergeItemCollapseStates = HashMap<Long, Boolean>()
/**
* Note: nextEvent is an older event than event
*/
fun create(event: TimelineEvent, fun create(event: TimelineEvent,
nextEvent: TimelineEvent?, nextEvent: TimelineEvent?,
items: List<TimelineEvent>, items: List<TimelineEvent>,
@ -52,7 +56,8 @@ class MergedHeaderItemFactory @Inject constructor(private val sessionHolder: Act
callback: TimelineEventController.Callback?, callback: TimelineEventController.Callback?,
requestModelBuild: () -> Unit) requestModelBuild: () -> Unit)
: BasedMergedItem<*>? { : BasedMergedItem<*>? {
return if (nextEvent?.root?.getClearType() == EventType.STATE_ROOM_CREATE && event.isRoomConfiguration()) { return if (nextEvent?.root?.getClearType() == EventType.STATE_ROOM_CREATE
&& event.isRoomConfiguration(nextEvent.root.getClearContent()?.toModel<RoomCreateContent>()?.creator)) {
// It's the first item before room.create // It's the first item before room.create
// Collapse all room configuration events // Collapse all room configuration events
buildRoomCreationMergedSummary(currentPosition, items, event, eventIdToHighlight, requestModelBuild, callback) buildRoomCreationMergedSummary(currentPosition, items, event, eventIdToHighlight, requestModelBuild, callback)
@ -127,7 +132,7 @@ class MergedHeaderItemFactory @Inject constructor(private val sessionHolder: Act
val mergedEvents = ArrayList<TimelineEvent>().also { it.add(event) } val mergedEvents = ArrayList<TimelineEvent>().also { it.add(event) }
var hasEncryption = false var hasEncryption = false
var encryptionAlgorithm: String? = null var encryptionAlgorithm: String? = null
while (prevEvent != null && prevEvent.isRoomConfiguration()) { while (prevEvent != null && prevEvent.isRoomConfiguration(null)) {
if (prevEvent.root.getClearType() == EventType.STATE_ROOM_ENCRYPTION) { if (prevEvent.root.getClearType() == EventType.STATE_ROOM_ENCRYPTION) {
hasEncryption = true hasEncryption = true
encryptionAlgorithm = prevEvent.root.getClearContent()?.toModel<EncryptionEventContent>()?.algorithm encryptionAlgorithm = prevEvent.root.getClearContent()?.toModel<EncryptionEventContent>()?.algorithm

View File

@ -50,14 +50,23 @@ fun TimelineEvent.canBeMerged(): Boolean {
return root.getClearType() == EventType.STATE_ROOM_MEMBER return root.getClearType() == EventType.STATE_ROOM_MEMBER
} }
fun TimelineEvent.isRoomConfiguration(): Boolean { fun TimelineEvent.isRoomConfiguration(roomCreatorUserId: String?): Boolean {
return when (root.getClearType()) { return when (root.getClearType()) {
EventType.STATE_ROOM_GUEST_ACCESS, EventType.STATE_ROOM_GUEST_ACCESS,
EventType.STATE_ROOM_HISTORY_VISIBILITY, EventType.STATE_ROOM_HISTORY_VISIBILITY,
EventType.STATE_ROOM_JOIN_RULES, EventType.STATE_ROOM_JOIN_RULES,
EventType.STATE_ROOM_MEMBER,
EventType.STATE_ROOM_NAME, EventType.STATE_ROOM_NAME,
EventType.STATE_ROOM_TOPIC,
EventType.STATE_ROOM_AVATAR,
EventType.STATE_ROOM_ALIASES,
EventType.STATE_ROOM_CANONICAL_ALIAS,
EventType.STATE_ROOM_POWER_LEVELS,
EventType.STATE_ROOM_ENCRYPTION -> true EventType.STATE_ROOM_ENCRYPTION -> true
EventType.STATE_ROOM_MEMBER -> {
// Keep only room member events regarding the room creator (when he joined the room),
// but exclude events where the room creator invite others, or where others join
roomCreatorUserId != null && root.stateKey == roomCreatorUserId
}
else -> false else -> false
} }
} }

View File

@ -43,7 +43,8 @@ abstract class MergedRoomCreationItem : BasedMergedItem<MergedRoomCreationItem.H
super.bind(holder) super.bind(holder)
if (attributes.isCollapsed) { if (attributes.isCollapsed) {
val data = distinctMergeData.firstOrNull() // Take the oldest data
val data = distinctMergeData.lastOrNull()
val summary = holder.expandView.resources.getString(R.string.room_created_summary_item, val summary = holder.expandView.resources.getString(R.string.room_created_summary_item,
data?.memberName ?: data?.userId ?: "") data?.memberName ?: data?.userId ?: "")