gui: fix channel sort order (#17) #20
Reference in New Issue
Block a user
Delete Branch "fix-channel-order"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Channel ordering is currently broken as described in #17. This change makes sorting work correctly and cleans up the logic a bit.
Changes
ChannelsStatewrapper struct to handle this behaviorChannelStateprocessing, including data update and parent-child tree sorting, into the impl forChannelsStateChannelRemoveinto this implParent child sorting properly applies the position values, which are arbitrary integers that are supposed to be sorted in numerical order. Lexicographical sorting is use for tiebreaking, which lines up (at least in my testing) with the official client's behavior. We may handle some lexicographical edge cases differently (spaces, symbols, etc) but 1. the Desktop client compliance is best effort and 2. users should use the position fields instead of relying on text sort order. Some compatibility is still helpful for matching temporary channel positioning, especially for servers with automated channel creation workflows.
This code is a bit complicated, as the mumble protocol makes no guarantees which order the channels will be sent. It ended up being simpler to just bulk recreate the children anytime any channel update is sent. I don't expect this to ever have performance issues, though maybe someday some server with 10,000 channels will send us a bug report 😆
Testing
I tested this change by creating a bunch of channel with various sort orders and names. I compared the behavior with the official desktop client and our client seemed to follow along.
Overall LGTM.
@@ -94,8 +86,121 @@ pub struct Chat {}#[derive(Default)]Note unrelated to this PR: We should consider adding
derive(Debug)to a lot of our structs to make logging easier in the future.@@ -98,0 +95,4 @@}impl ChannelState {pub fn update_from_ChannelState(Nit: not snake case
@@ -99,0 +145,4 @@let mut to_sort: Vec<(ChannelId, Option<ChannelId>, i32, String)> = Vec::new();for (id, state) in self.channels.iter() {// Hnadle channels with no parent (the root channel)Nit: Hnadle -> Handle