[polari] roomStack: Display room error message on failure to join room



commit 5a04afdad76fc070714092a7817c06e960b6cf4b
Author: Daronion <stefanosdimos 98 gmail com>
Date:   Tue May 21 19:00:19 2019 +0300

    roomStack: Display room error message on failure to join room
    
    Added a ChannelErrorBar that appears when connecting to
    a room fails. Upon becoming visible, the bar will indicate
    the type of error, and give the user the option to activate
    the reconnect-room action by clicking on a 'Retry' button.
    
    https://gitlab.gnome.org/GNOME/polari/issues/17

 src/roomStack.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
---
diff --git a/src/roomStack.js b/src/roomStack.js
index 57e6540..0701dd2 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -131,6 +131,61 @@ class SavePasswordConfirmationBar extends MessageInfoBar {
     }
 });
 
+const ChannelErrorBar = GObject.registerClass(
+class ChannelErrorBar extends MessageInfoBar {
+    _init(room) {
+        this._room = room;
+
+        super._init({ title: _('Failed to join the room') });
+
+        this.add_button(_('_Retry'), Gtk.ResponseType.ACCEPT).set({
+            action_name: 'app.reconnect-room',
+            action_target: new GLib.Variant('s', this._room.id)
+        });
+
+
+        this.connect('destroy', this._onDestroy.bind(this));
+
+        this._identifyError = this._room.connect('notify::channel-error', () => {
+            if (this._room.channel_error == '') {
+                this.revealed = false;
+                return;
+            }
+            this._updateLabels();
+            this.revealed = true;
+        });
+
+    }
+
+    _updateLabels() {
+        let text;
+
+        switch (this._room.channel_error) {
+        case Tp.error_get_dbus_name(Tp.Error.CHANNEL_FULL):
+            text = _('The room is full.');
+            break;
+        case Tp.error_get_dbus_name(Tp.Error.CHANNEL_BANNED):
+            text = _('You have been banned from the room.');
+            break;
+        case Tp.error_get_dbus_name(Tp.Error.CHANNEL_INVITE_ONLY):
+            text = _('The room is invite-only.');
+            break;
+        case Tp.error_get_dbus_name(Tp.Error.CHANNEL_KICKED):
+            text = _('You have been kicked from the room.');
+            break;
+        default:
+            text = _('It is not possible to join the room now, but you can retry later.');
+        }
+
+        this.subtitle = text;
+    }
+
+    _onDestroy() {
+        if (this._identifyError)
+            this._room.disconnect(this._identifyError);
+    }
+});
+
 const ChatPlaceholder = GObject.registerClass(
 class ChatPlaceholder extends Gtk.Overlay {
     _init(sizeGroup) {
@@ -190,6 +245,8 @@ class RoomView extends Gtk.Overlay {
         if (room.type == Tp.HandleType.CONTACT)
             this.add_overlay(new SavePasswordConfirmationBar(room));
 
+        this.add_overlay(new ChannelErrorBar(room));
+
         this._view = new ChatView(room);
         box.add(this._view);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]