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

🚀 : Ensure Consistent User Order in Room Data Initialization #9

Open
xuelink opened this issue Jun 22, 2024 · 0 comments
Open

🚀 : Ensure Consistent User Order in Room Data Initialization #9

xuelink opened this issue Jun 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@xuelink
Copy link
Member

xuelink commented Jun 22, 2024

Is your feature request related to a problem? Please describe.
I'm always frustrated when the order of users in the users array is inconsistent in the roomData object. Currently, the order is only reassigned when sender is greater than to, which can lead to unpredictability and potential issues when comparing or processing room data.

Describe the solution you'd like
I would like to improve the initialization of the roomData object to ensure a consistent and predictable order of user IDs. This can be achieved by sorting the users array numerically and then converting the user IDs back to strings. This approach guarantees that the user IDs are always stored in a consistent order.

Describe alternatives you've considered
An alternative solution could be to conditionally assign the roomData object only when sender is greater than to, as currently implemented. However, this approach does not ensure a consistent order of user IDs in all cases, which can lead to potential issues.

Additional context
Here is the improved version of the code to ensure consistent user order:

let roomData = {
  users: [sender, to].map(String).sort((a, b) => a.localeCompare(b)),
  copilot: [],
  typing: [false, false],
  unseen: [0, 0],
};

Contributor: @gab within the app

This version sorts the user IDs as strings, ensuring a consistent and predictable order in the users array.

If you want to speed up the process of this issue, please send 🚀 as a reaction.

@xuelink xuelink added the enhancement New feature or request label Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant