Skip to content

Commit

Permalink
[PBE-0] use user.id for mentions if user.name is empty (#5384)
Browse files Browse the repository at this point in the history
* [PBE-0] use user.id for mentions if user.name is empty

* add CHANGELOG

---------

Co-authored-by: Jc Miñarro <[email protected]>
  • Loading branch information
kanat and JcMinarro authored Aug 29, 2024
1 parent 4242d3b commit b0dde02
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

### ⬆️ Improved
- `MessageOptionsDialogFragment` now uses `MessageListItemViewHolderFactory` to get item view type. [#5369](https://github.com/GetStream/stream-chat-android/pull/5369)
- Default `MentionsViewHolder` uses `user.id` if `user.name` is empty. [#5384](https://github.com/GetStream/stream-chat-android/pull/5384)

### ✅ Added
- Create a new UI for the poll message. [#5285](https://github.com/GetStream/stream-chat-android/pull/5285)
Expand All @@ -86,6 +87,7 @@
- Expose `topBarContent` and `bottomBarContent` in `MessageScreen`. [#5377](https://github.com/GetStream/stream-chat-android/pull/5377)

### ⬆️ Improved
- `DefaultMentionSuggestionItemCenterContent` component uses `user.id` if `user.name` is empty. [#5384](https://github.com/GetStream/stream-chat-android/pull/5384)
- Added `showFileSize` parameter to `StreamAttachmentFactories.defaultFactories` to control file size UI visibility. [#5383](https://github.com/GetStream/stream-chat-android/pull/5383)

### ✅ Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,26 @@ internal fun RowScope.DefaultMentionSuggestionItemCenterContent(user: User) {
Column(
modifier = Modifier
.weight(1f)
.wrapContentHeight(),
.wrapContentHeight()
.align(Alignment.CenterVertically),
) {
val username = "@${user.id}"
Text(
text = user.name,
text = user.name.ifEmpty { username },
style = ChatTheme.typography.bodyBold,
color = ChatTheme.colors.textHighEmphasis,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(
text = "@${user.id}",
style = ChatTheme.typography.footnote,
color = ChatTheme.colors.textLowEmphasis,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (user.name.isNotEmpty()) {
Text(
text = username,
style = ChatTheme.typography.body,
color = ChatTheme.colors.textLowEmphasis,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ public class MessageComposerController(
* @param user The user that is used to autocomplete the mention.
*/
public fun selectMention(user: User) {
val augmentedMessageText = "${messageText.substringBeforeLast("@")}@${user.name} "
val username = user.name.ifEmpty { user.id }
val augmentedMessageText = "${messageText.substringBeforeLast("@")}@$username "

setMessageInputInternal(augmentedMessageText, MessageInput.Source.MentionSelected)
selectedMentions += user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ private class MentionsViewHolder(
binding.userAvatarView.doOnLayout {
binding.userAvatarView.setUser(item)
}
binding.usernameTextView.text = item.name
binding.mentionNameTextView.text = String.format(mentionTemplateText, item.name.lowercase())
val username = String.format(mentionTemplateText, item.id.lowercase())
binding.usernameTextView.text = item.name.ifEmpty { username }
binding.mentionNameTextView.isVisible = item.name.isNotEmpty()
binding.mentionNameTextView.text = username
}
}

0 comments on commit b0dde02

Please sign in to comment.