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
This commit is contained in:
parent
6ff69da0de
commit
e6aee5d7ea
@ -240,7 +240,15 @@ Source.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
respond: function(text) {
|
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);
|
this._channel.send_message_async(msg, 0, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -313,14 +321,24 @@ Notification.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
appendMessage: function(message, direction) {
|
appendMessage: function(message, direction) {
|
||||||
|
let type = message.get_message_type();
|
||||||
let [text, flags] = message.to_text();
|
let [text, flags] = message.to_text();
|
||||||
let timestamp = message.get_received_timestamp();
|
let timestamp = message.get_received_timestamp();
|
||||||
|
|
||||||
this.update(this.source.title, text, { customContent: true });
|
let messageBody = GLib.markup_escape_text(text, -1);
|
||||||
this._append(text, direction, timestamp);
|
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);
|
let currentTime = (Date.now() / 1000);
|
||||||
if (!timestamp)
|
if (!timestamp)
|
||||||
timestamp = currentTime;
|
timestamp = currentTime;
|
||||||
@ -332,8 +350,9 @@ Notification.prototype = {
|
|||||||
if (this._timestampTimeoutId)
|
if (this._timestampTimeoutId)
|
||||||
Mainloop.source_remove(this._timestampTimeoutId);
|
Mainloop.source_remove(this._timestampTimeoutId);
|
||||||
|
|
||||||
let body = this.addBody(text);
|
let body = this.addBody(text, true);
|
||||||
body.add_style_class_name(style);
|
for (let i = 0; i < styles.length; i ++)
|
||||||
|
body.add_style_class_name(styles[i]);
|
||||||
|
|
||||||
this._history.unshift({ actor: body, time: timestamp, realMessage: true });
|
this._history.unshift({ actor: body, time: timestamp, realMessage: true });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user