After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756319 - Connections should reorder in the roomlist when updating their name
Connections should reorder in the roomlist when updating their name
Status: RESOLVED FIXED
Product: polari
Classification: Applications
Component: general
3.18.x
Other Linux
: Normal minor
: ---
Assigned To: Polari maintainers
Polari maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-09 21:49 UTC by Bastian Ilsø
Modified: 2015-10-13 23:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
screenshot showing that "XYZ" is ordered before "GNOME". (19.88 KB, image/png)
2015-10-09 21:49 UTC, Bastian Ilsø
  Details
ui: resort room list if header names are changed (880 bytes, patch)
2015-10-13 05:15 UTC, Cody Welsh
none Details | Review
roomList: Resort room list if header names are changed (1.33 KB, patch)
2015-10-13 22:38 UTC, Cody Welsh
none Details | Review
roomList: Resort when header names are changed (1.20 KB, patch)
2015-10-13 23:03 UTC, Florian Müllner
committed Details | Review

Description Bastian Ilsø 2015-10-09 21:49:44 UTC
Created attachment 312986 [details]
screenshot showing that "XYZ" is ordered before "GNOME".

I have two connections activated. One is called "Freenode" and the other is called "GNOME". Polari lists the connections alphabetically in the roomlist, so that "Freenode" comes first and "GNOME" comes afterwards. However, if I rename "Freenode" to "XYZ" then the list goes out of alphabetical order. If I deactivate and activate "XYZ", then the list becomes in alphabetical order again.
Comment 1 Cody Welsh 2015-10-11 00:38:03 UTC
Looking at roomList.js and connections.js, it seems like the major difference between creation and deletion of connections is that we call req.create_account_async (where req is a Tp.AccountRequest obj) in const ConnectionDetails._createAccount, which itself calls req.create_account_finish(res).

I'm completely unfamiliar with Telepathy, though, so I have no idea (for now) how to resolve the issue.

Theoretically, though, maybe we can:

- Store the account we're editing
- Remove it temporarily
- Change the temporary room list
- Add it back to the connection list as a new connection

This would at least replicate the behavior of sorting after adding a new connection.
Comment 2 Florian Müllner 2015-10-11 01:58:13 UTC
(In reply to Cody Welsh from comment #1)
> Looking at roomList.js and connections.js, it seems like the major
> difference between creation and deletion of connections ...

Account deletion is not involved here at all - it's really just a property change (the name shown to the user) on a particular account object.


> Theoretically, though, maybe we can:
> 
> - Store the account we're editing
> - Remove it temporarily
> - Change the temporary room list
> - Add it back to the connection list as a new connection

The list doesn't really contain connections, it's a list of rooms that is sorted by account (and room type/name), then we insert a header before each row where the account is different from the one of the previous row (see gtk_list_box_set_sort_func() and gtk_list_box_set_header_func() and how we use them in roomList.js).

The closest to your suggestion is disabling the account while editing, but that has the effect that you are disconnected from all discussions during that time - not good. Luckily, that shouldn't be necessary - we can tell the list to resort using gtk_list_box_invalidate_sort() when any of the accounts in the list changes its display name (connect to the 'notify::display-name' signal) ...
Comment 3 Cody Welsh 2015-10-11 02:54:03 UTC
(In reply to Florian Müllner from comment #2)
> we can tell the
> list to resort using gtk_list_box_invalidate_sort() when any of the accounts
> in the list changes its display name (connect to the 'notify::display-name'
> signal) ...

Oh, I guess that was the missing part in my initial experimentation. I tried that a bunch of times in different locations, but didn't know about connecting said function to the signal. That would make a lot more sense! I'll take a look into it.
Comment 4 Cody Welsh 2015-10-11 21:33:35 UTC
Is there any way to access the current parent of a Gtk element? Since we're already connecting to notify::display-name in RoomListHeader, it would be pretty convenient to just call gtk_list_box_invalidate_sort() on the parent list box.
Comment 5 Florian Müllner 2015-10-11 23:13:16 UTC
(In reply to Cody Welsh from comment #4)
> Is there any way to access the current parent of a Gtk element?

Yup, gtk_widget_get_parent(). Note that the function may return null when the widget currently doesen't have a parent - we'll hit that case at least in the explicit call in _init().
Comment 6 Cody Welsh 2015-10-13 05:15:04 UTC
Created attachment 313165 [details] [review]
ui: resort room list if header names are changed

When a user updates a connection's name, the header will also change
its name. However, the room list will not resort in case the headers
are then out of order. This patch attempts to resort the room list
every time the display name is changed.
Comment 7 Florian Müllner 2015-10-13 14:42:00 UTC
Review of attachment 313165 [details] [review]:

Please provide a commit message[0] that briefly outlines why the change is done.

[0] https://wiki.gnome.org/Git/WorkingWithPatches#How_to_make_a_patch

::: src/roomList.js
@@ +185,3 @@
     _onDisplayNameChanged: function() {
         this._label.label = this._account.display_name;
+        if (this.get_parent() !== null) {

Nitpick: != is a better comparison here than !== - it's not like calling invalidate_sort() on undefined would work any more than calling it on null

@@ +186,3 @@
         this._label.label = this._account.display_name;
+        if (this.get_parent() !== null) {
+          this.get_parent().invalidate_sort();

This assumes that the GtkListBox is a direct parent of the header, which happens to be the case now, but there's no guarantee in the API that this won't change at some point.

You should at least do something like:

let parent = this.get_parent();
if (parent != null && parent instanceof Gtk.ListBox)
    parent.invalidate_sort();

to avoid exceptions when the assumption breaks. Or even future-proof the code a bit:

let parent;
do
    parent = this.get_parent();
while (parent && !(parent instanceof Gtk.ListBox));

if (parent)
    parent.invalidate_sort();
Comment 8 Florian Müllner 2015-10-13 14:46:52 UTC
(In reply to Cody Welsh from comment #6)
> Created attachment 313165 [details] [review] [review]
> ui: resort room list if header names are changed
> 
> When a user updates a connection's name, the header will also change
> its name. However, the room list will not resort in case the headers
> are then out of order. This patch attempts to resort the room list
> every time the display name is changed.

Oh, so this looks like the commit message, but it got lost when attaching the patch - in that case just minor nitpicks:
 - prefix should be "roomList", not "ui" ("ui" is either used for
   changes to GtkBuilder files, or for UI changes that span various
   modules - neither is the case here)
 - use sentence capitalization in the subject: Resort ... instead of resort
Comment 9 Cody Welsh 2015-10-13 22:38:14 UTC
Created attachment 313221 [details] [review]
roomList: Resort room list if header names are changed

When a user updates a connection's name, the header will also change
its name. However, the room list will not resort in case the headers
are then out of order. This patch attempts to resort the room list
every time the display name is changed.
Comment 10 Cody Welsh 2015-10-13 22:39:37 UTC
I hadn't considered the part about future-proofing! Sorry, I'm still learning the ecosystem :)
Comment 11 Florian Müllner 2015-10-13 23:03:03 UTC
Created attachment 313223 [details] [review]
roomList: Resort when header names are changed

Last patch version is fine, except that it applies to the previous version instead of master - here's the squashed patch that I'll push.
Comment 12 Florian Müllner 2015-10-13 23:03:42 UTC
Attachment 313223 [details] pushed as f796456 - roomList: Resort when header names are changed