Merge pull request #4494 from nextcloud/bugfix/noid/fixEmailGuestWhitspaces

Bugfix/noid/fix email guest whitspaces
This commit is contained in:
Sowjanya Kota 2024-11-28 17:16:44 +01:00 committed by GitHub
commit 4cffb5b8e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 59 additions and 48 deletions

View file

@ -148,7 +148,7 @@ public class ParticipantsAdapter extends BaseAdapter {
participantDisplayItem.getActorType() == Participant.ActorType.EMAILS) {
ImageViewExtensionsKt.loadFirstLetterAvatar(
imageView,
String.valueOf(participantDisplayItem.getNick().charAt(0))
String.valueOf(participantDisplayItem.getNick())
);
} else {
ImageViewExtensionsKt.loadAvatarWithUrl(imageView,null, participantDisplayItem.getUrlForAvatar());

View file

@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.items.ConversationItem.ConversationItemViewHolder
import com.nextcloud.talk.adapters.messages.MessagePayload
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.chat.data.model.ChatMessage.MessageType
import com.nextcloud.talk.data.database.mappers.asModel
@ -249,14 +250,15 @@ class ConversationItem(
} else if (model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
lastMessageDisplayText
} else {
val authorDisplayName =
if (!TextUtils.isEmpty(chatMessage?.actorDisplayName)) {
chatMessage?.actorDisplayName
} else if ("guests" == chatMessage?.actorType) {
val actorName = chatMessage?.actorDisplayName
val authorDisplayName = if (!actorName.isNullOrBlank()) {
actorName
} else if ("guests" == chatMessage?.actorType || "emails" == chatMessage?.actorType) {
appContext.getString(R.string.nc_guest)
} else {
""
}
String.format(
appContext.getString(R.string.nc_formatted_message),
authorDisplayName,

View file

@ -16,6 +16,7 @@ import androidx.core.content.res.ResourcesCompat
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.items.ParticipantItem.ParticipantItemViewHolder
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.extensions.loadDefaultAvatar
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
import com.nextcloud.talk.extensions.loadGuestAvatar
import com.nextcloud.talk.extensions.loadUserAvatar
@ -56,7 +57,15 @@ class MentionAutocompleteItem(
init {
mentionId = mention.mentionId
objectId = mention.id
displayName = mention.label
displayName = if (!mention.label.isNullOrBlank()) {
mention.label
} else if ("guests" == mention.source || "emails" == mention.source) {
context.resources.getString(R.string.nc_guest)
} else {
""
}
source = mention.source
status = mention.status
statusIcon = mention.statusIcon
@ -149,8 +158,12 @@ class MentionAutocompleteItem(
SOURCE_GUESTS, SOURCE_EMAILS -> {
avatarId = displayName
if (displayName.equals(context.resources.getString(R.string.nc_guest))) {
holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils)
} else {
holder.binding.avatarView.loadGuestAvatar(currentUser, avatarId!!, false)
}
}
else -> {
holder.binding.avatarView.loadUserAvatar(currentUser, avatarId!!, true, false)

View file

@ -85,6 +85,10 @@ class ParticipantItem(
setOnlineStateColor(holder)
holder.binding.nameText.text = model.displayName
if (model.type == Participant.ParticipantType.GUEST && model.displayName.isNullOrBlank()) {
holder.binding.nameText.text = sharedApplication!!.getString(R.string.nc_guest)
}
if (adapter!!.hasFilter()) {
viewThemeUtils.talk.themeAndHighlightText(
holder.binding.nameText,
@ -211,12 +215,11 @@ class ParticipantItem(
}
Participant.ActorType.GUESTS, Participant.ActorType.EMAILS -> {
if (model.displayName.isNullOrEmpty()) {
holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils)
val actorName = model.displayName
if (!actorName.isNullOrBlank()) {
holder.binding.avatarView.loadFirstLetterAvatar(actorName)
} else {
holder.binding.avatarView.loadFirstLetterAvatar(
model.displayName!!.first().toString()
)
holder.binding.avatarView.loadDefaultAvatar(viewThemeUtils)
}
}

View file

@ -157,10 +157,10 @@ class IncomingDeckCardViewHolder(incomingView: View, payload: Any) : MessageHold
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}

View file

@ -135,10 +135,10 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) :
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}

View file

@ -35,6 +35,7 @@ import com.nextcloud.talk.extensions.loadChangelogBotAvatar
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ChatMessageUtils
import com.nextcloud.talk.utils.DateUtils
import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.message.MessageUtils
@ -119,10 +120,10 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) :
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}
@ -131,16 +132,7 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) :
}
if (!message.isGrouped && !message.isOneToOneConversation && !message.isFormerOneToOneConversation) {
binding.messageUserAvatar.visibility = View.VISIBLE
if (message.actorType == "guests") {
// do nothing, avatar is set
} else if (message.actorType == "bots" && message.actorId == "changelog") {
binding.messageUserAvatar.loadChangelogBotAvatar()
} else if (message.actorType == "bots") {
binding.messageUserAvatar.loadBotsAvatar()
} else if (message.actorType == "federated_users") {
binding.messageUserAvatar.loadFederatedUserAvatar(message)
}
ChatMessageUtils().setAvatarOnMessage(binding.messageUserAvatar, message, viewThemeUtils)
} else {
if (message.isOneToOneConversation || message.isFormerOneToOneConversation) {
binding.messageUserAvatar.visibility = View.GONE

View file

@ -142,10 +142,10 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) :
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}

View file

@ -144,10 +144,10 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) :
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}

View file

@ -238,10 +238,10 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
}
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
val author: String = message.actorDisplayName!!
if (!TextUtils.isEmpty(author)) {
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
binding.messageAuthor.visibility = View.VISIBLE
binding.messageAuthor.text = author
binding.messageAuthor.text = actorName
binding.messageUserAvatar.setOnClickListener {
(payload as? MessagePayload)?.profileBottomSheet?.showFor(message, itemView.context)
}

View file

@ -305,10 +305,10 @@ fun ImageView.loadNoteToSelfAvatar(): io.reactivex.disposables.Disposable {
)
}
fun ImageView.loadFirstLetterAvatar(letter: String): io.reactivex.disposables.Disposable {
fun ImageView.loadFirstLetterAvatar(name: String): io.reactivex.disposables.Disposable {
val layers = arrayOfNulls<Drawable>(2)
layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background)
layers[1] = createTextDrawable(context, letter.uppercase(Locale.ROOT))
layers[1] = createTextDrawable(context, name.trimStart().uppercase(Locale.ROOT))
val layerDrawable = LayerDrawable(layers)
val data: Any = layerDrawable

View file

@ -21,8 +21,9 @@ class ChatMessageUtils {
fun setAvatarOnMessage(view: ImageView, message: ChatMessage, viewThemeUtils : ViewThemeUtils) {
view.visibility = View.VISIBLE
if (message.actorType == "guests" || message.actorType == "emails") {
if (message.actorDisplayName?.isNotEmpty() == true) {
view.loadFirstLetterAvatar(message.actorDisplayName?.first().toString())
val actorName = message.actorDisplayName
if (!actorName.isNullOrBlank()) {
view.loadFirstLetterAvatar(actorName)
} else {
view.loadDefaultAvatar(viewThemeUtils)
}