Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip the @ char when displaying a room Avatar based on its name #312

Merged
merged 2 commits into from
Jan 2, 2025

Conversation

Guocork
Copy link
Contributor

@Guocork Guocork commented Jan 1, 2025

截图 2025-01-01 15-50-05

The original algorithm only returned the first character, so if the first character of the room name was a special character, it wouldn't show up in the user avatar. I modified the code to return the first valid character, ensuring the avatar displays properly. In the image above, the first and third rooms show correctly. Without this fix, it would return a "?".

Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure this change is correct. If a username has non-alphanumeric characters at the beginning, wouldn't this change skip over them? It seems like we would want to display the first character in the room name, so I'm surprised my original function is wrong.

What are the raw text names of these rooms? Perhaps we can determine a better conditional, since I don't think we should skip all non-alphanumeric chars.

@Guocork
Copy link
Contributor Author

Guocork commented Jan 1, 2025

Hi @kevinaboos

This is an edge case, and the idea for this change comes from Element. When I create a room, invite two or more people, and don’t name the room or set an avatar, the room name will display all the members' names. For example, if I invite @Tyrese Luo and Alan Poon to the room without naming it, the room name will be something like: @Tyrese Luo and Alan Poon (in Element) or @Tyrese Luo, Alan Poon (in Robrix). You can see this in the image below.

Element:
image

Robrix:
截图 2024-12-31 16-26-42

In Element, special characters are skipped to display the avatar properly. But in Robrix, it can’t render special characters, so it shows a ?. That’s why I think we should handle this the same way Element does.

@Guocork
Copy link
Contributor Author

Guocork commented Jan 1, 2025

Of course, there’s also the case where the user sets the room name to a special character, like "😊😊😊" or "!!!". In this case, the modified code won’t use the username as the avatar and will return an empty string. However, I’d guess that users who set the room name like this would also set an avatar for the room, so the room can display the avatar directly.

@kevinaboos
Copy link
Member

kevinaboos commented Jan 1, 2025

Oh ok so we should just skip the leading @ sign then. I do that when displaying user avatars based on usernames, but we didn't apply it to room names yet.

Seems like you could just use the same function here:

robrix/src/utils.rs

Lines 118 to 123 in da624f3

pub fn user_name_first_letter(user_name: &str) -> Option<&str> {
use unicode_segmentation::UnicodeSegmentation;
user_name
.graphemes(true)
.find(|&g| g != "@")
}

@kevinaboos
Copy link
Member

However, I’d guess that users who set the room name like this would also set an avatar for the room, so the room can display the avatar directly.

We cannot assume that, hence my suggestion above.

@Guocork
Copy link
Contributor Author

Guocork commented Jan 2, 2025

Oh ok so we should just skip the leading @ sign then. I do that when displaying user avatars based on usernames, but we didn't apply it to room names yet.

Seems like you could just use the same function here:

robrix/src/utils.rs

Lines 118 to 123 in da624f3

pub fn user_name_first_letter(user_name: &str) -> Option<&str> {
use unicode_segmentation::UnicodeSegmentation;
user_name
.graphemes(true)
.find(|&g| g != "@")
}

Ok, I get it. Now it just skip @.

@kevinaboos kevinaboos changed the title Show valid characters. Skip the @ char when displaying a room Avatar based on its name Jan 2, 2025
@kevinaboos kevinaboos merged commit f0e91c1 into project-robius:main Jan 2, 2025
3 checks passed
@Guocork Guocork deleted the Unicode branch January 2, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants