From b9eca84d34967c1b00e72793fd909c10f4dcef88 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 28 Nov 2010 10:14:34 -0500 Subject: [PATCH] telepathyClient: Implement Sent signals. This will allow us to update our notifications when someone uses a different Telepathy client to send messages. https://bugzilla.gnome.org/show_bug.cgi?id=635991 --- js/misc/telepathy.js | 4 ++- js/ui/telepathyClient.js | 58 ++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/js/misc/telepathy.js b/js/misc/telepathy.js index 3a8d7e809..6de80c0ad 100644 --- a/js/misc/telepathy.js +++ b/js/misc/telepathy.js @@ -272,7 +272,9 @@ const ChannelTextIface = { ], signals: [ { name: 'Received', - inSignature: 'uuuuus' } + inSignature: 'uuuuus' }, + { name: 'Sent', + inSignature: 'uus' } ] }; let ChannelText = DBus.makeProxyClass(ChannelTextIface); diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js index c11d0ba58..57cb78f05 100644 --- a/js/ui/telepathyClient.js +++ b/js/ui/telepathyClient.js @@ -44,6 +44,10 @@ subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.ChannelType'] = Telepathy.C subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetHandleType'] = Telepathy.HandleType.LIST; subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetID'] = 'subscribe'; +const NotificationDirection = { + SENT: 'chat-sent', + RECEIVED: 'chat-received' +}; // This is GNOME Shell's implementation of the Telepathy 'Client' // interface. Specifically, the shell is a Telepathy 'Observer', which @@ -471,11 +475,14 @@ Source.prototype = { })); } + this._notification = new Notification(this); + // Since we only create sources when receiving a message, this // is a plausible default this._presence = Telepathy.ConnectionPresenceType.AVAILABLE; this._channelText = new Telepathy.ChannelText(DBus.session, connName, channelPath); + this._sentId = this._channelText.connect('Sent', Lang.bind(this, this._messageSent)); this._receivedId = this._channelText.connect('Received', Lang.bind(this, this._messageReceived)); this._channelText.ListPendingMessagesRemote(false, Lang.bind(this, this._gotPendingMessages)); @@ -519,22 +526,27 @@ Source.prototype = { _channelClosed: function() { this._channel.disconnect(this._closedId); this._channelText.disconnect(this._receivedId); + this._channelText.disconnect(this._sentId); this.destroy(); }, - _ensureNotification: function() { - if (!Main.messageTray.contains(this)) - Main.messageTray.add(this); - - if (!this._notification) - this._notification = new Notification(this); - }, - _messageReceived: function(channel, id, timestamp, sender, type, flags, text) { - this._ensureNotification(); - this._notification.appendMessage(text, timestamp); - this.notify(this._notification); + this._notification.appendMessage(text, timestamp, NotificationDirection.RECEIVED); + this.notify(); + }, + + // This is called for both messages we send from + // our client and other clients as well. + _messageSent: function(channel, timestamp, type, text) { + this._notification.appendMessage(text, timestamp, NotificationDirection.SENT); + }, + + notify: function() { + if (!Main.messageTray.contains(this)) + Main.messageTray.add(this); + + MessageTray.Source.prototype.notify.call(this, this._notification); }, respond: function(text) { @@ -542,22 +554,22 @@ Source.prototype = { }, setPresence: function(presence, message) { - let msg, notify; + let msg, shouldNotify; if (presence == Telepathy.ConnectionPresenceType.AVAILABLE) { msg = _("%s is online.").format(this.title); - notify = (this._presence == Telepathy.ConnectionPresenceType.OFFLINE); + shouldNotify = (this._presence == Telepathy.ConnectionPresenceType.OFFLINE); } else if (presence == Telepathy.ConnectionPresenceType.OFFLINE || presence == Telepathy.ConnectionPresenceType.EXTENDED_AWAY) { presence = Telepathy.ConnectionPresenceType.OFFLINE; msg = _("%s is offline.").format(this.title); - notify = (this._presence != Telepathy.ConnectionPresenceType.OFFLINE); + shouldNotify = (this._presence != Telepathy.ConnectionPresenceType.OFFLINE); } else if (presence == Telepathy.ConnectionPresenceType.AWAY) { msg = _("%s is away.").format(this.title); - notify = false; + shouldNotify = false; } else if (presence == Telepathy.ConnectionPresenceType.BUSY) { msg = _("%s is busy.").format(this.title); - notify = false; + shouldNotify = false; } else return; @@ -566,10 +578,9 @@ Source.prototype = { if (message) msg += ' (' + GLib.markup_escape_text(message, -1) + ')'; - this._ensureNotification(); - this._notification.appendPresence(msg, notify); - if (notify) - this.notify(this._notification); + this._notification.appendPresence(msg, shouldNotify); + if (shouldNotify) + this.notify(); } }; @@ -591,9 +602,9 @@ Notification.prototype = { this._timestampTimeoutId = 0; }, - appendMessage: function(text, timestamp) { + appendMessage: function(text, timestamp, direction) { this.update(this.source.title, text, { customContent: true }); - this._append(text, 'chat-received', timestamp); + this._append(text, direction, timestamp); }, _append: function(text, style, timestamp) { @@ -679,8 +690,9 @@ Notification.prototype = { if (text == '') return; + // Telepathy sends out the Sent signal for us. + // see Source._messageSent this._responseEntry.set_text(''); - this._append(text, 'chat-sent'); this.source.respond(text); } };