-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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.