Add braces to multiline if else

This commit is contained in:
Benoit Marty 2020-09-30 11:54:23 +02:00
parent 07446d2d41
commit 84202adc5b
1 changed files with 36 additions and 24 deletions

View File

@ -183,10 +183,11 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
return event.getClearContent().toModel<RoomCreateContent>() return event.getClearContent().toModel<RoomCreateContent>()
?.takeIf { it.creator.isNullOrBlank().not() } ?.takeIf { it.creator.isNullOrBlank().not() }
?.let { ?.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) 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) 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? { 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) 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) 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? { private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? {
@ -252,12 +254,13 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
val formattedVisibility = roomHistoryVisibilityFormatter.format(historyVisibility) 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, 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) formattedVisibility)
else } 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 (event.isDm()) R.string.notice_made_future_direct_room_visibility else R.string.notice_made_future_room_visibility,
senderName, formattedVisibility) senderName, formattedVisibility)
}
} }
private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? { private fun formatRoomThirdPartyInvite(event: Event, senderName: String?): CharSequence? {
@ -267,21 +270,23 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
return when { return when {
prevContent != null -> { prevContent != null -> {
// Revoke case // 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, 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) 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, 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) senderName, prevContent.displayName)
}
} }
content != null -> { content != null -> {
// Invitation case // 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, 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) 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, sp.getString(if (event.isDm()) R.string.notice_direct_room_third_party_invite else R.string.notice_room_third_party_invite,
senderName, content.displayName) senderName, content.displayName)
}
} }
else -> null else -> null
} }
@ -396,17 +401,19 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel() val eventContent: RoomGuestAccessContent? = event.getClearContent().toModel()
return when (eventContent?.guestAccess) { return when (eventContent?.guestAccess) {
GuestAccess.CanJoin -> 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) 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, sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_can_join else R.string.notice_room_guest_access_can_join,
senderName) senderName)
}
GuestAccess.Forbidden -> 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) 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, sp.getString(if (event.isDm()) R.string.notice_direct_room_guest_access_forbidden else R.string.notice_room_guest_access_forbidden,
senderName) senderName)
}
else -> null else -> null
} }
} }
@ -530,18 +537,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
} }
Membership.JOIN -> Membership.JOIN ->
eventContent.safeReason?.let { reason -> 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, 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) reason)
else } 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 (event.isDm()) R.string.notice_direct_room_join_with_reason else R.string.notice_room_join_with_reason,
senderDisplayName, reason) senderDisplayName, reason)
}
} ?: run { } ?: 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) 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, sp.getString(if (event.isDm()) R.string.notice_direct_room_join else R.string.notice_room_join,
senderDisplayName) senderDisplayName)
}
} }
Membership.LEAVE -> Membership.LEAVE ->
// 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
@ -559,18 +568,20 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
} }
else -> else ->
eventContent.safeReason?.let { reason -> 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, 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) reason)
else } 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 (event.isDm()) R.string.notice_direct_room_leave_with_reason else R.string.notice_room_leave_with_reason,
senderDisplayName, reason) senderDisplayName, reason)
}
} ?: run { } ?: 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) 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, sp.getString(if (event.isDm()) R.string.notice_direct_room_leave else R.string.notice_room_leave,
senderDisplayName) senderDisplayName)
}
} }
} }
} else { } else {
@ -637,11 +648,12 @@ class NoticeEventFormatter @Inject constructor(private val activeSessionDataSour
val content = event.getClearContent().toModel<RoomJoinRulesContent>() ?: return null val content = event.getClearContent().toModel<RoomJoinRulesContent>() ?: return null
return when (content.joinRules) { return when (content.joinRules) {
RoomJoinRules.INVITE -> 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) 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, sp.getString(if (event.isDm()) R.string.direct_room_join_rules_invite else R.string.room_join_rules_invite,
senderName) senderName)
}
RoomJoinRules.PUBLIC -> RoomJoinRules.PUBLIC ->
if (event.isSentByCurrentUser()) { if (event.isSentByCurrentUser()) {
sp.getString(R.string.room_join_rules_public_by_you) sp.getString(R.string.room_join_rules_public_by_you)