2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-08-16 11:07:40 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2010-04-14 10:24:14 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2010-02-02 10:21:47 -05:00
|
|
|
const Lang = imports.lang;
|
2010-11-25 09:29:41 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
2011-02-08 07:17:29 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-04-16 17:24:34 -04:00
|
|
|
const Signals = imports.signals;
|
2010-02-02 10:21:47 -05:00
|
|
|
const St = imports.gi.St;
|
2011-03-07 17:10:53 -05:00
|
|
|
const Tpl = imports.gi.TelepathyLogger;
|
2011-02-07 11:34:08 -05:00
|
|
|
const Tp = imports.gi.TelepathyGLib;
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-02-20 03:41:51 -05:00
|
|
|
const History = imports.misc.history;
|
2011-08-24 10:33:44 -04:00
|
|
|
const Params = imports.misc.params;
|
2010-02-02 10:21:47 -05:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
// See Notification.appendMessage
|
2010-11-25 09:29:41 -05:00
|
|
|
const SCROLLBACK_IMMEDIATE_TIME = 60; // 1 minute
|
2010-02-22 14:23:36 -05:00
|
|
|
const SCROLLBACK_RECENT_TIME = 15 * 60; // 15 minutes
|
|
|
|
const SCROLLBACK_RECENT_LENGTH = 20;
|
|
|
|
const SCROLLBACK_IDLE_LENGTH = 5;
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
// See Source._displayPendingMessages
|
|
|
|
const SCROLLBACK_HISTORY_LINES = 10;
|
|
|
|
|
2011-07-07 08:42:07 -04:00
|
|
|
// See Notification._onEntryChanged
|
|
|
|
const COMPOSING_STOP_TIMEOUT = 5;
|
|
|
|
|
2010-11-28 10:14:34 -05:00
|
|
|
const NotificationDirection = {
|
|
|
|
SENT: 'chat-sent',
|
|
|
|
RECEIVED: 'chat-received'
|
|
|
|
};
|
2010-04-16 15:18:32 -04:00
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
function makeMessageFromTpMessage(tpMessage, direction) {
|
|
|
|
let [text, flags] = tpMessage.to_text();
|
2011-08-23 13:38:51 -04:00
|
|
|
|
|
|
|
let timestamp = tpMessage.get_sent_timestamp();
|
|
|
|
if (timestamp == 0)
|
|
|
|
timestamp = tpMessage.get_received_timestamp();
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
return {
|
|
|
|
messageType: tpMessage.get_message_type(),
|
|
|
|
text: text,
|
|
|
|
sender: tpMessage.sender.alias,
|
2011-08-23 13:38:51 -04:00
|
|
|
timestamp: timestamp,
|
2011-03-07 17:10:53 -05:00
|
|
|
direction: direction
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function makeMessageFromTplEvent(event) {
|
|
|
|
let sent = event.get_sender().get_entity_type() == Tpl.EntityType.SELF;
|
|
|
|
let direction = sent ? NotificationDirection.SENT : NotificationDirection.RECEIVED;
|
|
|
|
|
|
|
|
return {
|
|
|
|
messageType: event.get_message_type(),
|
|
|
|
text: event.get_message(),
|
|
|
|
sender: event.get_sender().get_alias(),
|
|
|
|
timestamp: event.get_timestamp(),
|
|
|
|
direction: direction
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const Client = new Lang.Class({
|
|
|
|
Name: 'Client',
|
2010-02-02 10:21:47 -05:00
|
|
|
|
|
|
|
_init : function() {
|
2011-06-30 05:53:44 -04:00
|
|
|
// channel path -> ChatSource
|
|
|
|
this._chatSources = {};
|
2011-07-07 08:42:07 -04:00
|
|
|
this._chatState = Tp.ChannelChatState.ACTIVE;
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-09-14 11:01:48 -04:00
|
|
|
// account path -> AccountNotification
|
|
|
|
this._accountNotifications = {};
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
// Define features we want
|
|
|
|
this._accountManager = Tp.AccountManager.dup();
|
|
|
|
let factory = this._accountManager.get_factory();
|
|
|
|
factory.add_account_features([Tp.Account.get_feature_quark_connection()]);
|
|
|
|
factory.add_connection_features([Tp.Connection.get_feature_quark_contact_list()]);
|
|
|
|
factory.add_channel_features([Tp.Channel.get_feature_quark_contacts()]);
|
|
|
|
factory.add_contact_features([Tp.ContactFeature.ALIAS,
|
|
|
|
Tp.ContactFeature.AVATAR_DATA,
|
|
|
|
Tp.ContactFeature.PRESENCE,
|
|
|
|
Tp.ContactFeature.SUBSCRIPTION_STATES]);
|
|
|
|
|
2011-02-07 11:34:08 -05:00
|
|
|
// Set up a SimpleObserver, which will call _observeChannels whenever a
|
|
|
|
// channel matching its filters is detected.
|
|
|
|
// The second argument, recover, means _observeChannels will be run
|
|
|
|
// for any existing channel as well.
|
2011-08-26 06:27:40 -04:00
|
|
|
this._tpClient = new Shell.TpClient({ 'account-manager': this._accountManager,
|
2011-06-23 17:57:48 -04:00
|
|
|
'name': 'GnomeShell',
|
|
|
|
'uniquify-name': true })
|
|
|
|
this._tpClient.set_observe_channels_func(
|
2011-03-23 06:22:42 -04:00
|
|
|
Lang.bind(this, this._observeChannels));
|
2011-06-23 17:57:48 -04:00
|
|
|
this._tpClient.set_approve_channels_func(
|
2011-04-05 07:28:11 -04:00
|
|
|
Lang.bind(this, this._approveChannels));
|
2011-06-23 17:57:48 -04:00
|
|
|
this._tpClient.set_handle_channels_func(
|
2011-04-05 07:28:11 -04:00
|
|
|
Lang.bind(this, this._handleChannels));
|
2011-02-07 11:34:08 -05:00
|
|
|
|
2011-08-26 06:27:40 -04:00
|
|
|
// Workaround for gjs not supporting GPtrArray in signals.
|
|
|
|
// See BGO bug #653941 for context.
|
|
|
|
this._tpClient.set_contact_list_changed_func(
|
|
|
|
Lang.bind(this, this._contactListChanged));
|
|
|
|
|
2011-06-24 08:29:23 -04:00
|
|
|
// Allow other clients (such as Empathy) to pre-empt our channels if
|
|
|
|
// needed
|
|
|
|
this._tpClient.set_delegated_channels_callback(
|
|
|
|
Lang.bind(this, this._delegatedChannelsCb));
|
|
|
|
|
2011-02-07 11:34:08 -05:00
|
|
|
try {
|
2011-06-23 17:57:48 -04:00
|
|
|
this._tpClient.register();
|
2011-02-07 11:34:08 -05:00
|
|
|
} catch (e) {
|
2011-04-05 07:28:11 -04:00
|
|
|
throw new Error('Couldn\'t register Telepathy client. Error: \n' + e);
|
2011-02-07 11:34:08 -05:00
|
|
|
}
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
// Watch subscription requests and connection errors
|
|
|
|
this._subscriptionSource = null;
|
2011-08-27 20:26:25 -04:00
|
|
|
this._accountSource = null;
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
this._accountManager.connect('account-validity-changed',
|
|
|
|
Lang.bind(this, this._accountValidityChanged));
|
|
|
|
|
|
|
|
this._accountManager.prepare_async(null, Lang.bind(this, this._accountManagerPrepared));
|
2011-02-07 11:34:08 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_observeChannels: function(observer, account, conn, channels,
|
|
|
|
dispatchOp, requests, context) {
|
|
|
|
let len = channels.length;
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
let channel = channels[i];
|
|
|
|
let [targetHandle, targetHandleType] = channel.get_handle();
|
|
|
|
|
2012-06-05 06:39:30 -04:00
|
|
|
if (Shell.is_channel_invalidated(channel))
|
|
|
|
continue;
|
|
|
|
|
2011-02-07 11:34:08 -05:00
|
|
|
/* Only observe contact text channels */
|
|
|
|
if ((!(channel instanceof Tp.TextChannel)) ||
|
|
|
|
targetHandleType != Tp.HandleType.CONTACT)
|
|
|
|
continue;
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
this._createChatSource(account, conn, channel, channel.get_target_contact());
|
2011-02-07 11:34:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
context.accept();
|
2011-02-09 05:35:50 -05:00
|
|
|
},
|
|
|
|
|
2011-07-17 15:25:42 -04:00
|
|
|
_createChatSource: function(account, conn, channel, contact) {
|
2011-06-30 05:53:44 -04:00
|
|
|
if (this._chatSources[channel.get_object_path()])
|
2011-02-09 05:35:50 -05:00
|
|
|
return;
|
|
|
|
|
2011-06-30 05:53:44 -04:00
|
|
|
let source = new ChatSource(account, conn, channel, contact, this._tpClient);
|
2011-02-09 05:35:50 -05:00
|
|
|
|
2011-06-30 05:53:44 -04:00
|
|
|
this._chatSources[channel.get_object_path()] = source;
|
2011-02-09 05:35:50 -05:00
|
|
|
source.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
2011-06-23 17:57:48 -04:00
|
|
|
if (this._tpClient.is_handling_channel(channel)) {
|
2011-04-05 07:28:11 -04:00
|
|
|
// The chat box has been destroyed so it can't
|
|
|
|
// handle the channel any more.
|
2011-06-28 12:06:54 -04:00
|
|
|
channel.close_async(function(src, result) {
|
|
|
|
channel.close_finish(result);
|
|
|
|
});
|
2011-04-05 07:28:11 -04:00
|
|
|
}
|
|
|
|
|
2011-06-30 05:53:44 -04:00
|
|
|
delete this._chatSources[channel.get_object_path()];
|
2011-02-09 05:35:50 -05:00
|
|
|
}));
|
2011-04-05 07:28:11 -04:00
|
|
|
},
|
|
|
|
|
2011-07-17 15:25:42 -04:00
|
|
|
_handleChannels: function(handler, account, conn, channels,
|
|
|
|
requests, user_action_time, context) {
|
2011-12-15 06:24:38 -05:00
|
|
|
this._handlingChannels(account, conn, channels, true);
|
2011-07-17 15:25:42 -04:00
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-12-15 06:24:38 -05:00
|
|
|
_handlingChannels: function(account, conn, channels, notify) {
|
2011-04-05 07:28:11 -04:00
|
|
|
let len = channels.length;
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
let channel = channels[i];
|
|
|
|
|
|
|
|
// We can only handle text channel, so close any other channel
|
|
|
|
if (!(channel instanceof Tp.TextChannel)) {
|
|
|
|
channel.close_async(null);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-05 06:39:30 -04:00
|
|
|
if (Shell.is_channel_invalidated(channel))
|
|
|
|
continue;
|
|
|
|
|
2011-12-15 06:24:38 -05:00
|
|
|
// 'notify' will be true when coming from an actual HandleChannels
|
|
|
|
// call, and not when from a successful Claim call. The point is
|
|
|
|
// we don't want to notify for a channel we just claimed which
|
|
|
|
// has no new messages (for example, a new channel which only has
|
|
|
|
// a delivery notification). We rely on _displayPendingMessages()
|
|
|
|
// and _messageReceived() to notify for new messages.
|
|
|
|
|
|
|
|
// But we should still notify from HandleChannels because the
|
|
|
|
// Telepathy spec states that handlers must foreground channels
|
|
|
|
// in HandleChannels calls which are already being handled.
|
|
|
|
|
|
|
|
if (notify && this._tpClient.is_handling_channel(channel)) {
|
2011-04-05 07:28:11 -04:00
|
|
|
// We are already handling the channel, display the source
|
2011-06-30 05:53:44 -04:00
|
|
|
let source = this._chatSources[channel.get_object_path()];
|
2011-04-05 07:28:11 -04:00
|
|
|
if (source)
|
|
|
|
source.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-06-30 08:05:41 -04:00
|
|
|
_displayRoomInvitation: function(conn, channel, dispatchOp, context) {
|
|
|
|
// We can only approve the rooms if we have been invited to it
|
2011-09-12 08:33:02 -04:00
|
|
|
let selfContact = channel.group_get_self_contact();
|
|
|
|
if (selfContact == null) {
|
2011-06-30 08:05:41 -04:00
|
|
|
Shell.decline_dispatch_op(context, 'Not invited to the room');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
let [invited, inviter, reason, msg] = channel.group_get_local_pending_contact_info(selfContact);
|
2011-06-30 08:05:41 -04:00
|
|
|
if (!invited) {
|
|
|
|
Shell.decline_dispatch_op(context, 'Not invited to the room');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 06:59:23 -04:00
|
|
|
// FIXME: We don't have a 'chat room' icon (bgo #653737) use
|
|
|
|
// system-users for now as Empathy does.
|
2011-08-16 10:59:34 -04:00
|
|
|
let source = new ApproverSource(dispatchOp, _("Invitation"),
|
2011-10-07 17:35:38 -04:00
|
|
|
Gio.icon_new_for_string('system-users'));
|
2011-06-30 08:05:41 -04:00
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
let notif = new RoomInviteNotification(source, dispatchOp, channel, inviter);
|
2011-06-30 08:05:41 -04:00
|
|
|
source.notify(notif);
|
2011-04-05 07:28:11 -04:00
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-06-30 08:05:41 -04:00
|
|
|
_approveChannels: function(approver, account, conn, channels,
|
|
|
|
dispatchOp, context) {
|
|
|
|
let channel = channels[0];
|
2011-07-11 07:09:45 -04:00
|
|
|
let chanType = channel.get_channel_type();
|
|
|
|
|
2012-06-05 06:39:30 -04:00
|
|
|
if (Shell.is_channel_invalidated(channel)) {
|
|
|
|
Shell.decline_dispatch_op(context, 'Channel is invalidated');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 07:09:45 -04:00
|
|
|
if (chanType == Tp.IFACE_CHANNEL_TYPE_TEXT)
|
|
|
|
this._approveTextChannel(account, conn, channel, dispatchOp, context);
|
2012-01-11 07:39:38 -05:00
|
|
|
else if (chanType == Tp.IFACE_CHANNEL_TYPE_CALL)
|
2011-07-11 07:09:45 -04:00
|
|
|
this._approveCall(account, conn, channel, dispatchOp, context);
|
2011-08-16 11:07:40 -04:00
|
|
|
else if (chanType == Tp.IFACE_CHANNEL_TYPE_FILE_TRANSFER)
|
|
|
|
this._approveFileTransfer(account, conn, channel, dispatchOp, context);
|
2012-06-05 06:37:06 -04:00
|
|
|
else
|
|
|
|
Shell.decline_dispatch_op(context, 'Unsupported channel type');
|
2011-07-11 07:09:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_approveTextChannel: function(account, conn, channel, dispatchOp, context) {
|
2011-06-30 08:05:41 -04:00
|
|
|
let [targetHandle, targetHandleType] = channel.get_handle();
|
|
|
|
|
|
|
|
if (targetHandleType == Tp.HandleType.CONTACT) {
|
|
|
|
// Approve private text channels right away as we are going to handle it
|
|
|
|
dispatchOp.claim_with_async(this._tpClient,
|
|
|
|
Lang.bind(this, function(dispatchOp, result) {
|
|
|
|
try {
|
|
|
|
dispatchOp.claim_with_finish(result);
|
2011-12-15 06:24:38 -05:00
|
|
|
this._handlingChannels(account, conn, [channel], false);
|
2011-06-30 08:05:41 -04:00
|
|
|
} catch (err) {
|
|
|
|
throw new Error('Failed to Claim channel: ' + err);
|
|
|
|
}}));
|
|
|
|
|
|
|
|
context.accept();
|
|
|
|
} else {
|
|
|
|
this._displayRoomInvitation(conn, channel, dispatchOp, context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-11 07:09:45 -04:00
|
|
|
_approveCall: function(account, conn, channel, dispatchOp, context) {
|
|
|
|
let isVideo = false;
|
|
|
|
|
|
|
|
let props = channel.borrow_immutable_properties();
|
|
|
|
|
2012-01-11 07:39:38 -05:00
|
|
|
if (props[Tp.PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO])
|
2011-07-11 07:09:45 -04:00
|
|
|
isVideo = true;
|
|
|
|
|
|
|
|
// We got the TpContact
|
2011-08-16 10:59:34 -04:00
|
|
|
let source = new ApproverSource(dispatchOp, _("Call"), isVideo ?
|
2011-10-07 17:35:38 -04:00
|
|
|
Gio.icon_new_for_string('camera-web') :
|
|
|
|
Gio.icon_new_for_string('audio-input-microphone'));
|
2011-07-11 07:09:45 -04:00
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
let notif = new AudioVideoNotification(source, dispatchOp, channel,
|
|
|
|
channel.get_target_contact(), isVideo);
|
2011-07-11 07:09:45 -04:00
|
|
|
source.notify(notif);
|
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-08-16 11:07:40 -04:00
|
|
|
_approveFileTransfer: function(account, conn, channel, dispatchOp, context) {
|
|
|
|
// Use the icon of the file being transferred
|
|
|
|
let gicon = Gio.content_type_get_icon(channel.get_mime_type());
|
|
|
|
|
|
|
|
// We got the TpContact
|
|
|
|
let source = new ApproverSource(dispatchOp, _("File Transfer"), gicon);
|
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
2011-09-12 08:33:02 -04:00
|
|
|
let notif = new FileTransferNotification(source, dispatchOp, channel,
|
|
|
|
channel.get_target_contact());
|
2011-08-16 11:07:40 -04:00
|
|
|
source.notify(notif);
|
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-06-24 08:29:23 -04:00
|
|
|
_delegatedChannelsCb: function(client, channels) {
|
|
|
|
// Nothing to do as we don't make a distinction between observed and
|
|
|
|
// handled channels.
|
2011-08-26 06:27:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_accountManagerPrepared: function(am, result) {
|
|
|
|
am.prepare_finish(result);
|
|
|
|
|
|
|
|
let accounts = am.get_valid_accounts();
|
|
|
|
for (let i = 0; i < accounts.length; i++) {
|
|
|
|
this._accountValidityChanged(am, accounts[i], true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_accountValidityChanged: function(am, account, valid) {
|
|
|
|
if (!valid)
|
|
|
|
return;
|
|
|
|
|
2011-08-27 20:26:25 -04:00
|
|
|
// It would be better to connect to "status-changed" but we cannot.
|
|
|
|
// See discussion in https://bugzilla.gnome.org/show_bug.cgi?id=654159
|
|
|
|
account.connect("notify::connection-status",
|
|
|
|
Lang.bind(this, this._accountConnectionStatusNotifyCb));
|
|
|
|
|
2011-08-26 06:27:40 -04:00
|
|
|
account.connect('notify::connection',
|
|
|
|
Lang.bind(this, this._connectionChanged));
|
|
|
|
this._connectionChanged(account);
|
|
|
|
},
|
|
|
|
|
|
|
|
_connectionChanged: function(account) {
|
|
|
|
let conn = account.get_connection();
|
|
|
|
if (conn == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._tpClient.grab_contact_list_changed(conn);
|
|
|
|
if (conn.get_contact_list_state() == Tp.ContactListState.SUCCESS) {
|
|
|
|
this._contactListChanged(conn, conn.dup_contact_list(), []);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_contactListChanged: function(conn, added, removed) {
|
|
|
|
for (let i = 0; i < added.length; i++) {
|
|
|
|
let contact = added[i];
|
|
|
|
|
|
|
|
contact.connect('subscription-states-changed',
|
|
|
|
Lang.bind(this, this._subscriptionStateChanged));
|
|
|
|
this._subscriptionStateChanged(contact);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_subscriptionStateChanged: function(contact) {
|
|
|
|
if (contact.get_publish_state() != Tp.SubscriptionState.ASK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Implicitly accept publish requests if contact is already subscribed */
|
|
|
|
if (contact.get_subscribe_state() == Tp.SubscriptionState.YES ||
|
|
|
|
contact.get_subscribe_state() == Tp.SubscriptionState.ASK) {
|
|
|
|
|
|
|
|
contact.authorize_publication_async(function(src, result) {
|
|
|
|
src.authorize_publication_finish(result)});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Display notification to ask user to accept/reject request */
|
|
|
|
let source = this._ensureSubscriptionSource();
|
|
|
|
|
|
|
|
let notif = new SubscriptionRequestNotification(source, contact);
|
|
|
|
source.notify(notif);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ensureSubscriptionSource: function() {
|
|
|
|
if (this._subscriptionSource == null) {
|
2011-10-08 18:00:32 -04:00
|
|
|
this._subscriptionSource = new MessageTray.Source(_("Subscription request"),
|
|
|
|
'gtk-dialog-question',
|
|
|
|
St.IconType.FULLCOLOR);
|
2011-09-14 11:01:48 -04:00
|
|
|
Main.messageTray.add(this._subscriptionSource);
|
2011-08-26 06:27:40 -04:00
|
|
|
this._subscriptionSource.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._subscriptionSource = null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._subscriptionSource;
|
2011-08-27 20:26:25 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_accountConnectionStatusNotifyCb: function(account) {
|
|
|
|
let connectionError = account.connection_error;
|
|
|
|
|
|
|
|
if (account.connection_status != Tp.ConnectionStatus.DISCONNECTED ||
|
|
|
|
connectionError == Tp.error_get_dbus_name(Tp.Error.CANCELLED)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-14 11:01:48 -04:00
|
|
|
let notif = this._accountNotifications[account.get_object_path()];
|
|
|
|
if (notif)
|
|
|
|
return;
|
|
|
|
|
2011-08-27 20:26:25 -04:00
|
|
|
/* Display notification that account failed to connect */
|
|
|
|
let source = this._ensureAccountSource();
|
|
|
|
|
2011-09-14 11:01:48 -04:00
|
|
|
notif = new AccountNotification(source, account, connectionError);
|
|
|
|
this._accountNotifications[account.get_object_path()] = notif;
|
|
|
|
notif.connect('destroy', Lang.bind(this, function() {
|
|
|
|
delete this._accountNotifications[account.get_object_path()];
|
|
|
|
}));
|
2011-08-27 20:26:25 -04:00
|
|
|
source.notify(notif);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ensureAccountSource: function() {
|
|
|
|
if (this._accountSource == null) {
|
2011-10-08 18:00:32 -04:00
|
|
|
this._accountSource = new MessageTray.Source(_("Connection error"),
|
|
|
|
'gtk-dialog-error',
|
|
|
|
St.IconType.FULLCOLOR);
|
2011-09-14 11:01:48 -04:00
|
|
|
Main.messageTray.add(this._accountSource);
|
2011-08-27 20:26:25 -04:00
|
|
|
this._accountSource.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._accountSource = null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._accountSource;
|
2010-02-02 10:21:47 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const ChatSource = new Lang.Class({
|
|
|
|
Name: 'ChatSource',
|
|
|
|
Extends: MessageTray.Source,
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-04-05 07:28:11 -04:00
|
|
|
_init: function(account, conn, channel, contact, client) {
|
2011-02-08 05:22:46 -05:00
|
|
|
this._account = account;
|
2011-02-08 07:17:29 -05:00
|
|
|
this._contact = contact;
|
2011-04-05 07:28:11 -04:00
|
|
|
this._client = client;
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-10-08 18:00:32 -04:00
|
|
|
this.parent(contact.get_alias());
|
|
|
|
|
2012-05-25 05:15:57 -04:00
|
|
|
this.isChat = true;
|
2011-05-27 05:39:50 -04:00
|
|
|
this._pendingMessages = [];
|
|
|
|
|
2011-02-08 05:22:46 -05:00
|
|
|
this._conn = conn;
|
|
|
|
this._channel = channel;
|
|
|
|
this._closedId = this._channel.connect('invalidated', Lang.bind(this, this._channelClosed));
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-06-30 05:53:44 -04:00
|
|
|
this._notification = new ChatNotification(this);
|
2011-01-04 04:34:57 -05:00
|
|
|
this._notification.setUrgency(MessageTray.Urgency.HIGH);
|
2011-08-22 10:23:50 -04:00
|
|
|
this._notifyTimeoutId = 0;
|
2010-11-28 10:14:34 -05:00
|
|
|
|
2011-12-08 18:35:19 -05:00
|
|
|
// We ack messages when the user expands the new notification or views the summary
|
|
|
|
// notification, in which case the notification is also expanded.
|
|
|
|
this._notification.connect('expanded', Lang.bind(this, this._ackMessages));
|
2011-05-27 05:39:50 -04:00
|
|
|
|
2011-02-08 08:50:06 -05:00
|
|
|
this._presence = contact.get_presence_type();
|
2010-04-16 17:24:34 -04:00
|
|
|
|
2011-02-08 10:19:01 -05:00
|
|
|
this._sentId = this._channel.connect('message-sent', Lang.bind(this, this._messageSent));
|
|
|
|
this._receivedId = this._channel.connect('message-received', Lang.bind(this, this._messageReceived));
|
2011-05-27 05:39:50 -04:00
|
|
|
this._pendingId = this._channel.connect('pending-message-removed', Lang.bind(this, this._pendingRemoved));
|
2010-08-05 13:09:27 -04:00
|
|
|
|
2011-02-08 07:17:29 -05:00
|
|
|
this._notifyAliasId = this._contact.connect('notify::alias', Lang.bind(this, this._updateAlias));
|
2011-02-08 08:05:20 -05:00
|
|
|
this._notifyAvatarId = this._contact.connect('notify::avatar-file', Lang.bind(this, this._updateAvatarIcon));
|
2011-02-08 08:50:06 -05:00
|
|
|
this._presenceChangedId = this._contact.connect('presence-changed', Lang.bind(this, this._presenceChanged));
|
2011-02-08 10:19:01 -05:00
|
|
|
|
2011-02-28 13:14:07 -05:00
|
|
|
// Add ourselves as a source.
|
|
|
|
Main.messageTray.add(this);
|
|
|
|
this.pushNotification(this._notification);
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
this._getLogMessages();
|
2011-02-08 07:17:29 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateAlias: function() {
|
2011-02-28 13:15:02 -05:00
|
|
|
let oldAlias = this.title;
|
2011-10-03 14:48:49 -04:00
|
|
|
let newAlias = this._contact.get_alias();
|
|
|
|
|
|
|
|
if (oldAlias == newAlias)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.setTitle(newAlias);
|
|
|
|
this._notification.appendAliasChange(oldAlias, newAlias);
|
2010-02-02 10:21:47 -05:00
|
|
|
},
|
|
|
|
|
2012-07-19 09:05:17 -04:00
|
|
|
createIcon: function(size) {
|
2011-02-08 08:05:20 -05:00
|
|
|
this._iconBox = new St.Bin({ style_class: 'avatar-box' });
|
2012-07-19 09:05:17 -04:00
|
|
|
this._iconBox._size = size;
|
2011-02-08 08:05:20 -05:00
|
|
|
let textureCache = St.TextureCache.get_default();
|
|
|
|
let file = this._contact.get_avatar_file();
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
let uri = file.get_uri();
|
|
|
|
this._iconBox.child = textureCache.load_uri_async(uri, this._iconBox._size, this._iconBox._size);
|
|
|
|
} else {
|
2011-02-16 19:51:49 -05:00
|
|
|
this._iconBox.child = new St.Icon({ icon_name: 'avatar-default',
|
2011-02-08 08:05:20 -05:00
|
|
|
icon_type: St.IconType.FULLCOLOR,
|
|
|
|
icon_size: this._iconBox._size });
|
|
|
|
}
|
2011-09-21 16:46:08 -04:00
|
|
|
|
|
|
|
return this._iconBox;
|
|
|
|
},
|
|
|
|
|
2012-07-05 13:47:13 -04:00
|
|
|
createSecondaryIcon: function() {
|
|
|
|
let iconBox = new St.Bin();
|
|
|
|
iconBox.child = new St.Icon({ style_class: 'secondary-icon',
|
|
|
|
icon_type: St.IconType.FULLCOLOR });
|
|
|
|
let presenceType = this._contact.get_presence_type();
|
|
|
|
|
|
|
|
switch (presenceType) {
|
|
|
|
case Tp.ConnectionPresenceType.AVAILABLE:
|
|
|
|
iconBox.child.icon_name = 'user-available';
|
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.BUSY:
|
|
|
|
iconBox.child.icon_name = 'user-busy';
|
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.OFFLINE:
|
|
|
|
iconBox.child.icon_name = 'user-offline';
|
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.HIDDEN:
|
|
|
|
iconBox.child.icon_name = 'user-invisible';
|
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.AWAY:
|
|
|
|
iconBox.child.icon_name = 'user-away';
|
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.EXTENDED_AWAY:
|
|
|
|
iconBox.child.icon_name = 'user-idle';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iconBox.child.icon_name = 'user-offline';
|
|
|
|
}
|
|
|
|
return iconBox;
|
|
|
|
},
|
|
|
|
|
2011-09-21 16:46:08 -04:00
|
|
|
_updateAvatarIcon: function() {
|
2012-07-19 09:05:17 -04:00
|
|
|
this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
|
|
|
|
this._notification.update(this._notification.title, null, { customContent: true });
|
2010-02-02 10:21:47 -05:00
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
open: function(notification) {
|
2011-04-05 07:28:11 -04:00
|
|
|
if (this._client.is_handling_channel(this._channel)) {
|
|
|
|
// We are handling the channel, try to pass it to Empathy
|
2011-09-30 17:30:47 -04:00
|
|
|
this._client.delegate_channels_async([this._channel], global.get_current_time(), '', null);
|
2011-04-05 07:28:11 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We are not the handler, just ask to present the channel
|
|
|
|
let dbus = Tp.DBusDaemon.dup();
|
|
|
|
let cd = Tp.ChannelDispatcher.new(dbus);
|
|
|
|
|
|
|
|
cd.present_channel_async(this._channel, global.get_current_time(), null);
|
|
|
|
}
|
2010-04-08 10:55:22 -04:00
|
|
|
},
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
_getLogMessages: function() {
|
|
|
|
let logManager = Tpl.LogManager.dup_singleton();
|
|
|
|
let entity = Tpl.Entity.new_from_tp_contact(this._contact, Tpl.EntityType.CONTACT);
|
2012-05-25 14:55:20 -04:00
|
|
|
|
|
|
|
logManager.get_filtered_events_async(this._account, entity,
|
|
|
|
Tpl.EventTypeMask.TEXT, SCROLLBACK_HISTORY_LINES,
|
|
|
|
null, Lang.bind(this, this._displayPendingMessages));
|
2011-03-07 17:10:53 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_displayPendingMessages: function(logManager, result) {
|
|
|
|
let [success, events] = logManager.get_filtered_events_finish(result);
|
|
|
|
|
|
|
|
let logMessages = events.map(makeMessageFromTplEvent);
|
|
|
|
|
2011-03-23 15:25:42 -04:00
|
|
|
let pendingTpMessages = this._channel.get_pending_messages();
|
2011-05-27 04:52:08 -04:00
|
|
|
let pendingMessages = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < pendingTpMessages.length; i++) {
|
|
|
|
let message = pendingTpMessages[i];
|
|
|
|
|
|
|
|
if (message.get_message_type() == Tp.ChannelTextMessageType.DELIVERY_REPORT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pendingMessages.push(makeMessageFromTpMessage(message, NotificationDirection.RECEIVED));
|
2011-05-27 05:39:50 -04:00
|
|
|
|
|
|
|
this._pendingMessages.push(message);
|
2011-05-27 04:52:08 -04:00
|
|
|
}
|
2011-03-23 15:25:42 -04:00
|
|
|
|
2012-08-06 11:28:55 -04:00
|
|
|
this.countUpdated();
|
2011-06-27 08:31:53 -04:00
|
|
|
|
2011-03-24 07:09:04 -04:00
|
|
|
let showTimestamp = false;
|
|
|
|
|
2011-03-23 15:25:42 -04:00
|
|
|
for (let i = 0; i < logMessages.length; i++) {
|
|
|
|
let logMessage = logMessages[i];
|
|
|
|
let isPending = false;
|
|
|
|
|
|
|
|
// Skip any log messages that are also in pendingMessages
|
|
|
|
for (let j = 0; j < pendingMessages.length; j++) {
|
|
|
|
let pending = pendingMessages[j];
|
|
|
|
if (logMessage.timestamp == pending.timestamp && logMessage.text == pending.text) {
|
|
|
|
isPending = true;
|
|
|
|
break;
|
2011-03-07 17:10:53 -05:00
|
|
|
}
|
|
|
|
}
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-03-24 07:09:04 -04:00
|
|
|
if (!isPending) {
|
|
|
|
showTimestamp = true;
|
2011-03-24 07:11:17 -04:00
|
|
|
this._notification.appendMessage(logMessage, true, ['chat-log-message']);
|
2011-03-24 07:09:04 -04:00
|
|
|
}
|
2011-02-08 10:19:01 -05:00
|
|
|
}
|
2011-03-07 17:10:53 -05:00
|
|
|
|
2011-03-24 07:09:04 -04:00
|
|
|
if (showTimestamp)
|
|
|
|
this._notification.appendTimestamp();
|
|
|
|
|
2011-03-23 15:25:42 -04:00
|
|
|
for (let i = 0; i < pendingMessages.length; i++)
|
|
|
|
this._notification.appendMessage(pendingMessages[i], true);
|
|
|
|
|
|
|
|
if (pendingMessages.length > 0)
|
2011-03-07 17:10:53 -05:00
|
|
|
this.notify();
|
2010-02-02 10:21:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_channelClosed: function() {
|
|
|
|
this._channel.disconnect(this._closedId);
|
2011-02-08 10:19:01 -05:00
|
|
|
this._channel.disconnect(this._receivedId);
|
2011-05-27 05:39:50 -04:00
|
|
|
this._channel.disconnect(this._pendingId);
|
2011-02-08 10:19:01 -05:00
|
|
|
this._channel.disconnect(this._sentId);
|
2011-02-08 07:17:29 -05:00
|
|
|
|
|
|
|
this._contact.disconnect(this._notifyAliasId);
|
2011-02-08 08:05:20 -05:00
|
|
|
this._contact.disconnect(this._notifyAvatarId);
|
2011-02-08 08:50:06 -05:00
|
|
|
this._contact.disconnect(this._presenceChangedId);
|
2011-02-08 10:19:01 -05:00
|
|
|
|
2010-02-02 10:21:47 -05:00
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2012-08-06 11:28:55 -04:00
|
|
|
/* All messages are new messages for Telepathy sources */
|
|
|
|
get count() {
|
|
|
|
return this._pendingMessages.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
get unseenCount() {
|
|
|
|
return this.count;
|
|
|
|
},
|
|
|
|
|
|
|
|
get countVisible() {
|
|
|
|
return this.count > 0;
|
2011-06-27 08:31:53 -04:00
|
|
|
},
|
|
|
|
|
2011-02-08 10:19:01 -05:00
|
|
|
_messageReceived: function(channel, message) {
|
2011-05-05 08:19:59 -04:00
|
|
|
if (message.get_message_type() == Tp.ChannelTextMessageType.DELIVERY_REPORT)
|
|
|
|
return;
|
|
|
|
|
2011-05-27 05:39:50 -04:00
|
|
|
this._pendingMessages.push(message);
|
2012-08-06 11:28:55 -04:00
|
|
|
this.countUpdated();
|
2011-05-27 05:39:50 -04:00
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
message = makeMessageFromTpMessage(message, NotificationDirection.RECEIVED);
|
|
|
|
this._notification.appendMessage(message);
|
2011-08-22 10:23:50 -04:00
|
|
|
|
|
|
|
// Wait a bit before notifying for the received message, a handler
|
|
|
|
// could ack it in the meantime.
|
|
|
|
if (this._notifyTimeoutId != 0)
|
|
|
|
Mainloop.source_remove(this._notifyTimeoutId);
|
|
|
|
this._notifyTimeoutId = Mainloop.timeout_add(500,
|
|
|
|
Lang.bind(this, this._notifyTimeout));
|
|
|
|
},
|
|
|
|
|
|
|
|
_notifyTimeout: function() {
|
|
|
|
if (this._pendingMessages.length != 0)
|
|
|
|
this.notify();
|
|
|
|
|
|
|
|
this._notifyTimeoutId = 0;
|
|
|
|
|
|
|
|
return false;
|
2010-11-28 10:14:34 -05:00
|
|
|
},
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2010-11-28 10:14:34 -05:00
|
|
|
// This is called for both messages we send from
|
|
|
|
// our client and other clients as well.
|
2011-02-08 10:19:01 -05:00
|
|
|
_messageSent: function(channel, message, flags, token) {
|
2011-03-07 17:10:53 -05:00
|
|
|
message = makeMessageFromTpMessage(message, NotificationDirection.SENT);
|
|
|
|
this._notification.appendMessage(message);
|
2010-04-16 17:24:34 -04:00
|
|
|
},
|
|
|
|
|
2010-11-28 10:14:34 -05:00
|
|
|
notify: function() {
|
2011-11-20 12:56:27 -05:00
|
|
|
this.parent(this._notification);
|
2010-02-22 14:23:36 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
respond: function(text) {
|
2011-02-26 09:38:25 -05:00
|
|
|
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);
|
2011-06-28 11:42:41 -04:00
|
|
|
this._channel.send_message_async(msg, 0, Lang.bind(this, function (src, result) {
|
|
|
|
this._channel.send_message_finish(result);
|
|
|
|
}));
|
2010-04-16 17:24:34 -04:00
|
|
|
},
|
|
|
|
|
2011-07-07 08:42:07 -04:00
|
|
|
setChatState: function(state) {
|
|
|
|
// We don't want to send COMPOSING every time a letter is typed into
|
|
|
|
// the entry. We send the state only when it changes. Telepathy/Empathy
|
|
|
|
// might change it behind our back if the user is using both
|
|
|
|
// gnome-shell's entry and the Empathy conversation window. We could
|
|
|
|
// keep track of it with the ChatStateChanged signal but it is good
|
|
|
|
// enough right now.
|
|
|
|
if (state != this._chatState) {
|
|
|
|
this._chatState = state;
|
|
|
|
this._channel.set_chat_state_async(state, null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-06-03 16:07:29 -04:00
|
|
|
_presenceChanged: function (contact, presence, status, message) {
|
2012-07-05 13:47:13 -04:00
|
|
|
let msg, title;
|
2011-02-08 08:50:06 -05:00
|
|
|
|
2011-02-13 23:13:07 -05:00
|
|
|
title = GLib.markup_escape_text(this.title, -1);
|
2010-04-16 17:24:34 -04:00
|
|
|
|
2012-07-05 13:47:13 -04:00
|
|
|
this._notification.update(this._notification.title, null, { customContent: true, secondaryIcon: this.createSecondaryIcon() });
|
2010-04-16 17:24:34 -04:00
|
|
|
|
|
|
|
if (message)
|
|
|
|
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
|
2011-05-27 05:39:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_pendingRemoved: function(channel, message) {
|
|
|
|
let idx = this._pendingMessages.indexOf(message);
|
|
|
|
|
2011-06-27 08:31:53 -04:00
|
|
|
if (idx >= 0) {
|
2011-05-27 05:39:50 -04:00
|
|
|
this._pendingMessages.splice(idx, 1);
|
2012-08-06 11:28:55 -04:00
|
|
|
this.countUpdated();
|
2011-06-27 08:31:53 -04:00
|
|
|
}
|
2011-05-27 05:39:50 -04:00
|
|
|
else
|
|
|
|
throw new Error('Message not in our pending list: ' + message);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ackMessages: function() {
|
|
|
|
// Don't clear our messages here, tp-glib will send a
|
|
|
|
// 'pending-message-removed' for each one.
|
2011-07-11 10:14:36 -04:00
|
|
|
this._channel.ack_all_pending_messages_async(Lang.bind(this, function(src, result) {
|
|
|
|
this._channel.ack_all_pending_messages_finish(result);}));
|
2010-02-02 10:21:47 -05:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const ChatNotification = new Lang.Class({
|
|
|
|
Name: 'ChatNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2010-08-11 09:43:40 -04:00
|
|
|
_init: function(source) {
|
2012-07-05 13:47:13 -04:00
|
|
|
this.parent(source, source.title, null, { customContent: true, secondaryIcon: source.createSecondaryIcon() });
|
2010-12-22 02:41:11 -05:00
|
|
|
this.setResident(true);
|
2010-02-22 14:23:36 -05:00
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
this._responseEntry = new St.Entry({ style_class: 'chat-response',
|
|
|
|
can_focus: true });
|
2010-02-22 14:23:36 -05:00
|
|
|
this._responseEntry.clutter_text.connect('activate', Lang.bind(this, this._onEntryActivated));
|
2011-07-07 08:42:07 -04:00
|
|
|
this._responseEntry.clutter_text.connect('text-changed', Lang.bind(this, this._onEntryChanged));
|
2010-02-22 14:23:36 -05:00
|
|
|
this.setActionArea(this._responseEntry);
|
|
|
|
|
2011-03-09 07:56:35 -05:00
|
|
|
this._oldMaxScrollAdjustment = 0;
|
|
|
|
this._createScrollArea();
|
2011-08-24 10:33:44 -04:00
|
|
|
this._lastGroup = null;
|
|
|
|
this._lastGroupActor = null;
|
2011-03-09 07:56:35 -05:00
|
|
|
|
|
|
|
this._scrollArea.vscroll.adjustment.connect('changed', Lang.bind(this, function(adjustment) {
|
|
|
|
let currentValue = adjustment.value + adjustment.page_size;
|
|
|
|
if (currentValue == this._oldMaxScrollAdjustment)
|
|
|
|
this.scrollTo(St.Side.BOTTOM);
|
|
|
|
this._oldMaxScrollAdjustment = adjustment.upper;
|
|
|
|
}));
|
|
|
|
|
2011-02-20 03:41:51 -05:00
|
|
|
this._inputHistory = new History.HistoryManager({ entry: this._responseEntry.clutter_text });
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
this._history = [];
|
2010-11-25 09:29:41 -05:00
|
|
|
this._timestampTimeoutId = 0;
|
2011-07-07 08:42:07 -04:00
|
|
|
this._composingTimeoutId = 0;
|
2010-02-22 14:23:36 -05:00
|
|
|
},
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
/**
|
|
|
|
* appendMessage:
|
|
|
|
* @message: An object with the properties:
|
|
|
|
* text: the body of the message,
|
|
|
|
* messageType: a #Tp.ChannelTextMessageType,
|
|
|
|
* sender: the name of the sender,
|
|
|
|
* timestamp: the time the message was sent
|
|
|
|
* direction: a #NotificationDirection
|
|
|
|
*
|
|
|
|
* @noTimestamp: Whether to add a timestamp. If %true, no timestamp
|
|
|
|
* will be added, regardless of the difference since the
|
|
|
|
* last timestamp
|
|
|
|
*/
|
2011-08-24 10:33:44 -04:00
|
|
|
appendMessage: function(message, noTimestamp) {
|
2011-03-07 17:10:53 -05:00
|
|
|
let messageBody = GLib.markup_escape_text(message.text, -1);
|
2011-08-24 10:33:44 -04:00
|
|
|
let styles = [message.direction];
|
2011-03-07 17:10:53 -05:00
|
|
|
|
|
|
|
if (message.messageType == Tp.ChannelTextMessageType.ACTION) {
|
|
|
|
let senderAlias = GLib.markup_escape_text(message.sender, -1);
|
2011-02-26 09:38:25 -05:00
|
|
|
messageBody = '<i>%s</i> %s'.format(senderAlias, messageBody);
|
|
|
|
styles.push('chat-action');
|
|
|
|
}
|
|
|
|
|
2011-05-15 05:07:23 -04:00
|
|
|
if (message.direction == NotificationDirection.RECEIVED) {
|
|
|
|
this.update(this.source.title, messageBody, { customContent: true,
|
|
|
|
bannerMarkup: true });
|
|
|
|
}
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let group = (message.direction == NotificationDirection.RECEIVED ?
|
|
|
|
'received' : 'sent');
|
|
|
|
|
|
|
|
this._append({ body: messageBody,
|
|
|
|
group: group,
|
|
|
|
styles: styles,
|
|
|
|
timestamp: message.timestamp,
|
|
|
|
noTimestamp: noTimestamp });
|
2010-02-22 14:23:36 -05:00
|
|
|
},
|
|
|
|
|
2011-05-25 13:18:56 -04:00
|
|
|
_filterMessages: function() {
|
|
|
|
if (this._history.length < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let lastMessageTime = this._history[0].time;
|
|
|
|
let currentTime = (Date.now() / 1000);
|
|
|
|
|
|
|
|
// Keep the scrollback from growing too long. If the most
|
|
|
|
// recent message (before the one we just added) is within
|
|
|
|
// SCROLLBACK_RECENT_TIME, we will keep
|
|
|
|
// SCROLLBACK_RECENT_LENGTH previous messages. Otherwise
|
|
|
|
// we'll keep SCROLLBACK_IDLE_LENGTH messages.
|
|
|
|
|
|
|
|
let maxLength = (lastMessageTime < currentTime - SCROLLBACK_RECENT_TIME) ?
|
|
|
|
SCROLLBACK_IDLE_LENGTH : SCROLLBACK_RECENT_LENGTH;
|
|
|
|
|
|
|
|
let filteredHistory = this._history.filter(function(item) { return item.realMessage });
|
|
|
|
if (filteredHistory.length > maxLength) {
|
|
|
|
let lastMessageToKeep = filteredHistory[maxLength];
|
|
|
|
let expired = this._history.splice(this._history.indexOf(lastMessageToKeep));
|
|
|
|
for (let i = 0; i < expired.length; i++)
|
|
|
|
expired[i].actor.destroy();
|
|
|
|
}
|
2011-08-24 10:33:44 -04:00
|
|
|
|
|
|
|
let groups = this._contentArea.get_children();
|
2011-10-20 16:40:22 -04:00
|
|
|
for (let i = 0; i < groups.length; i++) {
|
2011-08-24 10:33:44 -04:00
|
|
|
let group = groups[i];
|
2012-05-29 20:36:45 -04:00
|
|
|
if (group.get_n_children() == 0)
|
2011-08-24 10:33:44 -04:00
|
|
|
group.destroy();
|
|
|
|
}
|
2011-05-25 13:18:56 -04:00
|
|
|
},
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
/**
|
|
|
|
* _append:
|
|
|
|
* @props: An object with the properties:
|
|
|
|
* body: The text of the message.
|
|
|
|
* group: The group of the message, one of:
|
|
|
|
* 'received', 'sent', 'meta'.
|
|
|
|
* styles: Style class names for the message to have.
|
|
|
|
* timestamp: The timestamp of the message.
|
|
|
|
* noTimestamp: suppress timestamp signal?
|
|
|
|
* childProps: props to add the actor with.
|
|
|
|
*/
|
|
|
|
_append: function(props) {
|
2010-11-25 09:29:41 -05:00
|
|
|
let currentTime = (Date.now() / 1000);
|
2011-08-24 10:33:44 -04:00
|
|
|
props = Params.parse(props, { body: null,
|
|
|
|
group: null,
|
|
|
|
styles: [],
|
|
|
|
timestamp: currentTime,
|
|
|
|
noTimestamp: false,
|
|
|
|
childProps: null });
|
2010-11-25 09:29:41 -05:00
|
|
|
|
|
|
|
// Reset the old message timeout
|
|
|
|
if (this._timestampTimeoutId)
|
|
|
|
Mainloop.source_remove(this._timestampTimeoutId);
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let highlighter = new MessageTray.URLHighlighter(props.body,
|
|
|
|
true, // line wrap?
|
|
|
|
true); // allow markup?
|
|
|
|
|
|
|
|
let body = highlighter.actor;
|
|
|
|
|
|
|
|
let styles = props.styles;
|
2011-10-20 16:40:22 -04:00
|
|
|
for (let i = 0; i < styles.length; i++)
|
2011-02-26 09:38:25 -05:00
|
|
|
body.add_style_class_name(styles[i]);
|
2010-02-22 14:23:36 -05:00
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let group = props.group;
|
|
|
|
if (group != this._lastGroup) {
|
|
|
|
let style = 'chat-group-' + group;
|
|
|
|
this._lastGroup = group;
|
|
|
|
this._lastGroupActor = new St.BoxLayout({ style_class: style,
|
|
|
|
vertical: true });
|
|
|
|
this.addActor(this._lastGroupActor);
|
|
|
|
}
|
2010-11-25 09:29:41 -05:00
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
this._lastGroupActor.add(body, props.childProps);
|
|
|
|
|
2012-04-13 13:05:51 -04:00
|
|
|
this.updated();
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let timestamp = props.timestamp;
|
|
|
|
this._history.unshift({ actor: body, time: timestamp,
|
|
|
|
realMessage: group != 'meta' });
|
|
|
|
|
|
|
|
if (!props.noTimestamp) {
|
2011-03-07 17:10:53 -05:00
|
|
|
if (timestamp < currentTime - SCROLLBACK_IMMEDIATE_TIME)
|
|
|
|
this.appendTimestamp();
|
|
|
|
else
|
|
|
|
// Schedule a new timestamp in SCROLLBACK_IMMEDIATE_TIME
|
|
|
|
// from the timestamp of the message.
|
|
|
|
this._timestampTimeoutId = Mainloop.timeout_add_seconds(
|
|
|
|
SCROLLBACK_IMMEDIATE_TIME - (currentTime - timestamp),
|
|
|
|
Lang.bind(this, this.appendTimestamp));
|
|
|
|
}
|
2010-02-22 14:23:36 -05:00
|
|
|
|
2011-05-25 13:18:56 -04:00
|
|
|
this._filterMessages();
|
2010-02-22 14:23:36 -05:00
|
|
|
},
|
|
|
|
|
2011-03-28 16:37:53 -04:00
|
|
|
_formatTimestamp: function(date) {
|
|
|
|
let now = new Date();
|
|
|
|
|
|
|
|
var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
|
|
|
|
|
2011-03-30 05:44:53 -04:00
|
|
|
let format;
|
|
|
|
|
2011-03-28 16:37:53 -04:00
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
if (daysAgo < 1 || (daysAgo < 7 && now.getDay() != date.getDay())) {
|
|
|
|
/* Translators: this is a time format string followed by a date.
|
|
|
|
If applicable, replace %X with a strftime format valid for your
|
|
|
|
locale, without seconds. */
|
|
|
|
// xgettext:no-c-format
|
2011-08-01 18:25:59 -04:00
|
|
|
format = _("Sent at <b>%X</b> on <b>%A</b>");
|
2011-03-28 16:37:53 -04:00
|
|
|
|
|
|
|
} else if (date.getYear() == now.getYear()) {
|
2011-08-01 18:25:59 -04:00
|
|
|
/* Translators: this is a time format in the style of "Wednesday, May 25",
|
|
|
|
shown when you get a chat message in the same year. */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("Sent on <b>%A</b>, <b>%B %d</b>");
|
2011-03-28 16:37:53 -04:00
|
|
|
} else {
|
2011-08-01 18:25:59 -04:00
|
|
|
/* Translators: this is a time format in the style of "Wednesday, May 25, 2012",
|
|
|
|
shown when you get a chat message in a different year. */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("Sent on <b>%A</b>, <b>%B %d</b>, %Y");
|
2011-03-28 16:37:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return date.toLocaleFormat(format);
|
|
|
|
},
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
appendTimestamp: function() {
|
2010-11-25 09:29:41 -05:00
|
|
|
let lastMessageTime = this._history[0].time;
|
|
|
|
let lastMessageDate = new Date(lastMessageTime * 1000);
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let timeLabel = this._append({ body: this._formatTimestamp(lastMessageDate),
|
|
|
|
group: 'meta',
|
|
|
|
styles: ['chat-meta-message'],
|
|
|
|
childProps: { expand: true, x_fill: false,
|
|
|
|
x_align: St.Align.END },
|
|
|
|
noTimestamp: true,
|
|
|
|
timestamp: lastMessageTime });
|
2011-05-25 13:18:56 -04:00
|
|
|
|
|
|
|
this._filterMessages();
|
|
|
|
|
2010-11-25 09:29:41 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-28 13:15:02 -05:00
|
|
|
appendAliasChange: function(oldAlias, newAlias) {
|
2011-03-15 09:45:53 -04:00
|
|
|
oldAlias = GLib.markup_escape_text(oldAlias, -1);
|
|
|
|
newAlias = GLib.markup_escape_text(newAlias, -1);
|
|
|
|
|
|
|
|
/* Translators: this is the other person changing their old IM name to their new
|
|
|
|
IM name. */
|
|
|
|
let message = '<i>' + _("%s is now known as %s").format(oldAlias, newAlias) + '</i>';
|
2011-08-24 10:33:44 -04:00
|
|
|
|
2011-09-08 21:37:25 -04:00
|
|
|
let label = this._append({ body: message,
|
2011-08-24 10:33:44 -04:00
|
|
|
group: 'meta',
|
|
|
|
styles: ['chat-meta-message'] });
|
|
|
|
|
2011-03-15 09:45:53 -04:00
|
|
|
this.update(newAlias, null, { customContent: true });
|
2011-05-25 13:18:56 -04:00
|
|
|
|
|
|
|
this._filterMessages();
|
2011-02-28 13:15:02 -05:00
|
|
|
},
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
_onEntryActivated: function() {
|
|
|
|
let text = this._responseEntry.get_text();
|
2010-07-21 00:42:37 -04:00
|
|
|
if (text == '')
|
2010-02-22 14:23:36 -05:00
|
|
|
return;
|
|
|
|
|
2011-02-20 03:41:51 -05:00
|
|
|
this._inputHistory.addItem(text);
|
|
|
|
|
2010-11-28 10:14:34 -05:00
|
|
|
// Telepathy sends out the Sent signal for us.
|
|
|
|
// see Source._messageSent
|
2010-02-22 14:23:36 -05:00
|
|
|
this._responseEntry.set_text('');
|
|
|
|
this.source.respond(text);
|
2011-07-07 08:42:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_composingStopTimeout: function() {
|
|
|
|
this._composingTimeoutId = 0;
|
|
|
|
|
|
|
|
this.source.setChatState(Tp.ChannelChatState.PAUSED);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onEntryChanged: function() {
|
|
|
|
let text = this._responseEntry.get_text();
|
|
|
|
|
|
|
|
// If we're typing, we want to send COMPOSING.
|
|
|
|
// If we empty the entry, we want to send ACTIVE.
|
|
|
|
// If we've stopped typing for COMPOSING_STOP_TIMEOUT
|
|
|
|
// seconds, we want to send PAUSED.
|
|
|
|
|
|
|
|
// Remove composing timeout.
|
|
|
|
if (this._composingTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._composingTimeoutId);
|
|
|
|
this._composingTimeoutId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text != '') {
|
|
|
|
this.source.setChatState(Tp.ChannelChatState.COMPOSING);
|
|
|
|
|
|
|
|
this._composingTimeoutId = Mainloop.timeout_add_seconds(
|
|
|
|
COMPOSING_STOP_TIMEOUT,
|
|
|
|
Lang.bind(this, this._composingStopTimeout));
|
|
|
|
} else {
|
|
|
|
this.source.setChatState(Tp.ChannelChatState.ACTIVE);
|
|
|
|
}
|
2010-02-02 10:21:47 -05:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-06-30 08:05:41 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const ApproverSource = new Lang.Class({
|
|
|
|
Name: 'ApproverSource',
|
|
|
|
Extends: MessageTray.Source,
|
2011-06-30 08:05:41 -04:00
|
|
|
|
2011-08-16 10:59:34 -04:00
|
|
|
_init: function(dispatchOp, text, gicon) {
|
|
|
|
this._gicon = gicon;
|
2011-10-08 18:00:32 -04:00
|
|
|
|
|
|
|
this.parent(text);
|
2011-06-30 08:05:41 -04:00
|
|
|
|
|
|
|
this._dispatchOp = dispatchOp;
|
|
|
|
|
|
|
|
// Destroy the source if the channel dispatch operation is invalidated
|
|
|
|
// as we can't approve any more.
|
|
|
|
this._invalidId = dispatchOp.connect('invalidated',
|
|
|
|
Lang.bind(this, function(domain, code, msg) {
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if (this._invalidId != 0) {
|
|
|
|
this._dispatchOp.disconnect(this._invalidId);
|
|
|
|
this._invalidId = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
this.parent();
|
2011-06-30 08:05:41 -04:00
|
|
|
},
|
|
|
|
|
2012-07-19 09:05:17 -04:00
|
|
|
createIcon: function(size) {
|
2011-08-16 10:59:34 -04:00
|
|
|
return new St.Icon({ gicon: this._gicon,
|
2012-07-19 09:05:17 -04:00
|
|
|
icon_size: size });
|
2011-06-30 08:05:41 -04:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-06-30 08:05:41 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const RoomInviteNotification = new Lang.Class({
|
|
|
|
Name: 'RoomInviteNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-06-30 08:05:41 -04:00
|
|
|
|
|
|
|
_init: function(source, dispatchOp, channel, inviter) {
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent(source,
|
|
|
|
/* translators: argument is a room name like
|
|
|
|
* room@jabber.org for example. */
|
|
|
|
_("Invitation to %s").format(channel.get_identifier()),
|
|
|
|
null,
|
|
|
|
{ customContent: true });
|
2011-06-30 08:05:41 -04:00
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
/* translators: first argument is the name of a contact and the second
|
|
|
|
* one the name of a room. "Alice is inviting you to join room@jabber.org
|
|
|
|
* for example. */
|
|
|
|
this.addBody(_("%s is inviting you to join %s").format(inviter.get_alias(), channel.get_identifier()));
|
|
|
|
|
|
|
|
this.addButton('decline', _("Decline"));
|
|
|
|
this.addButton('accept', _("Accept"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'decline':
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE,
|
|
|
|
'', function(src, result) {
|
|
|
|
src.leave_channels_finish(result)});
|
|
|
|
break;
|
|
|
|
case 'accept':
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(),
|
|
|
|
function(src, result) {
|
|
|
|
src.handle_with_time_finish(result)});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-07-11 07:09:45 -04:00
|
|
|
|
|
|
|
// Audio Video
|
2011-11-20 10:12:02 -05:00
|
|
|
const AudioVideoNotification = new Lang.Class({
|
|
|
|
Name: 'AudioVideoNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-07-11 07:09:45 -04:00
|
|
|
|
|
|
|
_init: function(source, dispatchOp, channel, contact, isVideo) {
|
|
|
|
let title = '';
|
|
|
|
|
|
|
|
if (isVideo)
|
|
|
|
/* translators: argument is a contact name like Alice for example. */
|
|
|
|
title = _("Video call from %s").format(contact.get_alias());
|
|
|
|
else
|
|
|
|
/* translators: argument is a contact name like Alice for example. */
|
|
|
|
title = _("Call from %s").format(contact.get_alias());
|
|
|
|
|
2011-11-28 04:38:00 -05:00
|
|
|
this.parent(source, title, null, { customContent: true });
|
2011-07-11 07:09:45 -04:00
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this.addButton('reject', _("Reject"));
|
2011-10-07 19:50:20 -04:00
|
|
|
/* translators: this is a button label (verb), not a noun */
|
2011-07-11 07:09:45 -04:00
|
|
|
this.addButton('answer', _("Answer"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'reject':
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE,
|
|
|
|
'', function(src, result) {
|
|
|
|
src.leave_channels_finish(result)});
|
|
|
|
break;
|
|
|
|
case 'answer':
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(),
|
|
|
|
function(src, result) {
|
|
|
|
src.handle_with_time_finish(result)});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-08-16 11:07:40 -04:00
|
|
|
|
|
|
|
// File Transfer
|
2011-11-20 10:12:02 -05:00
|
|
|
const FileTransferNotification = new Lang.Class({
|
|
|
|
Name: 'FileTransferNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-16 11:07:40 -04:00
|
|
|
|
|
|
|
_init: function(source, dispatchOp, channel, contact) {
|
2011-11-28 04:38:00 -05:00
|
|
|
this.parent(source,
|
2011-11-20 10:12:02 -05:00
|
|
|
/* To translators: The first parameter is
|
|
|
|
* the contact's alias and the second one is the
|
|
|
|
* file name. The string will be something
|
|
|
|
* like: "Alice is sending you test.ogg"
|
|
|
|
*/
|
|
|
|
_("%s is sending you %s").format(contact.get_alias(),
|
|
|
|
channel.get_filename()),
|
|
|
|
null,
|
|
|
|
{ customContent: true });
|
2011-08-16 11:07:40 -04:00
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this.addButton('decline', _("Decline"));
|
|
|
|
this.addButton('accept', _("Accept"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'decline':
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE,
|
|
|
|
'', function(src, result) {
|
|
|
|
src.leave_channels_finish(result)});
|
|
|
|
break;
|
|
|
|
case 'accept':
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(),
|
|
|
|
function(src, result) {
|
|
|
|
src.handle_with_time_finish(result)});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
// Subscription request
|
2011-11-20 10:12:02 -05:00
|
|
|
const SubscriptionRequestNotification = new Lang.Class({
|
|
|
|
Name: 'SubscriptionRequestNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
_init: function(source, contact) {
|
2011-11-28 04:38:00 -05:00
|
|
|
this.parent(source,
|
2011-11-20 10:12:02 -05:00
|
|
|
/* To translators: The parameter is the contact's alias */
|
|
|
|
_("%s would like permission to see when you are online").format(contact.get_alias()),
|
|
|
|
null, { customContent: true });
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
this._contact = contact;
|
|
|
|
this._connection = contact.get_connection();
|
|
|
|
|
|
|
|
let layout = new St.BoxLayout({ vertical: false });
|
|
|
|
|
|
|
|
// Display avatar
|
|
|
|
let iconBox = new St.Bin({ style_class: 'avatar-box' });
|
|
|
|
iconBox._size = 48;
|
|
|
|
|
|
|
|
let textureCache = St.TextureCache.get_default();
|
|
|
|
let file = contact.get_avatar_file();
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
let uri = file.get_uri();
|
|
|
|
iconBox.child = textureCache.load_uri_async(uri, iconBox._size, iconBox._size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iconBox.child = new St.Icon({ icon_name: 'avatar-default',
|
|
|
|
icon_type: St.IconType.FULLCOLOR,
|
|
|
|
icon_size: iconBox._size });
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.add(iconBox);
|
|
|
|
|
|
|
|
// subscription request message
|
|
|
|
let label = new St.Label({ style_class: 'subscription-message',
|
|
|
|
text: contact.get_publish_request() });
|
|
|
|
|
|
|
|
layout.add(label);
|
|
|
|
|
|
|
|
this.addActor(layout);
|
|
|
|
|
|
|
|
this.addButton('decline', _("Decline"));
|
|
|
|
this.addButton('accept', _("Accept"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'decline':
|
|
|
|
contact.remove_async(function(src, result) {
|
|
|
|
src.remove_finish(result)});
|
|
|
|
break;
|
|
|
|
case 'accept':
|
|
|
|
// Authorize the contact and request to see his status as well
|
|
|
|
contact.authorize_publication_async(function(src, result) {
|
|
|
|
src.authorize_publication_finish(result)});
|
|
|
|
|
|
|
|
contact.request_subscription_async('', function(src, result) {
|
|
|
|
src.request_subscription_finish(result)});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rely on _subscriptionStatesChangedCb to destroy the
|
|
|
|
// notification
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._changedId = contact.connect('subscription-states-changed',
|
|
|
|
Lang.bind(this, this._subscriptionStatesChangedCb));
|
|
|
|
this._invalidatedId = this._connection.connect('invalidated',
|
|
|
|
Lang.bind(this, this.destroy));
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if (this._changedId != 0) {
|
|
|
|
this._contact.disconnect(this._changedId);
|
|
|
|
this._changedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._invalidatedId != 0) {
|
|
|
|
this._connection.disconnect(this._invalidatedId);
|
|
|
|
this._invalidatedId = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent();
|
2011-08-26 06:27:40 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_subscriptionStatesChangedCb: function(contact, subscribe, publish, msg) {
|
|
|
|
// Destroy the notification if the subscription request has been
|
|
|
|
// answered
|
|
|
|
if (publish != Tp.SubscriptionState.ASK)
|
|
|
|
this.destroy();
|
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|
2011-08-27 20:26:25 -04:00
|
|
|
|
|
|
|
// Messages from empathy/libempathy/empathy-utils.c
|
|
|
|
// create_errors_to_message_hash()
|
|
|
|
|
|
|
|
/* Translator note: these should be the same messages that are
|
|
|
|
* used in Empathy, so just copy and paste from there. */
|
|
|
|
let _connectionErrorMessages = {};
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.NETWORK_ERROR)]
|
|
|
|
= _("Network error");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.AUTHENTICATION_FAILED)]
|
|
|
|
= _("Authentication failed");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.ENCRYPTION_ERROR)]
|
|
|
|
= _("Encryption error");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_NOT_PROVIDED)]
|
|
|
|
= _("Certificate not provided");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_UNTRUSTED)]
|
|
|
|
= _("Certificate untrusted");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_EXPIRED)]
|
|
|
|
= _("Certificate expired");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_NOT_ACTIVATED)]
|
|
|
|
= _("Certificate not activated");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_HOSTNAME_MISMATCH)]
|
|
|
|
= _("Certificate hostname mismatch");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_FINGERPRINT_MISMATCH)]
|
|
|
|
= _("Certificate fingerprint mismatch");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_SELF_SIGNED)]
|
|
|
|
= _("Certificate self-signed");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CANCELLED)]
|
|
|
|
= _("Status is set to offline");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.ENCRYPTION_NOT_AVAILABLE)]
|
|
|
|
= _("Encryption is not available");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_INVALID)]
|
|
|
|
= _("Certificate is invalid");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CONNECTION_REFUSED)]
|
|
|
|
= _("Connection has been refused");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CONNECTION_FAILED)]
|
|
|
|
= _("Connection can't be established");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CONNECTION_LOST)]
|
|
|
|
= _("Connection has been lost");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.ALREADY_CONNECTED)]
|
2012-02-08 07:36:58 -05:00
|
|
|
= _("This account is already connected to the server");
|
2011-08-27 20:26:25 -04:00
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CONNECTION_REPLACED)]
|
2011-08-30 16:16:28 -04:00
|
|
|
= _("Connection has been replaced by a new connection using the same resource");
|
2011-08-27 20:26:25 -04:00
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.REGISTRATION_EXISTS)]
|
|
|
|
= _("The account already exists on the server");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.SERVICE_BUSY)]
|
|
|
|
= _("Server is currently too busy to handle the connection");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_REVOKED)]
|
|
|
|
= _("Certificate has been revoked");
|
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_INSECURE)]
|
2011-08-30 16:16:28 -04:00
|
|
|
= _("Certificate uses an insecure cipher algorithm or is cryptographically weak");
|
2011-08-27 20:26:25 -04:00
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_LIMIT_EXCEEDED)]
|
2011-08-30 16:16:28 -04:00
|
|
|
= _("The length of the server certificate, or the depth of the server certificate chain, exceed the limits imposed by the cryptography library");
|
2011-09-13 08:05:35 -04:00
|
|
|
_connectionErrorMessages['org.freedesktop.DBus.Error.NoReply']
|
|
|
|
= _("Internal error");
|
2011-08-27 20:26:25 -04:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const AccountNotification = new Lang.Class({
|
|
|
|
Name: 'AccountNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-27 20:26:25 -04:00
|
|
|
|
|
|
|
_init: function(source, account, connectionError) {
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent(source,
|
|
|
|
/* translators: argument is the account name, like
|
|
|
|
* name@jabber.org for example. */
|
|
|
|
_("Connection to %s failed").format(account.get_display_name()),
|
|
|
|
null, { customContent: true });
|
2011-08-27 20:26:25 -04:00
|
|
|
|
2011-09-14 11:01:48 -04:00
|
|
|
this._label = new St.Label();
|
|
|
|
this.addActor(this._label);
|
|
|
|
this._updateMessage(connectionError);
|
2011-08-27 20:26:25 -04:00
|
|
|
|
|
|
|
this._account = account;
|
|
|
|
|
|
|
|
this.addButton('reconnect', _("Reconnect"));
|
|
|
|
this.addButton('edit', _("Edit account"));
|
|
|
|
|
|
|
|
this.connect('action-invoked', Lang.bind(this, function(self, action) {
|
|
|
|
switch (action) {
|
|
|
|
case 'reconnect':
|
|
|
|
// If it fails again, a new notification should pop up with the
|
|
|
|
// new error.
|
|
|
|
account.reconnect_async(null, null);
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
let cmd = '/usr/bin/empathy-accounts'
|
|
|
|
+ ' --select-account=%s'
|
|
|
|
.format(account.get_path_suffix());
|
|
|
|
let app_info = Gio.app_info_create_from_commandline(cmd, null, 0,
|
|
|
|
null);
|
|
|
|
app_info.launch([], null, null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._enabledId = account.connect('notify::enabled',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
if (!account.is_enabled())
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._invalidatedId = account.connect('invalidated',
|
|
|
|
Lang.bind(this, this.destroy));
|
|
|
|
|
|
|
|
this._connectionStatusId = account.connect('notify::connection-status',
|
|
|
|
Lang.bind(this, function() {
|
2011-09-14 11:01:48 -04:00
|
|
|
let status = account.connection_status;
|
|
|
|
if (status == Tp.ConnectionStatus.CONNECTED) {
|
2011-08-27 20:26:25 -04:00
|
|
|
this.destroy();
|
2011-09-14 11:01:48 -04:00
|
|
|
} else if (status == Tp.ConnectionStatus.DISCONNECTED) {
|
|
|
|
this._updateMessage(account.connection_error);
|
|
|
|
}
|
2011-08-27 20:26:25 -04:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2011-09-14 11:01:48 -04:00
|
|
|
_updateMessage: function(connectionError) {
|
|
|
|
let message;
|
|
|
|
if (connectionError in _connectionErrorMessages) {
|
|
|
|
message = _connectionErrorMessages[connectionError];
|
|
|
|
} else {
|
|
|
|
message = _("Unknown reason");
|
|
|
|
}
|
|
|
|
this._label.set_text(message);
|
|
|
|
},
|
|
|
|
|
2011-08-27 20:26:25 -04:00
|
|
|
destroy: function() {
|
|
|
|
if (this._enabledId != 0) {
|
|
|
|
this._account.disconnect(this._enabledId);
|
|
|
|
this._enabledId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._invalidatedId != 0) {
|
|
|
|
this._account.disconnect(this._invalidatedId);
|
|
|
|
this._invalidatedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._connectionStatusId != 0) {
|
|
|
|
this._account.disconnect(this._connectionStatusId);
|
|
|
|
this._connectionStatusId = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
this.parent();
|
2011-08-27 20:26:25 -04:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|