[polari] ircParser: Support for /msg command in entry area



commit 687614e5348ad74850b1d6f5e7eeb6403de42635
Author: Kunaal Jain <kunaalus gmail com>
Date:   Fri Jan 29 11:08:56 2016 +0530

    ircParser: Support for /msg command in entry area
    
    Adds support for /msg command which sends "one-off"
    message to user without focussing on the conversation
    window.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724592

 src/application.js     |   23 ++++++++++++++++++++---
 src/chatroomManager.js |    2 +-
 src/ircParser.js       |   24 +++++++++++++++++++++++-
 src/messageDialog.js   |    3 ++-
 src/userList.js        |    3 ++-
 5 files changed, 48 insertions(+), 7 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 09f84f5..b433434 100644
--- a/src/application.js
+++ b/src/application.js
@@ -66,7 +66,7 @@ const Application = new Lang.Class({
             parameter_type: GLib.VariantType.new('(ssu)') },
           { name: 'message-user',
             activate: Lang.bind(this, this._onMessageUser),
-            parameter_type: GLib.VariantType.new('(ssu)') },
+            parameter_type: GLib.VariantType.new('(sssu)') },
           { name: 'paste-text',
             activate: Lang.bind(this, this._onPasteText),
             parameter_type: GLib.VariantType.new('s') },
@@ -351,9 +351,26 @@ const Application = new Lang.Class({
     },
 
     _onMessageUser: function(action, parameter) {
-        let [accountPath, contactName, time] = parameter.deep_unpack();
+        let [accountPath, contactName, message, time] = parameter.deep_unpack();
         this._requestChannel(accountPath, Tp.HandleType.CONTACT,
-                             contactName, time);
+                             contactName, time, Lang.bind(this, this._sendMessage, message));
+    },
+
+    _sendMessage: function(channel, message) {
+        if (!message || !channel)
+            return;
+
+        let TpMessage = Tp.ClientMessage.new_text(Tp.ChannelTextMessageType.NORMAL,
+                                                  message);
+        channel.send_message_async(TpMessage, 0, Lang.bind(this,
+            function(c, res) {
+            try {
+                c.send_message_finish(res);
+            } catch(e) {
+                // TODO: propagate to user
+                logError(e, 'Failed to send message')
+            }
+        }));
     },
 
     _onPasteText: function(action, parameter) {
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 7a7b08e..f5a21a2 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -175,7 +175,7 @@ const _ChatroomManager = new Lang.Class({
     },
 
     _onQueryActivated: function(action, parameter) {
-        let [accountPath, channelName, time] = parameter.deep_unpack();
+        let [accountPath, channelName, message, time] = parameter.deep_unpack();
         let factory = Tp.AccountManager.dup().get_factory();
         let account = factory.ensure_account(accountPath, []);
 
diff --git a/src/ircParser.js b/src/ircParser.js
index 959b847..88a468c 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -26,6 +26,7 @@ const knownCommands = {
     JOIN: N_("/JOIN <channel> - joins <channel>"),
     KICK: N_("/KICK <nick> - kicks <nick> from current channel"),
     ME: N_("/ME <action> - sends <action> to the current channel"),
+    MSG: N_("/MSG <nick> [<message>] - sends a private message to <nick>"),
     NAMES: N_("/NAMES - lists users on the current channel"),
     NICK: N_("/NICK <nickname> - sets your nick to <nickname>"),
     PART: N_("/PART [<channel>] [<reason>] - leaves <channel>, by default the current one"),
@@ -170,6 +171,26 @@ const IrcParser = new Lang.Class({
                 this._sendMessage(message);
                 break;
             }
+            case 'MSG': {
+                let nick = argv.shift();
+                let message = argv.join(' ');
+                if (!nick || !message) {
+                    output = this._createFeedbackUsage(cmd);
+                    retval = false;
+                    break;
+                }
+
+                let account = this._room.account;
+
+                let app = Gio.Application.get_default();
+                let action = app.lookup_action('message-user');
+                action.activate(GLib.Variant.new('(sssu)',
+                                                 [ account.get_object_path(),
+                                                   nick,
+                                                   message,
+                                                   Tp.USER_ACTION_TIME_NOT_USER_ACTION ]));
+                break;
+            }
             case 'NAMES': {
                 let channel = this._room.channel;
                 let members = channel.group_dup_members_contacts().map(
@@ -226,9 +247,10 @@ const IrcParser = new Lang.Class({
 
                 let app = Gio.Application.get_default();
                 let action = app.lookup_action('message-user');
-                action.activate(GLib.Variant.new('(ssu)',
+                action.activate(GLib.Variant.new('(sssu)',
                                                  [ account.get_object_path(),
                                                    nick,
+                                                   '',
                                                    Utils.getTpEventTime() ]));
                 break;
             }
diff --git a/src/messageDialog.js b/src/messageDialog.js
index cfde0bb..5418533 100644
--- a/src/messageDialog.js
+++ b/src/messageDialog.js
@@ -174,9 +174,10 @@ const MessageDialog = new Lang.Class({
 
         let app = Gio.Application.get_default();
         let action = app.lookup_action('message-user');
-        action.activate(GLib.Variant.new('(ssu)',
+        action.activate(GLib.Variant.new('(sssu)',
                                          [ account.get_object_path(),
                                            user,
+                                           '',
                                            Utils.getTpEventTime() ]));
     },
 
diff --git a/src/userList.js b/src/userList.js
index e46914d..61c75c8 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -240,9 +240,10 @@ const UserListDetails = new Lang.Class({
         let app = Gio.Application.get_default();
         let action = app.lookup_action('message-user');
         let time = Gtk.get_current_event().get_time();
-        action.activate(GLib.Variant.new('(ssu)',
+        action.activate(GLib.Variant.new('(sssu)',
                                          [ account.get_object_path(),
                                            this._user.alias,
+                                           '',
                                            time ]));
     },
 


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