Ensure user will never see 'null' in a String

This commit is contained in:
Benoit Marty 2019-12-04 19:05:57 +01:00
parent 872b14373b
commit b9efc9f4bd

View file

@ -169,7 +169,7 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
} }
private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? { private fun buildMembershipNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String? {
val senderDisplayName = senderName ?: event.senderId val senderDisplayName = senderName ?: event.senderId ?: ""
val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: event.stateKey ?: "" val targetDisplayName = eventContent?.displayName ?: prevEventContent?.displayName ?: event.stateKey ?: ""
return when (eventContent?.membership) { return when (eventContent?.membership) {
Membership.INVITE -> { Membership.INVITE -> {
@ -177,9 +177,10 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
when { when {
eventContent.thirdPartyInvite != null -> { eventContent.thirdPartyInvite != null -> {
val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey
val threePidDisplayName = eventContent.thirdPartyInvite?.displayName ?: ""
eventContent.safeReason eventContent.safeReason
?.let { reason -> stringProvider.getString(R.string.notice_room_third_party_registered_invite_with_reason, userWhoHasAccepted, eventContent.thirdPartyInvite?.displayName, reason) } ?.let { reason -> stringProvider.getString(R.string.notice_room_third_party_registered_invite_with_reason, userWhoHasAccepted, threePidDisplayName, reason) }
?: stringProvider.getString(R.string.notice_room_third_party_registered_invite, userWhoHasAccepted, eventContent.thirdPartyInvite?.displayName) ?: stringProvider.getString(R.string.notice_room_third_party_registered_invite, userWhoHasAccepted, threePidDisplayName)
} }
event.stateKey == selfUserId -> event.stateKey == selfUserId ->
eventContent.safeReason eventContent.safeReason