Merge pull request #549 from vector-im/feature/third_party_invite

Fix rendering issue of accepted third party invitation event
This commit is contained in:
Benoit Marty 2019-09-06 16:36:30 +02:00 committed by GitHub
commit f2c8d4ad02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 18 deletions

View File

@ -19,6 +19,7 @@ Translations:


Build: Build:
- Fix issue with version name (#533) - Fix issue with version name (#533)
- Fix rendering issue of accepted third party invitation event


Changes in RiotX 0.4.0 (2019-XX-XX) Changes in RiotX 0.4.0 (2019-XX-XX)
=================================================== ===================================================

View File

@ -16,7 +16,6 @@


package im.vector.riotx.features.home.room.detail.timeline.format package im.vector.riotx.features.home.room.detail.timeline.format


import android.text.TextUtils
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
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
@ -24,12 +23,14 @@ import im.vector.matrix.android.api.session.room.model.*
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.di.ActiveSessionHolder
import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.home.room.detail.timeline.helper.senderName import im.vector.riotx.features.home.room.detail.timeline.helper.senderName
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject


class NoticeEventFormatter @Inject constructor(private val stringProvider: StringProvider) { class NoticeEventFormatter @Inject constructor(private val sessionHolder: ActiveSessionHolder,
private val stringProvider: StringProvider) {


fun format(timelineEvent: TimelineEvent): CharSequence? { fun format(timelineEvent: TimelineEvent): CharSequence? {
return when (val type = timelineEvent.root.getClearType()) { return when (val type = timelineEvent.root.getClearType()) {
@ -74,10 +75,10 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin


private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? { private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? {
val content = event.getClearContent().toModel<RoomNameContent>() ?: return null val content = event.getClearContent().toModel<RoomNameContent>() ?: return null
return if (!TextUtils.isEmpty(content.name)) { return if (content.name.isNullOrBlank()) {
stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name)
} else {
stringProvider.getString(R.string.notice_room_name_removed, senderName) stringProvider.getString(R.string.notice_room_name_removed, senderName)
} else {
stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name)
} }
} }


@ -95,8 +96,7 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin
} }


private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? { private fun formatRoomHistoryVisibilityEvent(event: Event, senderName: String?): CharSequence? {
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
?: return null


val formattedVisibility = when (historyVisibility) { val formattedVisibility = when (historyVisibility) {
RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared) RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared)
@ -138,7 +138,7 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin
private fun buildProfileNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? { private fun buildProfileNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? {
val displayText = StringBuilder() val displayText = StringBuilder()
// Check display name has been changed // Check display name has been changed
if (!TextUtils.equals(eventContent?.displayName, prevEventContent?.displayName)) { if (eventContent?.displayName != prevEventContent?.displayName) {
val displayNameText = when { val displayNameText = when {
prevEventContent?.displayName.isNullOrEmpty() -> prevEventContent?.displayName.isNullOrEmpty() ->
stringProvider.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName) stringProvider.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName)
@ -146,12 +146,12 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin
stringProvider.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName) stringProvider.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName)
else -> else ->
stringProvider.getString(R.string.notice_display_name_changed_from, stringProvider.getString(R.string.notice_display_name_changed_from,
event.senderId, prevEventContent?.displayName, eventContent?.displayName) event.senderId, prevEventContent?.displayName, eventContent?.displayName)
} }
displayText.append(displayNameText) displayText.append(displayNameText)
} }
// Check whether the avatar has been changed // Check whether the avatar has been changed
if (!TextUtils.equals(eventContent?.avatarUrl, prevEventContent?.avatarUrl)) { if (eventContent?.avatarUrl != prevEventContent?.avatarUrl) {
val displayAvatarText = if (displayText.isNotEmpty()) { val displayAvatarText = if (displayText.isNotEmpty()) {
displayText.append(" ") displayText.append(" ")
stringProvider.getString(R.string.notice_avatar_changed_too) stringProvider.getString(R.string.notice_avatar_changed_too)
@ -168,17 +168,18 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin
val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: "" val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: ""
return when { return when {
Membership.INVITE == eventContent?.membership -> { Membership.INVITE == eventContent?.membership -> {
// TODO get userId val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId
val selfUserId = ""
when { when {
eventContent.thirdPartyInvite != null -> eventContent.thirdPartyInvite != null -> {
val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey
stringProvider.getString(R.string.notice_room_third_party_registered_invite, stringProvider.getString(R.string.notice_room_third_party_registered_invite,
targetDisplayName, eventContent.thirdPartyInvite?.displayName) userWhoHasAccepted, eventContent.thirdPartyInvite?.displayName)
TextUtils.equals(event.stateKey, selfUserId) -> }
event.stateKey == selfUserId ->
stringProvider.getString(R.string.notice_room_invite_you, senderDisplayName) stringProvider.getString(R.string.notice_room_invite_you, senderDisplayName)
event.stateKey.isNullOrEmpty() -> event.stateKey.isNullOrEmpty() ->
stringProvider.getString(R.string.notice_room_invite_no_invitee, senderDisplayName) stringProvider.getString(R.string.notice_room_invite_no_invitee, senderDisplayName)
else -> else ->
stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName) stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
} }
} }
@ -186,7 +187,7 @@ class NoticeEventFormatter @Inject constructor(private val stringProvider: Strin
stringProvider.getString(R.string.notice_room_join, senderDisplayName) stringProvider.getString(R.string.notice_room_join, senderDisplayName)
Membership.LEAVE == eventContent?.membership -> Membership.LEAVE == eventContent?.membership ->
// 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked // 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked
return if (TextUtils.equals(event.senderId, event.stateKey)) { return if (event.senderId == event.stateKey) {
if (prevEventContent?.membership == Membership.INVITE) { if (prevEventContent?.membership == Membership.INVITE) {
stringProvider.getString(R.string.notice_room_reject, senderDisplayName) stringProvider.getString(R.string.notice_room_reject, senderDisplayName)
} else { } else {