Prefix with You instead of display name #3470

This commit is contained in:
Benoit Marty 2024-09-26 15:42:43 +02:00
parent 2468592ec0
commit 8118ae7ae1
3 changed files with 50 additions and 20 deletions

View file

@ -61,18 +61,18 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
val isOutgoing = event.isOwn
val senderDisambiguatedDisplayName = event.senderProfile.getDisambiguatedDisplayName(event.sender)
return when (val content = event.content) {
is MessageContent -> content.process(senderDisambiguatedDisplayName, isDmRoom)
is MessageContent -> content.process(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
RedactedContent -> {
val message = sp.getString(CommonStrings.common_message_removed)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is StickerContent -> {
val message = sp.getString(CommonStrings.common_sticker) + " (" + content.body + ")"
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is UnableToDecryptContent -> {
val message = sp.getString(CommonStrings.common_waiting_for_decryption_key)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is RoomMembershipContent -> {
roomMembershipContentFormatter.format(content, senderDisambiguatedDisplayName, isOutgoing)
@ -85,11 +85,11 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
}
is PollContent -> {
val message = sp.getString(CommonStrings.common_poll_summary, content.question)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is FailedToParseMessageLikeContent, is FailedToParseStateContent, is UnknownContent -> {
val message = sp.getString(CommonStrings.common_unsupported_event)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is LegacyCallInviteContent -> sp.getString(CommonStrings.common_call_invite)
is CallNotifyContent -> sp.getString(CommonStrings.common_call_started)
@ -99,6 +99,7 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
private fun MessageContent.process(
senderDisambiguatedDisplayName: String,
isDmRoom: Boolean,
isOutgoing: Boolean
): CharSequence {
val message = when (val messageType: MessageType = type) {
// Doesn't need a prefix
@ -136,15 +137,22 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
messageType.body
}
}
return message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom)
return message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
private fun String.prefixIfNeeded(
senderDisambiguatedDisplayName: String,
isDmRoom: Boolean,
isOutgoing: Boolean,
): CharSequence = if (isDmRoom) {
this
} else {
prefixWith(senderDisambiguatedDisplayName)
prefixWith(
if (isOutgoing) {
sp.getString(CommonStrings.common_you)
} else {
senderDisambiguatedDisplayName
}
)
}
}