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 769655 - Restructure and split up ChatroomManager
Restructure and split up ChatroomManager
Status: RESOLVED FIXED
Product: polari
Classification: Applications
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Polari maintainers
Polari maintainers
Depends on: 769582 769583 769584 769592
Blocks: 751575
 
 
Reported: 2016-08-09 01:14 UTC by Florian Müllner
Modified: 2016-08-29 23:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
mainWindow: Manage active room via an :active-room property (20.34 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
mainWindow: Focus the first added room (2.95 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
mainWindow: Track last selected room (4.52 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
chatroomManager: Handle channel requests (11.95 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
application: Initialize actions as early as possible (2.91 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
chatroomManager: Split out room management (30.52 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
none Details | Review
chatroomManager: Rename to TelepathyClient (4.18 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
telepathyClient: Stop using the singleton pattern (6.30 KB, patch)
2016-08-09 01:15 UTC, Florian Müllner
committed Details | Review
chatroomManager: Split out room management (30.52 KB, patch)
2016-08-29 12:08 UTC, Florian Müllner
committed Details | Review

Description Florian Müllner 2016-08-09 01:14:54 UTC
See the extensive commit message of the first patch for a rationale.
Comment 1 Florian Müllner 2016-08-09 01:15:01 UTC
Created attachment 332960 [details] [review]
mainWindow: Manage active room via an :active-room property

The ChatroomManager class hasn't aged very well, and has become
increasingly muddy with regard to what it actually does and how
it relates to other components (in particular the application):

 - ChatroomManager manages joined rooms, except updating
   which rooms should be joined is done by the application

 - ChatroomManager handles incoming channel requests from
   mission-control, but our own channel requests are made
   by the application

 - managing the list of rooms means we want it available as
   early as possible to other components; being a Telepathy
   handler and observer means we only want to start it when
   we should establish network connections

We will untangle that mess over the next couple of commits, starting
with something simple: managing the active room. Code-wise it would
be convenient to keep using an always available singleton for this,
with application being the obvious choice. However conceptually, the
window is better suited to manage the active room, as the whole concept
is tied to some visual representation - being "active" really means
being the currently selected room in the window. If we are ever going
to support more than a single main window, we surely don't want all
windows to show the same room. Similarly, if we allow running in the
background without any windows, the idea that any of the joined rooms
was active seems silly. So move tracking of the active room from the
ChatroomManager into the window.
Comment 2 Florian Müllner 2016-08-09 01:15:09 UTC
Created attachment 332961 [details] [review]
mainWindow: Focus the first added room

Now that the active room is a property of the window, it makes sense
to move initialization there as well rather than leaving it in the
chatroom manager.
Comment 3 Florian Müllner 2016-08-09 01:15:16 UTC
Created attachment 332962 [details] [review]
mainWindow: Track last selected room

Equally, the tracking of the last selected room is now easier done by
the window. For now, we still rely on the correct room being restored
first, but we will soon handle this in the window as well.
Comment 4 Florian Müllner 2016-08-09 01:15:25 UTC
Created attachment 332963 [details] [review]
chatroomManager: Handle channel requests

ChatroomManager already handles most connection-related actions - handling
and observing channels and (re)connecting accounts. It makes sense to assume
control over the remaining bit as well, and handle requesting new channels
as well.
Comment 5 Florian Müllner 2016-08-09 01:15:32 UTC
Created attachment 332964 [details] [review]
application: Initialize actions as early as possible

Until recently, some of the action create hooks were using some of the
singletons that are initialized on startup, so we had to create those
first before adding the actions. Now that this is no longer the case,
we can reorder the code so that all application actions are always
available, including to the singletons created on startup.
Comment 6 Florian Müllner 2016-08-09 01:15:39 UTC
Created attachment 332965 [details] [review]
chatroomManager: Split out room management

Originally rooms were tightly coupled with channels - a room was created
and added when we observed a channel, and removed when the channel was
invalidated - so doing room management in the telepathy observer/handler
made a lot of sense. But nowadays where we show disconnected rooms, the
only point where room management overlaps with channel handling is where
we match a channel to a (usually existing) room. It is time to split out
room management into its own class, including maintaining the list of
saved channels (where updating the list got split from restoring rooms
when the code moved into the application).
Comment 7 Florian Müllner 2016-08-09 01:15:46 UTC
Created attachment 332966 [details] [review]
chatroomManager: Rename to TelepathyClient

With room management now moved to its own module, the existing name
becomes a relict that doesn't make sense anymore. As the primary
functions are now registering as a channel observer and handler with
and requesting channels from mission control, TelepathyClient looks like
a reasonable pick.
Comment 8 Florian Müllner 2016-08-09 01:15:53 UTC
Created attachment 332967 [details] [review]
telepathyClient: Stop using the singleton pattern

The pattern made a lot of sense while many components needed to access it
for its room management, but now that it has been reduced to its function
as telepathy client, it is cleaner to make it a regular class that is
instantiated by the application when its functionality is actually
needed.
This also allows us to implement Telepathy.BaseClient directly instead of
using a helper class, and to get rid of the awkward lateInit() split.
Comment 9 Bastian Ilsø 2016-08-14 14:09:28 UTC
Review of attachment 332960 [details] [review]:

some comments and questions. :-)

::: src/application.js
@@ +536,2 @@
     _onLeaveCurrentRoom: function() {
+        let room = this._window.active_room;

question, what is the difference between this.active_window.active_room; and this.window.active_room? should this.active_window.active_room; be used here?

::: src/chatroomManager.js
@@ +476,3 @@
     },
 
+    _onActiveRoomChanged: function(window) {

in roomList, roomStack and userList it's called just "_activeRoomChanged", maybe we want to be consistent and do that here too?

::: src/mainWindow.js
@@ +115,3 @@
+                                                'active-room',
+                                                GObject.ParamFlags.READWRITE,
+                                                Polari.Room.$gtype)

mmmh, can you have dollarmarks in variable names? im just wondering in which cases you are supposed to do that.

@@ +118,2 @@
     },
+    Signals: { 'active-room-state-changed': {} },

I can see that this signal is connected to inside application.js, but to me it looks like it's emitted the same time as notify::active-room (and I perceive the meaning of the name to be the same). Can you elaborate a bit why this is necessary to have in addition to that?

@@ +127,3 @@
+        this._displayNameChangedId = 0;
+        this._topicChangedId = 0;
+        this._membersChangedId = 0;

should this._channelChangedId also be declared here?

this._channelChangedId = 0;
Comment 10 Florian Müllner 2016-08-14 17:30:43 UTC
(In reply to Bastian Ilsø from comment #9)
> ::: src/application.js
> @@ +536,2 @@
>      _onLeaveCurrentRoom: function() {
> +        let room = this._window.active_room;
> 
> question, what is the difference between this.active_window.active_room; and
> this.window.active_room? should this.active_window.active_room; be used here?

GtkApplication:active-window refers to the most recently focused app window. this._window is a simple propery we use to track the (single) main window we create. As long as we are a single-window application, there's no difference between the two. There's a patch to get rid of the _window property on the wip/window-experiments branch that I guess I could apply, as this._window is
 - wrong if we want to support multiple window
 - pointless if we don't (because it's just the same as
   GtkApplication:active-window)

I'm indifferent about this, but if we kill off the separate _window property now, it should be in a separate patch anyway ...



> ::: src/chatroomManager.js
> @@ +476,3 @@
>      },
>  
> +    _onActiveRoomChanged: function(window) {
> 
> in roomList, roomStack and userList it's called just "_activeRoomChanged",
> maybe we want to be consistent and do that here too?

On the other hand, we usually use _onSignalName (or _onPropertyNameChanged for ::notify), so arguably _activeRoomChanged() is wrong :-)

I don't mind changing it either way *shrug*


> ::: src/mainWindow.js
> @@ +115,3 @@
> +                                                'active-room',
> +                                               
> GObject.ParamFlags.READWRITE,
> +                                                Polari.Room.$gtype)
> 
> mmmh, can you have dollarmarks in variable names? im just wondering in which
> cases you are supposed to do that.

It's not a random variable name though - it's added by gjs to refer to the prototype's actual GType. I haven't been involved in that, but I figure the "uncommon" name was used to make conflicts with regular code less likely ...


> @@ +118,2 @@
>      },
> +    Signals: { 'active-room-state-changed': {} },
> 
> I can see that this signal is connected to inside application.js, but to me
> it looks like it's emitted the same time as notify::active-room (and I
> perceive the meaning of the name to be the same). Can you elaborate a bit
> why this is necessary to have in addition to that?

It is not necessary, just a bit more convenient - it's not *only* emitted on room changes, but also when the active room's channel changes. We use that to track if the currently visible room is connected (i.e. whether the userList should be available etc.). See the ::active-state-changed signal that used to be in ChatroomManager that this signal replaces.


> @@ +127,3 @@
> +        this._displayNameChangedId = 0;
> +        this._topicChangedId = 0;
> +        this._membersChangedId = 0;
> 
> should this._channelChangedId also be declared here?
> 
> this._channelChangedId = 0;

Yup.
Comment 11 Rares Visalom 2016-08-15 11:00:24 UTC
Review of attachment 332960 [details] [review]:

looks good to me (with Bastian's observation about this._channelChangedId = 0 initialization).
Comment 12 Rares Visalom 2016-08-15 11:11:34 UTC
Review of attachment 332961 [details] [review]:

looks good to me.
Comment 13 Bastian Ilsø 2016-08-15 18:27:23 UTC
Review of attachment 332961 [details] [review]:

isn't the initialization still happening in chatroom manager, technically speaking? i mean, _onRoomAdded sets the active_room label but only if it was already set which the chatroom manager does? Would it make sense to have this.active_room = null in init?
Comment 14 Bastian Ilsø 2016-08-15 18:37:54 UTC
Review of attachment 332962 [details] [review]:

looks good to me
Comment 15 Rares Visalom 2016-08-15 21:42:48 UTC
Review of attachment 332962 [details] [review]:

looks good to me.
Comment 16 Rares Visalom 2016-08-15 22:42:21 UTC
Review of attachment 332963 [details] [review]:

looks good to me.
Comment 17 Rares Visalom 2016-08-15 22:49:29 UTC
Review of attachment 332964 [details] [review]:

looks good to me.
Comment 18 Rares Visalom 2016-08-16 12:29:58 UTC
Review of attachment 332966 [details] [review]:

looks good to me.
Comment 19 Rares Visalom 2016-08-16 12:43:31 UTC
Review of attachment 332967 [details] [review]:

looks good to me.
Comment 20 Rares Visalom 2016-08-16 12:44:00 UTC
Review of attachment 332965 [details] [review]:

looks good to me.
Comment 21 Florian Müllner 2016-08-29 12:08:04 UTC
Created attachment 334359 [details] [review]
chatroomManager: Split out room management

Fix parameter unpacking for 'message-user' action (in _onQueryActivated): the (unused) 'message' parameter is positioned before the 'time' parameter, not after.
Comment 22 Florian Müllner 2016-08-29 23:30:02 UTC
Attachment 332960 [details] pushed as 59daae7 - mainWindow: Manage active room via an :active-room property
Attachment 332961 [details] pushed as 2723a61 - mainWindow: Focus the first added room
Attachment 332962 [details] pushed as 4a55bb3 - mainWindow: Track last selected room
Attachment 332963 [details] pushed as 9b1497e - chatroomManager: Handle channel requests
Attachment 332964 [details] pushed as a615198 - application: Initialize actions as early as possible
Attachment 332966 [details] pushed as 7bbb220 - chatroomManager: Rename to TelepathyClient
Attachment 332967 [details] pushed as 3b0eae3 - telepathyClient: Stop using the singleton pattern
Attachment 334359 [details] pushed as 7da6b54 - chatroomManager: Split out room management