[gnome-shell] telepathyClient: Add support for the ACTION message type



commit e6aee5d7ea19a1377c0e7d3f33e2c7316e1bbe62
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Feb 26 09:38:25 2011 -0500

    telepathyClient: Add support for the ACTION message type
    
    This message type is usually supported by the '/me' command
    in IRC and IM clients.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642793

 js/ui/telepathyClient.js |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js
index 89a1861..de504b4 100644
--- a/js/ui/telepathyClient.js
+++ b/js/ui/telepathyClient.js
@@ -240,7 +240,15 @@ Source.prototype = {
     },
 
     respond: function(text) {
-        let msg = Tp.ClientMessage.new_text(Tp.ChannelTextMessageType.NORMAL, text);
+        let type;
+        if (text.slice(0, 4) == '/me ') {
+            type = Tp.ChannelTextMessageType.ACTION;
+            text = text.slice(4);
+        } else {
+            type = Tp.ChannelTextMessageType.NORMAL;
+        }
+
+        let msg = Tp.ClientMessage.new_text(type, text);
         this._channel.send_message_async(msg, 0, null);
     },
 
@@ -313,14 +321,24 @@ Notification.prototype = {
     },
 
     appendMessage: function(message, direction) {
+        let type = message.get_message_type();
         let [text, flags] = message.to_text();
         let timestamp = message.get_received_timestamp();
 
-        this.update(this.source.title, text, { customContent: true });
-        this._append(text, direction, timestamp);
+        let messageBody = GLib.markup_escape_text(text, -1);
+        let styles = [direction];
+
+        if (type == Tp.ChannelTextMessageType.ACTION) {
+            let senderAlias = GLib.markup_escape_text(message.sender.alias, -1);
+            messageBody = '<i>%s</i> %s'.format(senderAlias, messageBody);
+            styles.push('chat-action');
+        }
+
+        this.update(this.source.title, messageBody, { customContent: true, bannerMarkup: true });
+        this._append(messageBody, styles, timestamp);
     },
 
-    _append: function(text, style, timestamp) {
+    _append: function(text, styles, timestamp) {
         let currentTime = (Date.now() / 1000);
         if (!timestamp)
             timestamp = currentTime;
@@ -332,8 +350,9 @@ Notification.prototype = {
         if (this._timestampTimeoutId)
             Mainloop.source_remove(this._timestampTimeoutId);
 
-        let body = this.addBody(text);
-        body.add_style_class_name(style);
+        let body = this.addBody(text, true);
+        for (let i = 0; i < styles.length; i ++)
+            body.add_style_class_name(styles[i]);
 
         this._history.unshift({ actor: body, time: timestamp, realMessage: true });
 



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