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 867c63aff..4f30a9338 100644 --- a/js/ui/telepathyClient.js +++ b/js/ui/telepathyClient.js @@ -469,11 +469,15 @@ Source.prototype = { })); } + this._notification = undefined; + this._sentMessages = []; + // 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)); @@ -517,6 +521,7 @@ Source.prototype = { _channelClosed: function() { this._channel.disconnect(this._closedId); this._channelText.disconnect(this._receivedId); + this._channelText.disconnect(this._sentId); this.destroy(); }, @@ -524,17 +529,30 @@ Source.prototype = { if (!Main.messageTray.contains(this)) Main.messageTray.add(this); - if (!this._notification) + if (!this._notification) { this._notification = new Notification(this); + for (let i = 0; i < this._sentMessages.length; i ++) + this._notification.appendMessage(this._sentMessages[i], false, true); + this._sentMessages = []; + } }, _messageReceived: function(channel, id, timestamp, sender, type, flags, text) { this._ensureNotification(); - this._notification.appendMessage(text); + this._notification.appendMessage(text, false, false); this.notify(this._notification); }, + _messageSent: function(channel, timestamp, type, text) { + if (this._notification) { + this._notification.appendMessage(text, false, true); + this.notify(this._notification); + } else { + this._sentMessages.push(text); + } + }, + respond: function(text) { this._channelText.SendRemote(Telepathy.ChannelTextMessageType.NORMAL, text); }, @@ -565,7 +583,7 @@ Source.prototype = { msg += ' (' + GLib.markup_escape_text(message, -1) + ')'; this._ensureNotification(); - this._notification.appendMessage(msg, true); + this._notification.appendMessage(msg, true, false); if (notify) this.notify(this._notification); } @@ -588,12 +606,12 @@ Notification.prototype = { this._history = []; }, - appendMessage: function(text, asTitle) { + appendMessage: function(text, asTitle, sent) { if (asTitle) this.update(text, null, { customContent: true }); else this.update(this.source.title, text, { customContent: true }); - this._append(text, 'chat-received'); + this._append(text, sent ? 'chat-sent' : 'chat-received'); }, _append: function(text, style) { @@ -635,7 +653,6 @@ Notification.prototype = { return; this._responseEntry.set_text(''); - this._append(text, 'chat-sent'); this.source.respond(text); } };