Better code
This commit is contained in:
parent
d28700e2bf
commit
872b14373b
|
@ -171,8 +171,8 @@ 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 {
|
return when (eventContent?.membership) {
|
||||||
Membership.INVITE == eventContent?.membership -> {
|
Membership.INVITE -> {
|
||||||
val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId
|
val selfUserId = sessionHolder.getSafeActiveSession()?.myUserId
|
||||||
when {
|
when {
|
||||||
eventContent.thirdPartyInvite != null -> {
|
eventContent.thirdPartyInvite != null -> {
|
||||||
|
@ -195,13 +195,13 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
||||||
?: stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
|
?: stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Membership.JOIN == eventContent?.membership ->
|
Membership.JOIN ->
|
||||||
eventContent.safeReason
|
eventContent.safeReason
|
||||||
?.let { reason -> stringProvider.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason) }
|
?.let { reason -> stringProvider.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason) }
|
||||||
?: stringProvider.getString(R.string.notice_room_join, senderDisplayName)
|
?: stringProvider.getString(R.string.notice_room_join, senderDisplayName)
|
||||||
Membership.LEAVE == eventContent?.membership ->
|
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
|
||||||
return if (event.senderId == event.stateKey) {
|
if (event.senderId == event.stateKey) {
|
||||||
if (prevEventContent?.membership == Membership.INVITE) {
|
if (prevEventContent?.membership == Membership.INVITE) {
|
||||||
eventContent.safeReason
|
eventContent.safeReason
|
||||||
?.let { reason -> stringProvider.getString(R.string.notice_room_reject_with_reason, senderDisplayName, reason) }
|
?.let { reason -> stringProvider.getString(R.string.notice_room_reject_with_reason, senderDisplayName, reason) }
|
||||||
|
@ -226,15 +226,15 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
Membership.BAN == eventContent?.membership ->
|
Membership.BAN ->
|
||||||
eventContent.safeReason
|
eventContent.safeReason
|
||||||
?.let { reason -> stringProvider.getString(R.string.notice_room_ban_with_reason, senderDisplayName, targetDisplayName, reason) }
|
?.let { reason -> stringProvider.getString(R.string.notice_room_ban_with_reason, senderDisplayName, targetDisplayName, reason) }
|
||||||
?: stringProvider.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
|
?: stringProvider.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
|
||||||
Membership.KNOCK == eventContent?.membership ->
|
Membership.KNOCK ->
|
||||||
eventContent.safeReason
|
eventContent.safeReason
|
||||||
?.let { reason -> stringProvider.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason) }
|
?.let { reason -> stringProvider.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason) }
|
||||||
?: stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
?: stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue