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
This commit is contained in:
Jasper St. Pierre 2010-11-28 10:14:34 -05:00 committed by Dan Winship
parent aef005f451
commit b9eca84d34
2 changed files with 38 additions and 24 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

@ -44,6 +44,10 @@ subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.ChannelType'] = Telepathy.C
subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetHandleType'] = Telepathy.HandleType.LIST; subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetHandleType'] = Telepathy.HandleType.LIST;
subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetID'] = 'subscribe'; subscribedContactsChannel[Telepathy.CHANNEL_NAME + '.TargetID'] = 'subscribe';
const NotificationDirection = {
SENT: 'chat-sent',
RECEIVED: 'chat-received'
};
// This is GNOME Shell's implementation of the Telepathy 'Client' // This is GNOME Shell's implementation of the Telepathy 'Client'
// interface. Specifically, the shell is a Telepathy 'Observer', which // 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 // 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));
@ -519,22 +526,27 @@ 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();
}, },
_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, _messageReceived: function(channel, id, timestamp, sender,
type, flags, text) { type, flags, text) {
this._ensureNotification(); this._notification.appendMessage(text, timestamp, NotificationDirection.RECEIVED);
this._notification.appendMessage(text, timestamp); this.notify();
this.notify(this._notification); },
// 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) { respond: function(text) {
@ -542,22 +554,22 @@ Source.prototype = {
}, },
setPresence: function(presence, message) { setPresence: function(presence, message) {
let msg, notify; let msg, shouldNotify;
if (presence == Telepathy.ConnectionPresenceType.AVAILABLE) { if (presence == Telepathy.ConnectionPresenceType.AVAILABLE) {
msg = _("%s is online.").format(this.title); 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 || } else if (presence == Telepathy.ConnectionPresenceType.OFFLINE ||
presence == Telepathy.ConnectionPresenceType.EXTENDED_AWAY) { presence == Telepathy.ConnectionPresenceType.EXTENDED_AWAY) {
presence = Telepathy.ConnectionPresenceType.OFFLINE; presence = Telepathy.ConnectionPresenceType.OFFLINE;
msg = _("%s is offline.").format(this.title); 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) { } else if (presence == Telepathy.ConnectionPresenceType.AWAY) {
msg = _("%s is away.").format(this.title); msg = _("%s is away.").format(this.title);
notify = false; shouldNotify = false;
} else if (presence == Telepathy.ConnectionPresenceType.BUSY) { } else if (presence == Telepathy.ConnectionPresenceType.BUSY) {
msg = _("%s is busy.").format(this.title); msg = _("%s is busy.").format(this.title);
notify = false; shouldNotify = false;
} else } else
return; return;
@ -566,10 +578,9 @@ Source.prototype = {
if (message) if (message)
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>'; msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
this._ensureNotification(); this._notification.appendPresence(msg, shouldNotify);
this._notification.appendPresence(msg, notify); if (shouldNotify)
if (notify) this.notify();
this.notify(this._notification);
} }
}; };
@ -591,9 +602,9 @@ Notification.prototype = {
this._timestampTimeoutId = 0; this._timestampTimeoutId = 0;
}, },
appendMessage: function(text, timestamp) { appendMessage: function(text, timestamp, direction) {
this.update(this.source.title, text, { customContent: true }); this.update(this.source.title, text, { customContent: true });
this._append(text, 'chat-received', timestamp); this._append(text, direction, timestamp);
}, },
_append: function(text, style, timestamp) { _append: function(text, style, timestamp) {
@ -679,8 +690,9 @@ Notification.prototype = {
if (text == '') if (text == '')
return; return;
// Telepathy sends out the Sent signal for us.
// see Source._messageSent
this._responseEntry.set_text(''); this._responseEntry.set_text('');
this._append(text, 'chat-sent');
this.source.respond(text); this.source.respond(text);
} }
}; };