Shortened lines

This commit is contained in:
Benoit Marty 2019-12-04 19:17:23 +01:00
parent e0e778909d
commit 415511f3e0

View file

@ -29,7 +29,7 @@ import timber.log.Timber
import javax.inject.Inject
class NoticeEventFormatter @Inject constructor(private val sessionHolder: ActiveSessionHolder,
private val stringProvider: StringProvider) {
private val sp: StringProvider) {
fun format(timelineEvent: TimelineEvent): CharSequence? {
return when (val type = timelineEvent.root.getClearType()) {
@ -77,22 +77,22 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
private fun formatRoomNameEvent(event: Event, senderName: String?): CharSequence? {
val content = event.getClearContent().toModel<RoomNameContent>() ?: return null
return if (content.name.isNullOrBlank()) {
stringProvider.getString(R.string.notice_room_name_removed, senderName)
sp.getString(R.string.notice_room_name_removed, senderName)
} else {
stringProvider.getString(R.string.notice_room_name_changed, senderName, content.name)
sp.getString(R.string.notice_room_name_changed, senderName, content.name)
}
}
private fun formatRoomTombstoneEvent(senderName: String?): CharSequence? {
return stringProvider.getString(R.string.notice_room_update, senderName)
return sp.getString(R.string.notice_room_update, senderName)
}
private fun formatRoomTopicEvent(event: Event, senderName: String?): CharSequence? {
val content = event.getClearContent().toModel<RoomTopicContent>() ?: return null
return if (content.topic.isNullOrEmpty()) {
stringProvider.getString(R.string.notice_room_topic_removed, senderName)
sp.getString(R.string.notice_room_topic_removed, senderName)
} else {
stringProvider.getString(R.string.notice_room_topic_changed, senderName, content.topic)
sp.getString(R.string.notice_room_topic_changed, senderName, content.topic)
}
}
@ -100,12 +100,12 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
val formattedVisibility = when (historyVisibility) {
RoomHistoryVisibility.SHARED -> stringProvider.getString(R.string.notice_room_visibility_shared)
RoomHistoryVisibility.INVITED -> stringProvider.getString(R.string.notice_room_visibility_invited)
RoomHistoryVisibility.JOINED -> stringProvider.getString(R.string.notice_room_visibility_joined)
RoomHistoryVisibility.WORLD_READABLE -> stringProvider.getString(R.string.notice_room_visibility_world_readable)
RoomHistoryVisibility.SHARED -> sp.getString(R.string.notice_room_visibility_shared)
RoomHistoryVisibility.INVITED -> sp.getString(R.string.notice_room_visibility_invited)
RoomHistoryVisibility.JOINED -> sp.getString(R.string.notice_room_visibility_joined)
RoomHistoryVisibility.WORLD_READABLE -> sp.getString(R.string.notice_room_visibility_world_readable)
}
return stringProvider.getString(R.string.notice_made_future_room_visibility, senderName, formattedVisibility)
return sp.getString(R.string.notice_made_future_room_visibility, senderName, formattedVisibility)
}
private fun formatCallEvent(event: Event, senderName: String?): CharSequence? {
@ -114,13 +114,13 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
val content = event.getClearContent().toModel<CallInviteContent>() ?: return null
val isVideoCall = content.offer.sdp == CallInviteContent.Offer.SDP_VIDEO
return if (isVideoCall) {
stringProvider.getString(R.string.notice_placed_video_call, senderName)
sp.getString(R.string.notice_placed_video_call, senderName)
} else {
stringProvider.getString(R.string.notice_placed_voice_call, senderName)
sp.getString(R.string.notice_placed_voice_call, senderName)
}
}
EventType.CALL_ANSWER == event.type -> stringProvider.getString(R.string.notice_answered_call, senderName)
EventType.CALL_HANGUP == event.type -> stringProvider.getString(R.string.notice_ended_call, senderName)
EventType.CALL_ANSWER == event.type -> sp.getString(R.string.notice_answered_call, senderName)
EventType.CALL_HANGUP == event.type -> sp.getString(R.string.notice_ended_call, senderName)
else -> null
}
}
@ -142,11 +142,11 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
if (eventContent?.displayName != prevEventContent?.displayName) {
val displayNameText = when {
prevEventContent?.displayName.isNullOrEmpty() ->
stringProvider.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName)
sp.getString(R.string.notice_display_name_set, event.senderId, eventContent?.displayName)
eventContent?.displayName.isNullOrEmpty() ->
stringProvider.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName)
sp.getString(R.string.notice_display_name_removed, event.senderId, prevEventContent?.displayName)
else ->
stringProvider.getString(R.string.notice_display_name_changed_from, event.senderId, prevEventContent?.displayName, eventContent?.displayName)
sp.getString(R.string.notice_display_name_changed_from, event.senderId, prevEventContent?.displayName, eventContent?.displayName)
}
displayText.append(displayNameText)
}
@ -154,15 +154,15 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
if (eventContent?.avatarUrl != prevEventContent?.avatarUrl) {
val displayAvatarText = if (displayText.isNotEmpty()) {
displayText.append(" ")
stringProvider.getString(R.string.notice_avatar_changed_too)
sp.getString(R.string.notice_avatar_changed_too)
} else {
stringProvider.getString(R.string.notice_avatar_url_changed, senderName)
sp.getString(R.string.notice_avatar_url_changed, senderName)
}
displayText.append(displayAvatarText)
}
if (displayText.isEmpty()) {
displayText.append(
stringProvider.getString(R.string.notice_member_no_changes, senderName)
sp.getString(R.string.notice_member_no_changes, senderName)
)
}
return displayText.toString()
@ -179,73 +179,63 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
val userWhoHasAccepted = eventContent.thirdPartyInvite?.signed?.mxid ?: event.stateKey
val threePidDisplayName = eventContent.thirdPartyInvite?.displayName ?: ""
eventContent.safeReason?.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, threePidDisplayName)
sp.getString(R.string.notice_room_third_party_registered_invite_with_reason, userWhoHasAccepted, threePidDisplayName, reason)
} ?: sp.getString(R.string.notice_room_third_party_registered_invite, userWhoHasAccepted, threePidDisplayName)
}
event.stateKey == selfUserId ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_invite_you_with_reason, senderDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_invite_you, senderDisplayName)
sp.getString(R.string.notice_room_invite_you_with_reason, senderDisplayName, reason)
} ?: sp.getString(R.string.notice_room_invite_you, senderDisplayName)
event.stateKey.isNullOrEmpty() ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_invite_no_invitee_with_reason, senderDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_invite_no_invitee, senderDisplayName)
sp.getString(R.string.notice_room_invite_no_invitee_with_reason, senderDisplayName, reason)
} ?: sp.getString(R.string.notice_room_invite_no_invitee, senderDisplayName)
else ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
sp.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName, reason)
} ?: sp.getString(R.string.notice_room_invite, senderDisplayName, targetDisplayName)
}
}
Membership.JOIN ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason)
sp.getString(R.string.notice_room_join_with_reason, senderDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_join, senderDisplayName)
?: sp.getString(R.string.notice_room_join, senderDisplayName)
Membership.LEAVE ->
// 2 cases here: this member may have left voluntarily or they may have been "left" by someone else ie. kicked
if (event.senderId == event.stateKey) {
if (prevEventContent?.membership == Membership.INVITE) {
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_reject_with_reason, senderDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_reject, senderDisplayName)
sp.getString(R.string.notice_room_reject_with_reason, senderDisplayName, reason)
} ?: sp.getString(R.string.notice_room_reject, senderDisplayName)
} else {
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_leave_with_reason, senderDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_leave, senderDisplayName)
sp.getString(R.string.notice_room_leave_with_reason, senderDisplayName, reason)
} ?: sp.getString(R.string.notice_room_leave, senderDisplayName)
}
} else if (prevEventContent?.membership == Membership.INVITE) {
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_withdraw_with_reason, senderDisplayName, targetDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_withdraw, senderDisplayName, targetDisplayName)
sp.getString(R.string.notice_room_withdraw_with_reason, senderDisplayName, targetDisplayName, reason)
} ?: sp.getString(R.string.notice_room_withdraw, senderDisplayName, targetDisplayName)
} else if (prevEventContent?.membership == Membership.JOIN) {
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
sp.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
} ?: sp.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
} else if (prevEventContent?.membership == Membership.BAN) {
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_unban_with_reason, senderDisplayName, targetDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_unban, senderDisplayName, targetDisplayName)
sp.getString(R.string.notice_room_unban_with_reason, senderDisplayName, targetDisplayName, reason)
} ?: sp.getString(R.string.notice_room_unban, senderDisplayName, targetDisplayName)
} else {
null
}
Membership.BAN ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_ban_with_reason, senderDisplayName, targetDisplayName, reason)
}
?: stringProvider.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
eventContent.safeReason?.let {
sp.getString(R.string.notice_room_ban_with_reason, senderDisplayName, targetDisplayName, it)
} ?: sp.getString(R.string.notice_room_ban, senderDisplayName, targetDisplayName)
Membership.KNOCK ->
eventContent.safeReason?.let { reason ->
stringProvider.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
} ?: stringProvider.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
sp.getString(R.string.notice_room_kick_with_reason, senderDisplayName, targetDisplayName, reason)
} ?: sp.getString(R.string.notice_room_kick, senderDisplayName, targetDisplayName)
else -> null
}
}
@ -253,8 +243,8 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
private fun formatJoinRulesEvent(event: Event, senderName: String?): CharSequence? {
val content = event.getClearContent().toModel<RoomJoinRulesContent>() ?: return null
return when (content.joinRules) {
RoomJoinRules.INVITE -> stringProvider.getString(R.string.room_join_rules_invite, senderName)
RoomJoinRules.PUBLIC -> stringProvider.getString(R.string.room_join_rules_public, senderName)
RoomJoinRules.INVITE -> sp.getString(R.string.room_join_rules_invite, senderName)
RoomJoinRules.PUBLIC -> sp.getString(R.string.room_join_rules_public, senderName)
else -> null
}
}