Implement Sent signals for Telepathy.

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
This commit is contained in:
Jasper St. Pierre 2010-11-28 10:14:34 -05:00
parent 9ed3ce9006
commit 9efa271888
2 changed files with 26 additions and 7 deletions

View File

@ -272,7 +272,9 @@ const ChannelTextIface = {
], ],
signals: [ signals: [
{ name: 'Received', { name: 'Received',
inSignature: 'uuuuus' } inSignature: 'uuuuus' },
{ name: 'Sent',
inSignature: 'uus' }
] ]
}; };
let ChannelText = DBus.makeProxyClass(ChannelTextIface); let ChannelText = DBus.makeProxyClass(ChannelTextIface);

View File

@ -469,11 +469,15 @@ Source.prototype = {
})); }));
} }
this._notification = undefined;
this._sentMessages = [];
// Since we only create sources when receiving a message, this // Since we only create sources when receiving a message, this
// is a plausible default // is a plausible default
this._presence = Telepathy.ConnectionPresenceType.AVAILABLE; this._presence = Telepathy.ConnectionPresenceType.AVAILABLE;
this._channelText = new Telepathy.ChannelText(DBus.session, connName, channelPath); 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._receivedId = this._channelText.connect('Received', Lang.bind(this, this._messageReceived));
this._channelText.ListPendingMessagesRemote(false, Lang.bind(this, this._gotPendingMessages)); this._channelText.ListPendingMessagesRemote(false, Lang.bind(this, this._gotPendingMessages));
@ -517,6 +521,7 @@ Source.prototype = {
_channelClosed: function() { _channelClosed: function() {
this._channel.disconnect(this._closedId); this._channel.disconnect(this._closedId);
this._channelText.disconnect(this._receivedId); this._channelText.disconnect(this._receivedId);
this._channelText.disconnect(this._sentId);
this.destroy(); this.destroy();
}, },
@ -524,17 +529,30 @@ Source.prototype = {
if (!Main.messageTray.contains(this)) if (!Main.messageTray.contains(this))
Main.messageTray.add(this); Main.messageTray.add(this);
if (!this._notification) if (!this._notification) {
this._notification = new Notification(this); 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, _messageReceived: function(channel, id, timestamp, sender,
type, flags, text) { type, flags, text) {
this._ensureNotification(); this._ensureNotification();
this._notification.appendMessage(text); this._notification.appendMessage(text, false, false);
this.notify(this._notification); 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) { respond: function(text) {
this._channelText.SendRemote(Telepathy.ChannelTextMessageType.NORMAL, text); this._channelText.SendRemote(Telepathy.ChannelTextMessageType.NORMAL, text);
}, },
@ -565,7 +583,7 @@ Source.prototype = {
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>'; msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
this._ensureNotification(); this._ensureNotification();
this._notification.appendMessage(msg, true); this._notification.appendMessage(msg, true, false);
if (notify) if (notify)
this.notify(this._notification); this.notify(this._notification);
} }
@ -588,12 +606,12 @@ Notification.prototype = {
this._history = []; this._history = [];
}, },
appendMessage: function(text, asTitle) { appendMessage: function(text, asTitle, sent) {
if (asTitle) if (asTitle)
this.update(text, null, { customContent: true }); this.update(text, null, { customContent: true });
else else
this.update(this.source.title, text, { customContent: true }); 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) { _append: function(text, style) {
@ -635,7 +653,6 @@ Notification.prototype = {
return; return;
this._responseEntry.set_text(''); this._responseEntry.set_text('');
this._append(text, 'chat-sent');
this.source.respond(text); this.source.respond(text);
} }
}; };