2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-08-16 15:07:40 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2010-04-14 14:24:14 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
2010-02-02 15:21:47 +00:00
|
|
|
const Lang = imports.lang;
|
2010-11-25 14:29:41 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2011-02-08 12:17:29 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-04-16 21:24:34 +00:00
|
|
|
const Signals = imports.signals;
|
2010-02-02 15:21:47 +00:00
|
|
|
const St = imports.gi.St;
|
2011-03-07 22:10:53 +00:00
|
|
|
const Tpl = imports.gi.TelepathyLogger;
|
2011-02-07 16:34:08 +00:00
|
|
|
const Tp = imports.gi.TelepathyGLib;
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-02-20 08:41:51 +00:00
|
|
|
const History = imports.misc.history;
|
2010-02-02 15:21:47 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2012-09-13 21:42:08 +00:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2010-02-22 19:23:36 +00:00
|
|
|
// See Notification.appendMessage
|
2010-11-25 14:29:41 +00:00
|
|
|
const SCROLLBACK_IMMEDIATE_TIME = 60; // 1 minute
|
2010-02-22 19:23:36 +00:00
|
|
|
const SCROLLBACK_RECENT_TIME = 15 * 60; // 15 minutes
|
|
|
|
const SCROLLBACK_RECENT_LENGTH = 20;
|
|
|
|
const SCROLLBACK_IDLE_LENGTH = 5;
|
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
// See Source._displayPendingMessages
|
|
|
|
const SCROLLBACK_HISTORY_LINES = 10;
|
|
|
|
|
2011-07-07 12:42:07 +00:00
|
|
|
// See Notification._onEntryChanged
|
|
|
|
const COMPOSING_STOP_TIMEOUT = 5;
|
|
|
|
|
2010-11-28 15:14:34 +00:00
|
|
|
const NotificationDirection = {
|
|
|
|
SENT: 'chat-sent',
|
|
|
|
RECEIVED: 'chat-received'
|
|
|
|
};
|
2010-04-16 19:18:32 +00:00
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
function makeMessageFromTpMessage(tpMessage, direction) {
|
|
|
|
let [text, flags] = tpMessage.to_text();
|
2011-08-23 17:38:51 +00:00
|
|
|
|
|
|
|
let timestamp = tpMessage.get_sent_timestamp();
|
|
|
|
if (timestamp == 0)
|
|
|
|
timestamp = tpMessage.get_received_timestamp();
|
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
return {
|
|
|
|
messageType: tpMessage.get_message_type(),
|
|
|
|
text: text,
|
|
|
|
sender: tpMessage.sender.alias,
|
2011-08-23 17:38:51 +00:00
|
|
|
timestamp: timestamp,
|
2011-03-07 22:10:53 +00: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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
const TelepathyClient = new Lang.Class({
|
|
|
|
Name: 'TelepathyClient',
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
_init: function() {
|
2011-06-30 09:53:44 +00:00
|
|
|
// channel path -> ChatSource
|
|
|
|
this._chatSources = {};
|
2011-07-07 12:42:07 +00:00
|
|
|
this._chatState = Tp.ChannelChatState.ACTIVE;
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-09-14 15:01:48 +00:00
|
|
|
// account path -> AccountNotification
|
|
|
|
this._accountNotifications = {};
|
|
|
|
|
2011-09-12 12:33:02 +00: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 16:34:08 +00: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.
|
2012-09-03 01:23:50 +00:00
|
|
|
this._tpClient = new Shell.TpClient({ name: 'GnomeShell',
|
|
|
|
account_manager: this._accountManager,
|
|
|
|
uniquify_name: true });
|
2011-06-23 21:57:48 +00:00
|
|
|
this._tpClient.set_observe_channels_func(
|
2011-03-23 10:22:42 +00:00
|
|
|
Lang.bind(this, this._observeChannels));
|
2011-06-23 21:57:48 +00:00
|
|
|
this._tpClient.set_approve_channels_func(
|
2011-04-05 11:28:11 +00:00
|
|
|
Lang.bind(this, this._approveChannels));
|
2011-06-23 21:57:48 +00:00
|
|
|
this._tpClient.set_handle_channels_func(
|
2011-04-05 11:28:11 +00:00
|
|
|
Lang.bind(this, this._handleChannels));
|
2011-02-07 16:34:08 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
// Watch subscription requests and connection errors
|
|
|
|
this._subscriptionSource = null;
|
|
|
|
this._accountSource = null;
|
|
|
|
|
2011-08-26 10:27:40 +00: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 12:29:23 +00: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));
|
2012-09-03 01:23:50 +00:00
|
|
|
},
|
2011-06-24 12:29:23 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
enable: function() {
|
2011-02-07 16:34:08 +00:00
|
|
|
try {
|
2011-06-23 21:57:48 +00:00
|
|
|
this._tpClient.register();
|
2011-02-07 16:34:08 +00:00
|
|
|
} catch (e) {
|
2011-04-05 11:28:11 +00:00
|
|
|
throw new Error('Couldn\'t register Telepathy client. Error: \n' + e);
|
2011-02-07 16:34:08 +00:00
|
|
|
}
|
2011-08-26 10:27:40 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
this._accountManagerValidityChangedId = this._accountManager.connect('account-validity-changed',
|
|
|
|
Lang.bind(this, this._accountValidityChanged));
|
2011-08-26 10:27:40 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
if (!this._accountManager.is_prepared(Tp.AccountManager.get_feature_quark_core()))
|
|
|
|
this._accountManager.prepare_async(null, Lang.bind(this, this._accountManagerPrepared));
|
|
|
|
},
|
2011-08-26 10:27:40 +00:00
|
|
|
|
2012-09-03 01:23:50 +00:00
|
|
|
disable: function() {
|
|
|
|
this._tpClient.unregister();
|
|
|
|
this._accountManager.disconnect(this._accountManagerValidityChangedId);
|
|
|
|
this._accountManagerValidityChangedId = 0;
|
2011-02-07 16:34:08 +00: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-08-14 19:21:10 +00:00
|
|
|
if (channel.get_invalidated())
|
2012-06-05 10:39:30 +00:00
|
|
|
continue;
|
|
|
|
|
2011-02-07 16:34:08 +00:00
|
|
|
/* Only observe contact text channels */
|
|
|
|
if ((!(channel instanceof Tp.TextChannel)) ||
|
|
|
|
targetHandleType != Tp.HandleType.CONTACT)
|
|
|
|
continue;
|
|
|
|
|
2011-09-12 12:33:02 +00:00
|
|
|
this._createChatSource(account, conn, channel, channel.get_target_contact());
|
2011-02-07 16:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
context.accept();
|
2011-02-09 10:35:50 +00:00
|
|
|
},
|
|
|
|
|
2011-07-17 19:25:42 +00:00
|
|
|
_createChatSource: function(account, conn, channel, contact) {
|
2011-06-30 09:53:44 +00:00
|
|
|
if (this._chatSources[channel.get_object_path()])
|
2011-02-09 10:35:50 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-30 09:53:44 +00:00
|
|
|
let source = new ChatSource(account, conn, channel, contact, this._tpClient);
|
2011-02-09 10:35:50 +00:00
|
|
|
|
2011-06-30 09:53:44 +00:00
|
|
|
this._chatSources[channel.get_object_path()] = source;
|
2011-02-09 10:35:50 +00:00
|
|
|
source.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
2011-06-23 21:57:48 +00:00
|
|
|
if (this._tpClient.is_handling_channel(channel)) {
|
2011-04-05 11:28:11 +00:00
|
|
|
// The chat box has been destroyed so it can't
|
|
|
|
// handle the channel any more.
|
2011-06-28 16:06:54 +00:00
|
|
|
channel.close_async(function(src, result) {
|
|
|
|
channel.close_finish(result);
|
|
|
|
});
|
2011-04-05 11:28:11 +00:00
|
|
|
}
|
|
|
|
|
2011-06-30 09:53:44 +00:00
|
|
|
delete this._chatSources[channel.get_object_path()];
|
2011-02-09 10:35:50 +00:00
|
|
|
}));
|
2011-04-05 11:28:11 +00:00
|
|
|
},
|
|
|
|
|
2011-07-17 19:25:42 +00:00
|
|
|
_handleChannels: function(handler, account, conn, channels,
|
|
|
|
requests, user_action_time, context) {
|
2011-12-15 11:24:38 +00:00
|
|
|
this._handlingChannels(account, conn, channels, true);
|
2011-07-17 19:25:42 +00:00
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-12-15 11:24:38 +00:00
|
|
|
_handlingChannels: function(account, conn, channels, notify) {
|
2011-04-05 11:28:11 +00: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-08-14 19:21:10 +00:00
|
|
|
if (channel.get_invalidated())
|
2012-06-05 10:39:30 +00:00
|
|
|
continue;
|
|
|
|
|
2011-12-15 11:24:38 +00: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 11:28:11 +00:00
|
|
|
// We are already handling the channel, display the source
|
2011-06-30 09:53:44 +00:00
|
|
|
let source = this._chatSources[channel.get_object_path()];
|
2011-04-05 11:28:11 +00:00
|
|
|
if (source)
|
|
|
|
source.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-06-30 12:05:41 +00:00
|
|
|
_displayRoomInvitation: function(conn, channel, dispatchOp, context) {
|
|
|
|
// We can only approve the rooms if we have been invited to it
|
2011-09-12 12:33:02 +00:00
|
|
|
let selfContact = channel.group_get_self_contact();
|
|
|
|
if (selfContact == null) {
|
2012-08-14 19:21:10 +00:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Not invited to the room' }));
|
2011-06-30 12:05:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:33:02 +00:00
|
|
|
let [invited, inviter, reason, msg] = channel.group_get_local_pending_contact_info(selfContact);
|
2011-06-30 12:05:41 +00:00
|
|
|
if (!invited) {
|
2012-08-14 19:21:10 +00:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Not invited to the room' }));
|
2011-06-30 12:05:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 10:59:23 +00:00
|
|
|
// FIXME: We don't have a 'chat room' icon (bgo #653737) use
|
|
|
|
// system-users for now as Empathy does.
|
2011-08-16 14:59:34 +00:00
|
|
|
let source = new ApproverSource(dispatchOp, _("Invitation"),
|
2011-10-07 21:35:38 +00:00
|
|
|
Gio.icon_new_for_string('system-users'));
|
2011-06-30 12:05:41 +00:00
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
2011-09-12 12:33:02 +00:00
|
|
|
let notif = new RoomInviteNotification(source, dispatchOp, channel, inviter);
|
2011-06-30 12:05:41 +00:00
|
|
|
source.notify(notif);
|
2011-04-05 11:28:11 +00:00
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-06-30 12:05:41 +00:00
|
|
|
_approveChannels: function(approver, account, conn, channels,
|
|
|
|
dispatchOp, context) {
|
|
|
|
let channel = channels[0];
|
2011-07-11 11:09:45 +00:00
|
|
|
let chanType = channel.get_channel_type();
|
|
|
|
|
2012-08-14 19:21:10 +00:00
|
|
|
if (channel.get_invalidated()) {
|
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Channel is invalidated' }));
|
2012-06-05 10:39:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 11:09:45 +00:00
|
|
|
if (chanType == Tp.IFACE_CHANNEL_TYPE_TEXT)
|
|
|
|
this._approveTextChannel(account, conn, channel, dispatchOp, context);
|
2012-01-11 12:39:38 +00:00
|
|
|
else if (chanType == Tp.IFACE_CHANNEL_TYPE_CALL)
|
2011-07-11 11:09:45 +00:00
|
|
|
this._approveCall(account, conn, channel, dispatchOp, context);
|
2011-08-16 15:07:40 +00:00
|
|
|
else if (chanType == Tp.IFACE_CHANNEL_TYPE_FILE_TRANSFER)
|
|
|
|
this._approveFileTransfer(account, conn, channel, dispatchOp, context);
|
2012-06-05 10:37:06 +00:00
|
|
|
else
|
2012-08-14 19:21:10 +00:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Unsupported channel type' }));
|
2011-07-11 11:09:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_approveTextChannel: function(account, conn, channel, dispatchOp, context) {
|
2011-06-30 12:05:41 +00: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 11:24:38 +00:00
|
|
|
this._handlingChannels(account, conn, [channel], false);
|
2011-06-30 12:05:41 +00:00
|
|
|
} catch (err) {
|
|
|
|
throw new Error('Failed to Claim channel: ' + err);
|
|
|
|
}}));
|
|
|
|
|
|
|
|
context.accept();
|
|
|
|
} else {
|
|
|
|
this._displayRoomInvitation(conn, channel, dispatchOp, context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-11 11:09:45 +00:00
|
|
|
_approveCall: function(account, conn, channel, dispatchOp, context) {
|
|
|
|
let isVideo = false;
|
|
|
|
|
|
|
|
let props = channel.borrow_immutable_properties();
|
|
|
|
|
2012-01-11 12:39:38 +00:00
|
|
|
if (props[Tp.PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO])
|
2011-07-11 11:09:45 +00:00
|
|
|
isVideo = true;
|
|
|
|
|
|
|
|
// We got the TpContact
|
2011-08-16 14:59:34 +00:00
|
|
|
let source = new ApproverSource(dispatchOp, _("Call"), isVideo ?
|
2011-10-07 21:35:38 +00:00
|
|
|
Gio.icon_new_for_string('camera-web') :
|
|
|
|
Gio.icon_new_for_string('audio-input-microphone'));
|
2011-07-11 11:09:45 +00:00
|
|
|
Main.messageTray.add(source);
|
|
|
|
|
2011-09-12 12:33:02 +00:00
|
|
|
let notif = new AudioVideoNotification(source, dispatchOp, channel,
|
|
|
|
channel.get_target_contact(), isVideo);
|
2011-07-11 11:09:45 +00:00
|
|
|
source.notify(notif);
|
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-08-16 15:07:40 +00: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 12:33:02 +00:00
|
|
|
let notif = new FileTransferNotification(source, dispatchOp, channel,
|
|
|
|
channel.get_target_contact());
|
2011-08-16 15:07:40 +00:00
|
|
|
source.notify(notif);
|
|
|
|
context.accept();
|
|
|
|
},
|
|
|
|
|
2011-06-24 12:29:23 +00:00
|
|
|
_delegatedChannelsCb: function(client, channels) {
|
|
|
|
// Nothing to do as we don't make a distinction between observed and
|
|
|
|
// handled channels.
|
2011-08-26 10:27:40 +00: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-28 00:26:25 +00: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 10:27:40 +00: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 22:00:32 +00:00
|
|
|
this._subscriptionSource = new MessageTray.Source(_("Subscription request"),
|
2012-05-30 13:58:37 +00:00
|
|
|
'gtk-dialog-question');
|
2011-09-14 15:01:48 +00:00
|
|
|
Main.messageTray.add(this._subscriptionSource);
|
2011-08-26 10:27:40 +00:00
|
|
|
this._subscriptionSource.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._subscriptionSource = null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._subscriptionSource;
|
2011-08-28 00:26:25 +00: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 15:01:48 +00:00
|
|
|
let notif = this._accountNotifications[account.get_object_path()];
|
|
|
|
if (notif)
|
|
|
|
return;
|
|
|
|
|
2011-08-28 00:26:25 +00:00
|
|
|
/* Display notification that account failed to connect */
|
|
|
|
let source = this._ensureAccountSource();
|
|
|
|
|
2011-09-14 15:01:48 +00: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-28 00:26:25 +00:00
|
|
|
source.notify(notif);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ensureAccountSource: function() {
|
|
|
|
if (this._accountSource == null) {
|
2011-10-08 22:00:32 +00:00
|
|
|
this._accountSource = new MessageTray.Source(_("Connection error"),
|
2012-05-30 13:58:37 +00:00
|
|
|
'gtk-dialog-error');
|
2011-09-14 15:01:48 +00:00
|
|
|
Main.messageTray.add(this._accountSource);
|
2011-08-28 00:26:25 +00:00
|
|
|
this._accountSource.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._accountSource = null;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._accountSource;
|
2010-02-02 15:21:47 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const ChatSource = new Lang.Class({
|
|
|
|
Name: 'ChatSource',
|
|
|
|
Extends: MessageTray.Source,
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-04-05 11:28:11 +00:00
|
|
|
_init: function(account, conn, channel, contact, client) {
|
2011-02-08 10:22:46 +00:00
|
|
|
this._account = account;
|
2011-02-08 12:17:29 +00:00
|
|
|
this._contact = contact;
|
2011-04-05 11:28:11 +00:00
|
|
|
this._client = client;
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-10-08 22:00:32 +00:00
|
|
|
this.parent(contact.get_alias());
|
|
|
|
|
2012-05-25 09:15:57 +00:00
|
|
|
this.isChat = true;
|
2011-05-27 09:39:50 +00:00
|
|
|
this._pendingMessages = [];
|
|
|
|
|
2011-02-08 10:22:46 +00:00
|
|
|
this._conn = conn;
|
|
|
|
this._channel = channel;
|
|
|
|
this._closedId = this._channel.connect('invalidated', Lang.bind(this, this._channelClosed));
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-06-30 09:53:44 +00:00
|
|
|
this._notification = new ChatNotification(this);
|
2011-01-04 09:34:57 +00:00
|
|
|
this._notification.setUrgency(MessageTray.Urgency.HIGH);
|
2011-08-22 14:23:50 +00:00
|
|
|
this._notifyTimeoutId = 0;
|
2010-11-28 15:14:34 +00:00
|
|
|
|
2011-12-08 23:35:19 +00: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 09:39:50 +00:00
|
|
|
|
2011-02-08 13:50:06 +00:00
|
|
|
this._presence = contact.get_presence_type();
|
2010-04-16 21:24:34 +00:00
|
|
|
|
2011-02-08 15:19:01 +00: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 09:39:50 +00:00
|
|
|
this._pendingId = this._channel.connect('pending-message-removed', Lang.bind(this, this._pendingRemoved));
|
2010-08-05 17:09:27 +00:00
|
|
|
|
2011-02-08 12:17:29 +00:00
|
|
|
this._notifyAliasId = this._contact.connect('notify::alias', Lang.bind(this, this._updateAlias));
|
2011-02-08 13:05:20 +00:00
|
|
|
this._notifyAvatarId = this._contact.connect('notify::avatar-file', Lang.bind(this, this._updateAvatarIcon));
|
2011-02-08 13:50:06 +00:00
|
|
|
this._presenceChangedId = this._contact.connect('presence-changed', Lang.bind(this, this._presenceChanged));
|
2011-02-08 15:19:01 +00:00
|
|
|
|
2011-02-28 18:14:07 +00:00
|
|
|
// Add ourselves as a source.
|
|
|
|
Main.messageTray.add(this);
|
|
|
|
this.pushNotification(this._notification);
|
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
this._getLogMessages();
|
2011-02-08 12:17:29 +00:00
|
|
|
},
|
|
|
|
|
2012-09-05 15:32:45 +00:00
|
|
|
buildRightClickMenu: function() {
|
|
|
|
let item;
|
|
|
|
|
|
|
|
let rightClickMenu = this.parent();
|
|
|
|
item = new PopupMenu.PopupMenuItem('');
|
|
|
|
item.actor.connect('notify::mapped', Lang.bind(this, function() {
|
2012-09-14 16:15:51 +00:00
|
|
|
item.label.set_text(this.isMuted ? _("Unmute") : _("Mute"));
|
2012-09-05 15:32:45 +00:00
|
|
|
}));
|
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
|
|
|
this.setMuted(!this.isMuted);
|
|
|
|
this.emit('done-displaying-content');
|
|
|
|
}));
|
|
|
|
rightClickMenu.add(item.actor);
|
|
|
|
return rightClickMenu;
|
|
|
|
},
|
|
|
|
|
2011-02-08 12:17:29 +00:00
|
|
|
_updateAlias: function() {
|
2011-02-28 18:15:02 +00:00
|
|
|
let oldAlias = this.title;
|
2011-10-03 18:48:49 +00:00
|
|
|
let newAlias = this._contact.get_alias();
|
|
|
|
|
|
|
|
if (oldAlias == newAlias)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.setTitle(newAlias);
|
|
|
|
this._notification.appendAliasChange(oldAlias, newAlias);
|
2010-02-02 15:21:47 +00:00
|
|
|
},
|
|
|
|
|
2012-09-15 06:10:15 +00:00
|
|
|
getIcon: function() {
|
2011-02-08 13:05:20 +00:00
|
|
|
let file = this._contact.get_avatar_file();
|
|
|
|
if (file) {
|
2012-09-15 06:10:15 +00:00
|
|
|
return new Gio.FileIcon({ file: file });
|
2011-02-08 13:05:20 +00:00
|
|
|
} else {
|
2012-09-15 06:10:15 +00:00
|
|
|
return new Gio.ThemedIcon({ name: 'avatar-default' });
|
2011-02-08 13:05:20 +00:00
|
|
|
}
|
2011-09-21 20:46:08 +00:00
|
|
|
},
|
|
|
|
|
2012-09-15 06:10:15 +00:00
|
|
|
getSecondaryIcon: function() {
|
2012-09-14 14:33:52 +00:00
|
|
|
let iconName;
|
2012-07-05 17:47:13 +00:00
|
|
|
let presenceType = this._contact.get_presence_type();
|
|
|
|
|
|
|
|
switch (presenceType) {
|
|
|
|
case Tp.ConnectionPresenceType.AVAILABLE:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-available';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.BUSY:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-busy';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.OFFLINE:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-offline';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.HIDDEN:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-invisible';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.AWAY:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-away';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.EXTENDED_AWAY:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-idle';
|
2012-07-05 17:47:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-14 14:33:52 +00:00
|
|
|
iconName = 'user-offline';
|
2012-07-05 17:47:13 +00:00
|
|
|
}
|
2012-09-14 14:33:52 +00:00
|
|
|
return new Gio.ThemedIcon({ name: iconName });
|
2012-07-05 17:47:13 +00:00
|
|
|
},
|
|
|
|
|
2011-09-21 20:46:08 +00:00
|
|
|
_updateAvatarIcon: function() {
|
2012-07-23 04:07:51 +00:00
|
|
|
this.iconUpdated();
|
2012-07-19 13:05:17 +00:00
|
|
|
this._notification.update(this._notification.title, null, { customContent: true });
|
2010-02-02 15:21:47 +00:00
|
|
|
},
|
|
|
|
|
2011-02-11 19:43:01 +00:00
|
|
|
open: function(notification) {
|
2011-04-05 11:28:11 +00:00
|
|
|
if (this._client.is_handling_channel(this._channel)) {
|
|
|
|
// We are handling the channel, try to pass it to Empathy
|
2011-09-30 21:30:47 +00:00
|
|
|
this._client.delegate_channels_async([this._channel], global.get_current_time(), '', null);
|
2011-04-05 11:28:11 +00: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 14:55:22 +00:00
|
|
|
},
|
|
|
|
|
2011-03-07 22:10:53 +00: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 18:55:20 +00:00
|
|
|
|
|
|
|
logManager.get_filtered_events_async(this._account, entity,
|
|
|
|
Tpl.EventTypeMask.TEXT, SCROLLBACK_HISTORY_LINES,
|
|
|
|
null, Lang.bind(this, this._displayPendingMessages));
|
2011-03-07 22:10:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_displayPendingMessages: function(logManager, result) {
|
|
|
|
let [success, events] = logManager.get_filtered_events_finish(result);
|
|
|
|
|
|
|
|
let logMessages = events.map(makeMessageFromTplEvent);
|
|
|
|
|
2011-03-23 19:25:42 +00:00
|
|
|
let pendingTpMessages = this._channel.get_pending_messages();
|
2011-05-27 08:52:08 +00: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 09:39:50 +00:00
|
|
|
|
|
|
|
this._pendingMessages.push(message);
|
2011-05-27 08:52:08 +00:00
|
|
|
}
|
2011-03-23 19:25:42 +00:00
|
|
|
|
2012-08-06 15:28:55 +00:00
|
|
|
this.countUpdated();
|
2011-06-27 12:31:53 +00:00
|
|
|
|
2011-03-24 11:09:04 +00:00
|
|
|
let showTimestamp = false;
|
|
|
|
|
2011-03-23 19:25:42 +00: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 22:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-03-24 11:09:04 +00:00
|
|
|
if (!isPending) {
|
|
|
|
showTimestamp = true;
|
2011-03-24 11:11:17 +00:00
|
|
|
this._notification.appendMessage(logMessage, true, ['chat-log-message']);
|
2011-03-24 11:09:04 +00:00
|
|
|
}
|
2011-02-08 15:19:01 +00:00
|
|
|
}
|
2011-03-07 22:10:53 +00:00
|
|
|
|
2011-03-24 11:09:04 +00:00
|
|
|
if (showTimestamp)
|
|
|
|
this._notification.appendTimestamp();
|
|
|
|
|
2011-03-23 19:25:42 +00:00
|
|
|
for (let i = 0; i < pendingMessages.length; i++)
|
|
|
|
this._notification.appendMessage(pendingMessages[i], true);
|
|
|
|
|
|
|
|
if (pendingMessages.length > 0)
|
2011-03-07 22:10:53 +00:00
|
|
|
this.notify();
|
2010-02-02 15:21:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_channelClosed: function() {
|
|
|
|
this._channel.disconnect(this._closedId);
|
2011-02-08 15:19:01 +00:00
|
|
|
this._channel.disconnect(this._receivedId);
|
2011-05-27 09:39:50 +00:00
|
|
|
this._channel.disconnect(this._pendingId);
|
2011-02-08 15:19:01 +00:00
|
|
|
this._channel.disconnect(this._sentId);
|
2011-02-08 12:17:29 +00:00
|
|
|
|
|
|
|
this._contact.disconnect(this._notifyAliasId);
|
2011-02-08 13:05:20 +00:00
|
|
|
this._contact.disconnect(this._notifyAvatarId);
|
2011-02-08 13:50:06 +00:00
|
|
|
this._contact.disconnect(this._presenceChangedId);
|
2011-02-08 15:19:01 +00:00
|
|
|
|
2010-02-02 15:21:47 +00:00
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2012-08-06 15:28:55 +00: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 12:31:53 +00:00
|
|
|
},
|
|
|
|
|
2011-02-08 15:19:01 +00:00
|
|
|
_messageReceived: function(channel, message) {
|
2011-05-05 12:19:59 +00:00
|
|
|
if (message.get_message_type() == Tp.ChannelTextMessageType.DELIVERY_REPORT)
|
|
|
|
return;
|
|
|
|
|
2011-05-27 09:39:50 +00:00
|
|
|
this._pendingMessages.push(message);
|
2012-08-06 15:28:55 +00:00
|
|
|
this.countUpdated();
|
2011-05-27 09:39:50 +00:00
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
message = makeMessageFromTpMessage(message, NotificationDirection.RECEIVED);
|
|
|
|
this._notification.appendMessage(message);
|
2011-08-22 14:23:50 +00: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 15:14:34 +00:00
|
|
|
},
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2010-11-28 15:14:34 +00:00
|
|
|
// This is called for both messages we send from
|
|
|
|
// our client and other clients as well.
|
2011-02-08 15:19:01 +00:00
|
|
|
_messageSent: function(channel, message, flags, token) {
|
2011-03-07 22:10:53 +00:00
|
|
|
message = makeMessageFromTpMessage(message, NotificationDirection.SENT);
|
|
|
|
this._notification.appendMessage(message);
|
2010-04-16 21:24:34 +00:00
|
|
|
},
|
|
|
|
|
2010-11-28 15:14:34 +00:00
|
|
|
notify: function() {
|
2011-11-20 17:56:27 +00:00
|
|
|
this.parent(this._notification);
|
2010-02-22 19:23:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
respond: function(text) {
|
2011-02-26 14:38:25 +00: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 15:42:41 +00:00
|
|
|
this._channel.send_message_async(msg, 0, Lang.bind(this, function (src, result) {
|
|
|
|
this._channel.send_message_finish(result);
|
|
|
|
}));
|
2010-04-16 21:24:34 +00:00
|
|
|
},
|
|
|
|
|
2011-07-07 12:42:07 +00: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 20:07:29 +00:00
|
|
|
_presenceChanged: function (contact, presence, status, message) {
|
2012-07-05 17:47:13 +00:00
|
|
|
let msg, title;
|
2011-02-08 13:50:06 +00:00
|
|
|
|
2011-02-14 04:13:07 +00:00
|
|
|
title = GLib.markup_escape_text(this.title, -1);
|
2010-04-16 21:24:34 +00:00
|
|
|
|
2012-09-15 06:10:15 +00:00
|
|
|
this._notification.update(this._notification.title, null, { customContent: true, secondaryGIcon: this.getSecondaryIcon() });
|
2010-04-16 21:24:34 +00:00
|
|
|
|
|
|
|
if (message)
|
|
|
|
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
|
2011-05-27 09:39:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_pendingRemoved: function(channel, message) {
|
|
|
|
let idx = this._pendingMessages.indexOf(message);
|
|
|
|
|
2011-06-27 12:31:53 +00:00
|
|
|
if (idx >= 0) {
|
2011-05-27 09:39:50 +00:00
|
|
|
this._pendingMessages.splice(idx, 1);
|
2012-08-06 15:28:55 +00:00
|
|
|
this.countUpdated();
|
2011-06-27 12:31:53 +00:00
|
|
|
}
|
2011-05-27 09:39:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_ackMessages: function() {
|
|
|
|
// Don't clear our messages here, tp-glib will send a
|
|
|
|
// 'pending-message-removed' for each one.
|
2011-07-11 14:14:36 +00: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 15:21:47 +00:00
|
|
|
}
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const ChatNotification = new Lang.Class({
|
|
|
|
Name: 'ChatNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2010-02-02 15:21:47 +00:00
|
|
|
|
2010-08-11 13:43:40 +00:00
|
|
|
_init: function(source) {
|
2012-09-15 06:10:15 +00:00
|
|
|
this.parent(source, source.title, null, { customContent: true, secondaryGIcon: source.getSecondaryIcon() });
|
2010-12-22 07:41:11 +00:00
|
|
|
this.setResident(true);
|
2010-02-22 19:23:36 +00:00
|
|
|
|
2011-02-10 03:45:50 +00:00
|
|
|
this._responseEntry = new St.Entry({ style_class: 'chat-response',
|
|
|
|
can_focus: true });
|
2010-02-22 19:23:36 +00:00
|
|
|
this._responseEntry.clutter_text.connect('activate', Lang.bind(this, this._onEntryActivated));
|
2011-07-07 12:42:07 +00:00
|
|
|
this._responseEntry.clutter_text.connect('text-changed', Lang.bind(this, this._onEntryChanged));
|
2010-02-22 19:23:36 +00:00
|
|
|
this.setActionArea(this._responseEntry);
|
|
|
|
|
2012-09-05 16:59:50 +00:00
|
|
|
this._responseEntry.clutter_text.connect('key-focus-in', Lang.bind(this, function() {
|
|
|
|
this.focused = true;
|
|
|
|
}));
|
|
|
|
this._responseEntry.clutter_text.connect('key-focus-out', Lang.bind(this, function() {
|
|
|
|
this.focused = false;
|
|
|
|
this.emit('unfocused');
|
|
|
|
}));
|
|
|
|
|
2011-03-09 12:56:35 +00:00
|
|
|
this._oldMaxScrollAdjustment = 0;
|
|
|
|
this._createScrollArea();
|
2011-08-24 14:33:44 +00:00
|
|
|
this._lastGroup = null;
|
|
|
|
this._lastGroupActor = null;
|
2011-03-09 12:56:35 +00: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 08:41:51 +00:00
|
|
|
this._inputHistory = new History.HistoryManager({ entry: this._responseEntry.clutter_text });
|
|
|
|
|
2010-02-22 19:23:36 +00:00
|
|
|
this._history = [];
|
2010-11-25 14:29:41 +00:00
|
|
|
this._timestampTimeoutId = 0;
|
2011-07-07 12:42:07 +00:00
|
|
|
this._composingTimeoutId = 0;
|
2010-02-22 19:23:36 +00:00
|
|
|
},
|
|
|
|
|
2011-03-07 22:10:53 +00: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 14:33:44 +00:00
|
|
|
appendMessage: function(message, noTimestamp) {
|
2011-03-07 22:10:53 +00:00
|
|
|
let messageBody = GLib.markup_escape_text(message.text, -1);
|
2011-08-24 14:33:44 +00:00
|
|
|
let styles = [message.direction];
|
2011-03-07 22:10:53 +00:00
|
|
|
|
|
|
|
if (message.messageType == Tp.ChannelTextMessageType.ACTION) {
|
|
|
|
let senderAlias = GLib.markup_escape_text(message.sender, -1);
|
2011-02-26 14:38:25 +00:00
|
|
|
messageBody = '<i>%s</i> %s'.format(senderAlias, messageBody);
|
|
|
|
styles.push('chat-action');
|
|
|
|
}
|
|
|
|
|
2011-05-15 09:07:23 +00:00
|
|
|
if (message.direction == NotificationDirection.RECEIVED) {
|
|
|
|
this.update(this.source.title, messageBody, { customContent: true,
|
|
|
|
bannerMarkup: true });
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:33:44 +00: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 19:23:36 +00:00
|
|
|
},
|
|
|
|
|
2011-05-25 17:18:56 +00: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 14:33:44 +00:00
|
|
|
|
|
|
|
let groups = this._contentArea.get_children();
|
2011-10-20 20:40:22 +00:00
|
|
|
for (let i = 0; i < groups.length; i++) {
|
2011-08-24 14:33:44 +00:00
|
|
|
let group = groups[i];
|
2012-05-30 00:36:45 +00:00
|
|
|
if (group.get_n_children() == 0)
|
2011-08-24 14:33:44 +00:00
|
|
|
group.destroy();
|
|
|
|
}
|
2011-05-25 17:18:56 +00:00
|
|
|
},
|
|
|
|
|
2011-08-24 14:33:44 +00: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 14:29:41 +00:00
|
|
|
let currentTime = (Date.now() / 1000);
|
2011-08-24 14:33:44 +00:00
|
|
|
props = Params.parse(props, { body: null,
|
|
|
|
group: null,
|
|
|
|
styles: [],
|
|
|
|
timestamp: currentTime,
|
|
|
|
noTimestamp: false,
|
|
|
|
childProps: null });
|
2010-11-25 14:29:41 +00:00
|
|
|
|
|
|
|
// Reset the old message timeout
|
|
|
|
if (this._timestampTimeoutId)
|
|
|
|
Mainloop.source_remove(this._timestampTimeoutId);
|
|
|
|
|
2011-08-24 14:33:44 +00: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 20:40:22 +00:00
|
|
|
for (let i = 0; i < styles.length; i++)
|
2011-02-26 14:38:25 +00:00
|
|
|
body.add_style_class_name(styles[i]);
|
2010-02-22 19:23:36 +00:00
|
|
|
|
2011-08-24 14:33:44 +00: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 14:29:41 +00:00
|
|
|
|
2011-08-24 14:33:44 +00:00
|
|
|
this._lastGroupActor.add(body, props.childProps);
|
|
|
|
|
2012-04-13 17:05:51 +00:00
|
|
|
this.updated();
|
|
|
|
|
2011-08-24 14:33:44 +00:00
|
|
|
let timestamp = props.timestamp;
|
|
|
|
this._history.unshift({ actor: body, time: timestamp,
|
|
|
|
realMessage: group != 'meta' });
|
|
|
|
|
|
|
|
if (!props.noTimestamp) {
|
2011-03-07 22:10:53 +00: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 19:23:36 +00:00
|
|
|
|
2011-05-25 17:18:56 +00:00
|
|
|
this._filterMessages();
|
2010-02-22 19:23:36 +00:00
|
|
|
},
|
|
|
|
|
2011-03-28 20:37:53 +00:00
|
|
|
_formatTimestamp: function(date) {
|
|
|
|
let now = new Date();
|
|
|
|
|
|
|
|
var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
|
|
|
|
|
2011-03-30 09:44:53 +00:00
|
|
|
let format;
|
|
|
|
|
2012-09-30 13:39:37 +00:00
|
|
|
// Show only the hour if date is on today
|
|
|
|
if(daysAgo < 1){
|
|
|
|
format = "<b>%H:%M</b>";
|
|
|
|
}
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
|
|
|
else if(daysAgo <2){
|
|
|
|
/* Translators: this is a time format string followed by the word "Yesterday". i.e. "14:30 on Yesterday"*/
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("<b>%H:%M</b> on Yesterday");
|
|
|
|
}
|
2011-03-28 20:37:53 +00:00
|
|
|
// Show a week day and time if date is in the last week
|
2012-09-30 13:39:37 +00:00
|
|
|
else if (daysAgo < 7) {
|
|
|
|
/* Translators: this is a time format string followed by a week day name. i.e. "14:30 on Monday*/
|
2011-03-28 20:37:53 +00:00
|
|
|
// xgettext:no-c-format
|
2012-09-30 13:39:37 +00:00
|
|
|
format = _("<b>%H:%M</b> on <b>%A</b>");
|
2011-03-28 20:37:53 +00:00
|
|
|
|
|
|
|
} else if (date.getYear() == now.getYear()) {
|
2012-09-30 13:39:37 +00:00
|
|
|
/* Translators: this is a time format in the style of "14:30 on Wednesday, May 25",
|
|
|
|
shown when you get a chat message in the same year */
|
2011-08-01 22:25:59 +00:00
|
|
|
// xgettext:no-c-format
|
2012-09-30 13:39:37 +00:00
|
|
|
format = _("<b>%H:%M</b> on <b>%A</b>, <b>%B</b> <b>%d</b>");
|
2011-03-28 20:37:53 +00:00
|
|
|
} else {
|
2012-09-30 13:39:37 +00:00
|
|
|
/* Translators: this is a time format in the style of "14:30 on Wednesday, May 25, 2012",
|
|
|
|
shown when you get a chat message in a different year */
|
2011-08-01 22:25:59 +00:00
|
|
|
// xgettext:no-c-format
|
2012-09-30 13:39:37 +00:00
|
|
|
format = _("<b>%H:%M</b> on <b>%A</b>, <b>%B</b> <b>%d</b>, %Y");
|
2011-03-28 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return date.toLocaleFormat(format);
|
|
|
|
},
|
|
|
|
|
2011-03-07 22:10:53 +00:00
|
|
|
appendTimestamp: function() {
|
2010-11-25 14:29:41 +00:00
|
|
|
let lastMessageTime = this._history[0].time;
|
|
|
|
let lastMessageDate = new Date(lastMessageTime * 1000);
|
|
|
|
|
2011-08-24 14:33:44 +00:00
|
|
|
let timeLabel = this._append({ body: this._formatTimestamp(lastMessageDate),
|
|
|
|
group: 'meta',
|
|
|
|
styles: ['chat-meta-message'],
|
2012-09-30 13:39:37 +00:00
|
|
|
childProps: { expand: true, x_fill: false },
|
2011-08-24 14:33:44 +00:00
|
|
|
noTimestamp: true,
|
|
|
|
timestamp: lastMessageTime });
|
2011-05-25 17:18:56 +00:00
|
|
|
|
|
|
|
this._filterMessages();
|
|
|
|
|
2010-11-25 14:29:41 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-28 18:15:02 +00:00
|
|
|
appendAliasChange: function(oldAlias, newAlias) {
|
2011-03-15 13:45:53 +00: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 14:33:44 +00:00
|
|
|
|
2011-09-09 01:37:25 +00:00
|
|
|
let label = this._append({ body: message,
|
2011-08-24 14:33:44 +00:00
|
|
|
group: 'meta',
|
|
|
|
styles: ['chat-meta-message'] });
|
|
|
|
|
2011-03-15 13:45:53 +00:00
|
|
|
this.update(newAlias, null, { customContent: true });
|
2011-05-25 17:18:56 +00:00
|
|
|
|
|
|
|
this._filterMessages();
|
2011-02-28 18:15:02 +00:00
|
|
|
},
|
|
|
|
|
2010-02-22 19:23:36 +00:00
|
|
|
_onEntryActivated: function() {
|
|
|
|
let text = this._responseEntry.get_text();
|
2010-07-21 04:42:37 +00:00
|
|
|
if (text == '')
|
2010-02-22 19:23:36 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-20 08:41:51 +00:00
|
|
|
this._inputHistory.addItem(text);
|
|
|
|
|
2010-11-28 15:14:34 +00:00
|
|
|
// Telepathy sends out the Sent signal for us.
|
|
|
|
// see Source._messageSent
|
2010-02-22 19:23:36 +00:00
|
|
|
this._responseEntry.set_text('');
|
|
|
|
this.source.respond(text);
|
2011-07-07 12:42:07 +00: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 15:21:47 +00:00
|
|
|
}
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|
2011-06-30 12:05:41 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const ApproverSource = new Lang.Class({
|
|
|
|
Name: 'ApproverSource',
|
|
|
|
Extends: MessageTray.Source,
|
2011-06-30 12:05:41 +00:00
|
|
|
|
2011-08-16 14:59:34 +00:00
|
|
|
_init: function(dispatchOp, text, gicon) {
|
|
|
|
this._gicon = gicon;
|
2011-10-08 22:00:32 +00:00
|
|
|
|
|
|
|
this.parent(text);
|
2011-06-30 12:05:41 +00: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 17:56:27 +00:00
|
|
|
this.parent();
|
2011-06-30 12:05:41 +00:00
|
|
|
},
|
|
|
|
|
2012-09-15 06:10:15 +00:00
|
|
|
getIcon: function() {
|
|
|
|
return this._gicon;
|
2011-06-30 12:05:41 +00:00
|
|
|
}
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|
2011-06-30 12:05:41 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const RoomInviteNotification = new Lang.Class({
|
|
|
|
Name: 'RoomInviteNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-06-30 12:05:41 +00:00
|
|
|
|
|
|
|
_init: function(source, dispatchOp, channel, inviter) {
|
2011-11-20 15:12:02 +00: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 12:05:41 +00: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 15:12:02 +00:00
|
|
|
});
|
2011-07-11 11:09:45 +00:00
|
|
|
|
|
|
|
// Audio Video
|
2011-11-20 15:12:02 +00:00
|
|
|
const AudioVideoNotification = new Lang.Class({
|
|
|
|
Name: 'AudioVideoNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-07-11 11:09:45 +00: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 09:38:00 +00:00
|
|
|
this.parent(source, title, null, { customContent: true });
|
2011-07-11 11:09:45 +00:00
|
|
|
this.setResident(true);
|
|
|
|
|
|
|
|
this.addButton('reject', _("Reject"));
|
2011-10-07 23:50:20 +00:00
|
|
|
/* translators: this is a button label (verb), not a noun */
|
2011-07-11 11:09:45 +00: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 15:12:02 +00:00
|
|
|
});
|
2011-08-16 15:07:40 +00:00
|
|
|
|
|
|
|
// File Transfer
|
2011-11-20 15:12:02 +00:00
|
|
|
const FileTransferNotification = new Lang.Class({
|
|
|
|
Name: 'FileTransferNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-16 15:07:40 +00:00
|
|
|
|
|
|
|
_init: function(source, dispatchOp, channel, contact) {
|
2011-11-28 09:38:00 +00:00
|
|
|
this.parent(source,
|
2011-11-20 15:12:02 +00: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 15:07:40 +00: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 15:12:02 +00:00
|
|
|
});
|
2011-08-26 10:27:40 +00:00
|
|
|
|
|
|
|
// Subscription request
|
2011-11-20 15:12:02 +00:00
|
|
|
const SubscriptionRequestNotification = new Lang.Class({
|
|
|
|
Name: 'SubscriptionRequestNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-26 10:27:40 +00:00
|
|
|
|
|
|
|
_init: function(source, contact) {
|
2011-11-28 09:38:00 +00:00
|
|
|
this.parent(source,
|
2011-11-20 15:12:02 +00: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 10:27:40 +00: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_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 15:12:02 +00:00
|
|
|
this.parent();
|
2011-08-26 10:27:40 +00: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 15:12:02 +00:00
|
|
|
});
|
2011-08-28 00:26:25 +00: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 12:36:58 +00:00
|
|
|
= _("This account is already connected to the server");
|
2011-08-28 00:26:25 +00:00
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CONNECTION_REPLACED)]
|
2011-08-30 20:16:28 +00:00
|
|
|
= _("Connection has been replaced by a new connection using the same resource");
|
2011-08-28 00:26:25 +00: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 20:16:28 +00:00
|
|
|
= _("Certificate uses an insecure cipher algorithm or is cryptographically weak");
|
2011-08-28 00:26:25 +00:00
|
|
|
_connectionErrorMessages[Tp.error_get_dbus_name(Tp.Error.CERT_LIMIT_EXCEEDED)]
|
2011-08-30 20:16:28 +00: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 12:05:35 +00:00
|
|
|
_connectionErrorMessages['org.freedesktop.DBus.Error.NoReply']
|
|
|
|
= _("Internal error");
|
2011-08-28 00:26:25 +00:00
|
|
|
|
2011-11-20 15:12:02 +00:00
|
|
|
const AccountNotification = new Lang.Class({
|
|
|
|
Name: 'AccountNotification',
|
|
|
|
Extends: MessageTray.Notification,
|
2011-08-28 00:26:25 +00:00
|
|
|
|
|
|
|
_init: function(source, account, connectionError) {
|
2011-11-20 15:12:02 +00: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-28 00:26:25 +00:00
|
|
|
|
2011-09-14 15:01:48 +00:00
|
|
|
this._label = new St.Label();
|
|
|
|
this.addActor(this._label);
|
|
|
|
this._updateMessage(connectionError);
|
2011-08-28 00:26:25 +00: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.
|
2012-08-16 19:52:24 +00:00
|
|
|
account.reconnect_async(null);
|
2011-08-28 00:26:25 +00:00
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
let cmd = '/usr/bin/empathy-accounts'
|
|
|
|
+ ' --select-account=%s'
|
|
|
|
.format(account.get_path_suffix());
|
2012-08-16 19:52:24 +00:00
|
|
|
let app_info = Gio.app_info_create_from_commandline(cmd, null, 0);
|
2012-08-16 19:54:10 +00:00
|
|
|
app_info.launch([], global.create_app_launch_context());
|
2011-08-28 00:26:25 +00:00
|
|
|
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 15:01:48 +00:00
|
|
|
let status = account.connection_status;
|
|
|
|
if (status == Tp.ConnectionStatus.CONNECTED) {
|
2011-08-28 00:26:25 +00:00
|
|
|
this.destroy();
|
2011-09-14 15:01:48 +00:00
|
|
|
} else if (status == Tp.ConnectionStatus.DISCONNECTED) {
|
|
|
|
this._updateMessage(account.connection_error);
|
|
|
|
}
|
2011-08-28 00:26:25 +00:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2011-09-14 15:01:48 +00:00
|
|
|
_updateMessage: function(connectionError) {
|
|
|
|
let message;
|
|
|
|
if (connectionError in _connectionErrorMessages) {
|
|
|
|
message = _connectionErrorMessages[connectionError];
|
|
|
|
} else {
|
|
|
|
message = _("Unknown reason");
|
|
|
|
}
|
|
|
|
this._label.set_text(message);
|
|
|
|
},
|
|
|
|
|
2011-08-28 00:26:25 +00: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 15:12:02 +00:00
|
|
|
this.parent();
|
2011-08-28 00:26:25 +00:00
|
|
|
}
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|
2012-09-03 01:23:50 +00:00
|
|
|
const Component = TelepathyClient;
|