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
|
|
|
|
2013-09-13 08:55:07 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
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;
|
2010-02-02 10:21:47 -05:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2012-09-13 17:42:08 -04:00
|
|
|
const Params = imports.misc.params;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
// See Notification.appendMessage
|
2013-06-22 13:21:32 -04:00
|
|
|
const SCROLLBACK_IMMEDIATE_TIME = 3 * 60; // 3 minutes
|
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;
|
|
|
|
|
2014-02-18 05:14:07 -05:00
|
|
|
const CLOCK_FORMAT_KEY = 'clock-format';
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
const TelepathyClient = new Lang.Class({
|
|
|
|
Name: 'TelepathyClient',
|
2010-02-02 10:21:47 -05:00
|
|
|
|
2012-09-02 21:23:50 -04: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.
|
2012-09-02 21:23:50 -04:00
|
|
|
this._tpClient = new Shell.TpClient({ name: 'GnomeShell',
|
|
|
|
account_manager: this._accountManager,
|
|
|
|
uniquify_name: true });
|
2011-06-23 17:57:48 -04:00
|
|
|
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
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
// Watch subscription requests and connection errors
|
|
|
|
this._subscriptionSource = null;
|
|
|
|
this._accountSource = null;
|
|
|
|
|
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));
|
2012-09-02 21:23:50 -04:00
|
|
|
},
|
2011-06-24 08:29:23 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
enable: function() {
|
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
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
this._accountManagerValidityChangedId = this._accountManager.connect('account-validity-changed',
|
|
|
|
Lang.bind(this, this._accountValidityChanged));
|
2011-08-26 06:27:40 -04:00
|
|
|
|
2012-09-02 21:23:50 -04: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 06:27:40 -04:00
|
|
|
|
2012-09-02 21:23:50 -04:00
|
|
|
disable: function() {
|
|
|
|
this._tpClient.unregister();
|
|
|
|
this._accountManager.disconnect(this._accountManagerValidityChangedId);
|
|
|
|
this._accountManagerValidityChangedId = 0;
|
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-08-14 15:21:10 -04:00
|
|
|
if (channel.get_invalidated())
|
2012-06-05 06:39:30 -04:00
|
|
|
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-08-14 15:21:10 -04:00
|
|
|
if (channel.get_invalidated())
|
2012-06-05 06:39:30 -04:00
|
|
|
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) {
|
2012-08-14 15:21:10 -04:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Not invited to the room' }));
|
2011-06-30 08:05:41 -04:00
|
|
|
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) {
|
2012-08-14 15:21:10 -04:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Not invited to the room' }));
|
2011-06-30 08:05:41 -04:00
|
|
|
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-08-14 15:21:10 -04:00
|
|
|
if (channel.get_invalidated()) {
|
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: 'Channel is invalidated' }));
|
2012-06-05 06:39:30 -04:00
|
|
|
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
|
2012-08-14 15:21:10 -04:00
|
|
|
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
|
|
|
|
message: '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 */
|
2012-10-30 13:55:31 -04:00
|
|
|
let source = this._ensureAppSource();
|
2011-08-26 06:27:40 -04:00
|
|
|
|
|
|
|
let notif = new SubscriptionRequestNotification(source, contact);
|
|
|
|
source.notify(notif);
|
|
|
|
},
|
|
|
|
|
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 */
|
2012-10-30 13:55:31 -04:00
|
|
|
let source = this._ensureAppSource();
|
2011-08-27 20:26:25 -04:00
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2012-10-30 13:55:31 -04:00
|
|
|
_ensureAppSource: function() {
|
|
|
|
if (this._appSource == null) {
|
|
|
|
this._appSource = new MessageTray.Source(_("Chat"), 'empathy');
|
2013-10-13 16:01:56 -04:00
|
|
|
this._appSource.policy = new MessageTray.NotificationApplicationPolicy('empathy');
|
2012-11-03 21:11:08 -04:00
|
|
|
|
2012-10-30 13:55:31 -04:00
|
|
|
Main.messageTray.add(this._appSource);
|
|
|
|
this._appSource.connect('destroy', Lang.bind(this, function () {
|
|
|
|
this._appSource = null;
|
2011-08-27 20:26:25 -04:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2012-10-30 13:55:31 -04:00
|
|
|
return this._appSource;
|
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);
|
2013-10-13 23:20:50 -04:00
|
|
|
this._notification.connect('clicked', Lang.bind(this, this.open));
|
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
|
|
|
},
|
|
|
|
|
2012-09-05 11:32:45 -04: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 12:15:51 -04:00
|
|
|
item.label.set_text(this.isMuted ? _("Unmute") : _("Mute"));
|
2012-09-05 11:32:45 -04:00
|
|
|
}));
|
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
|
|
|
this.setMuted(!this.isMuted);
|
2012-11-30 10:14:50 -05:00
|
|
|
this.emit('done-displaying-content', false);
|
2012-09-05 11:32:45 -04:00
|
|
|
}));
|
|
|
|
rightClickMenu.add(item.actor);
|
|
|
|
return rightClickMenu;
|
|
|
|
},
|
|
|
|
|
2012-11-03 21:11:08 -04:00
|
|
|
_createPolicy: function() {
|
2013-10-13 16:01:56 -04:00
|
|
|
return new MessageTray.NotificationApplicationPolicy('empathy');
|
2012-11-03 21:11:08 -04:00
|
|
|
},
|
|
|
|
|
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-09-15 02:10:15 -04:00
|
|
|
getIcon: function() {
|
2011-02-08 08:05:20 -05:00
|
|
|
let file = this._contact.get_avatar_file();
|
|
|
|
if (file) {
|
2012-09-15 02:10:15 -04:00
|
|
|
return new Gio.FileIcon({ file: file });
|
2011-02-08 08:05:20 -05:00
|
|
|
} else {
|
2012-09-15 02:10:15 -04:00
|
|
|
return new Gio.ThemedIcon({ name: 'avatar-default' });
|
2011-02-08 08:05:20 -05:00
|
|
|
}
|
2011-09-21 16:46:08 -04:00
|
|
|
},
|
|
|
|
|
2012-09-15 02:10:15 -04:00
|
|
|
getSecondaryIcon: function() {
|
2012-09-14 10:33:52 -04:00
|
|
|
let iconName;
|
2012-07-05 13:47:13 -04:00
|
|
|
let presenceType = this._contact.get_presence_type();
|
|
|
|
|
|
|
|
switch (presenceType) {
|
|
|
|
case Tp.ConnectionPresenceType.AVAILABLE:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-available';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.BUSY:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-busy';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.OFFLINE:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-offline';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.HIDDEN:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-invisible';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.AWAY:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-away';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
case Tp.ConnectionPresenceType.EXTENDED_AWAY:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-idle';
|
2012-07-05 13:47:13 -04:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-14 10:33:52 -04:00
|
|
|
iconName = 'user-offline';
|
2012-07-05 13:47:13 -04:00
|
|
|
}
|
2012-09-14 10:33:52 -04:00
|
|
|
return new Gio.ThemedIcon({ name: iconName });
|
2012-07-05 13:47:13 -04:00
|
|
|
},
|
|
|
|
|
2011-09-21 16:46:08 -04:00
|
|
|
_updateAvatarIcon: function() {
|
2012-07-23 00:07:51 -04:00
|
|
|
this.iconUpdated();
|
2012-07-19 09:05:17 -04:00
|
|
|
this._notification.update(this._notification.title, null, { customContent: true });
|
2010-02-02 10:21:47 -05:00
|
|
|
},
|
|
|
|
|
2013-10-13 23:20:50 -04:00
|
|
|
open: function() {
|
|
|
|
if (this._client.is_handling_channel(this._channel)) {
|
|
|
|
// We are handling the channel, try to pass it to Empathy
|
|
|
|
this._client.delegate_channels_async([this._channel],
|
|
|
|
global.get_current_time(),
|
|
|
|
'org.freedesktop.Telepathy.Client.Empathy.Chat', null);
|
|
|
|
} 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
|
|
|
},
|
|
|
|
|
2014-01-20 17:21:14 -05:00
|
|
|
destroy: function(reason) {
|
|
|
|
if (this._destroyed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._destroyed = true;
|
2010-02-02 10:21:47 -05:00
|
|
|
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
|
|
|
|
2014-01-20 17:21:14 -05:00
|
|
|
if (this._timestampTimeoutId)
|
|
|
|
Mainloop.source_remove(this._timestampTimeoutId);
|
|
|
|
|
|
|
|
this.parent(reason);
|
|
|
|
},
|
|
|
|
|
|
|
|
_channelClosed: function() {
|
|
|
|
this.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
|
2010-02-02 10:21:47 -05:00
|
|
|
},
|
|
|
|
|
2012-08-06 11:28:55 -04:00
|
|
|
/* All messages are new messages for Telepathy sources */
|
|
|
|
get count() {
|
|
|
|
return this._pendingMessages.length;
|
|
|
|
},
|
|
|
|
|
2013-02-28 21:25:05 -05:00
|
|
|
get indicatorCount() {
|
|
|
|
return this.count;
|
|
|
|
},
|
|
|
|
|
2012-08-06 11:28:55 -04:00
|
|
|
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));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._notifyTimeoutId, '[gnome-shell] this._notifyTimeout');
|
2011-08-22 10:23:50 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_notifyTimeout: function() {
|
|
|
|
if (this._pendingMessages.length != 0)
|
|
|
|
this.notify();
|
|
|
|
|
|
|
|
this._notifyTimeoutId = 0;
|
|
|
|
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
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-09-15 02:10:15 -04:00
|
|
|
this._notification.update(this._notification.title, null, { customContent: true, secondaryGIcon: this.getSecondaryIcon() });
|
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
|
|
|
},
|
|
|
|
|
|
|
|
_ackMessages: function() {
|
|
|
|
// Don't clear our messages here, tp-glib will send a
|
|
|
|
// 'pending-message-removed' for each one.
|
2012-11-26 16:30:20 -05:00
|
|
|
this._channel.ack_all_pending_messages_async(null);
|
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-09-15 02:10:15 -04:00
|
|
|
this.parent(source, source.title, null, { customContent: true, secondaryGIcon: source.getSecondaryIcon() });
|
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);
|
|
|
|
|
2012-09-05 12:59:50 -04: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 07:56:35 -05:00
|
|
|
this._createScrollArea();
|
2011-08-24 10:33:44 -04:00
|
|
|
this._lastGroup = null;
|
2011-03-09 07:56:35 -05:00
|
|
|
|
2012-10-21 08:11:45 -04:00
|
|
|
// Keep track of the bottom position for the current adjustment and
|
|
|
|
// force a scroll to the bottom if things change while we were at the
|
|
|
|
// bottom
|
|
|
|
this._oldMaxScrollValue = this._scrollArea.vscroll.adjustment.value;
|
2012-11-04 18:06:47 -05:00
|
|
|
this._scrollArea.add_style_class_name('chat-notification-scrollview');
|
2011-03-09 07:56:35 -05:00
|
|
|
this._scrollArea.vscroll.adjustment.connect('changed', Lang.bind(this, function(adjustment) {
|
2012-10-21 08:11:45 -04:00
|
|
|
if (adjustment.value == this._oldMaxScrollValue)
|
2011-03-09 07:56:35 -05:00
|
|
|
this.scrollTo(St.Side.BOTTOM);
|
2012-10-21 08:11:45 -04:00
|
|
|
this._oldMaxScrollValue = Math.max(adjustment.lower, adjustment.upper - adjustment.page_size);
|
2011-03-09 07:56:35 -05:00
|
|
|
}));
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* _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) {
|
|
|
|
this._lastGroup = group;
|
2013-09-13 08:55:07 -04:00
|
|
|
let emptyLine = new St.Label({ style_class: 'chat-empty-line' });
|
|
|
|
this.addActor(emptyLine);
|
2014-07-08 12:15:52 -04:00
|
|
|
this._history.unshift({ actor: emptyLine, time: timestamp,
|
|
|
|
realMessage: false });
|
2011-08-24 10:33:44 -04:00
|
|
|
}
|
2010-11-25 09:29:41 -05:00
|
|
|
|
2014-07-08 12:15:52 -04:00
|
|
|
let lineBox = new St.BoxLayout({ vertical: false });
|
|
|
|
lineBox.add(body, props.childProps);
|
|
|
|
this.addActor(lineBox);
|
|
|
|
this._lastMessageBox = lineBox;
|
2011-08-24 10:33:44 -04:00
|
|
|
|
2012-04-13 13:05:51 -04:00
|
|
|
this.updated();
|
|
|
|
|
2011-08-24 10:33:44 -04:00
|
|
|
let timestamp = props.timestamp;
|
2014-07-08 12:15:52 -04:00
|
|
|
this._history.unshift({ actor: lineBox, time: timestamp,
|
2011-08-24 10:33:44 -04:00
|
|
|
realMessage: group != 'meta' });
|
|
|
|
|
|
|
|
if (!props.noTimestamp) {
|
2014-04-10 13:26:52 -04:00
|
|
|
if (timestamp < currentTime - SCROLLBACK_IMMEDIATE_TIME) {
|
2011-03-07 17:10:53 -05:00
|
|
|
this.appendTimestamp();
|
2014-04-10 13:26:52 -04:00
|
|
|
} else {
|
2011-03-07 17:10:53 -05:00
|
|
|
// 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));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._timestampTimeoutId, '[gnome-shell] this.appendTimestamp');
|
|
|
|
}
|
2011-03-07 17:10:53 -05:00
|
|
|
}
|
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;
|
|
|
|
|
2014-06-24 15:17:09 -04:00
|
|
|
let desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
2014-02-18 05:14:07 -05:00
|
|
|
let clockFormat = desktopSettings.get_string(CLOCK_FORMAT_KEY);
|
2014-04-03 11:16:48 -04:00
|
|
|
let hasAmPm = date.toLocaleFormat('%p') != '';
|
2011-03-28 16:37:53 -04:00
|
|
|
|
2014-04-03 11:16:48 -04:00
|
|
|
if (clockFormat == '24h' || !hasAmPm) {
|
|
|
|
// Show only the time if date is on today
|
|
|
|
if(daysAgo < 1){
|
|
|
|
/* Translators: Time in 24h format */
|
|
|
|
format = _("%H\u2236%M");
|
|
|
|
}
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
|
|
|
else if(daysAgo <2){
|
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 24h format. i.e. "Yesterday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("Yesterday, %H\u2236%M");
|
|
|
|
}
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7) {
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 24h format. i.e. "Monday, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%A, %H\u2236%M");
|
|
|
|
|
|
|
|
} else if (date.getYear() == now.getYear()) {
|
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 24h format.
|
|
|
|
i.e. "May 25, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%B %d, %H\u2236%M");
|
|
|
|
} else {
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 24h format.
|
|
|
|
i.e. "May 25 2012, 14:30" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%B %d %Y, %H\u2236%M");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Show only the time if date is on today
|
|
|
|
if(daysAgo < 1){
|
|
|
|
/* Translators: Time in 24h format */
|
|
|
|
format = _("%l\u2236%M %p");
|
|
|
|
}
|
|
|
|
// Show the word "Yesterday" and time if date is on yesterday
|
|
|
|
else if(daysAgo <2){
|
|
|
|
/* Translators: this is the word "Yesterday" followed by a
|
|
|
|
time string in 12h format. i.e. "Yesterday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("Yesterday, %l\u2236%M %p");
|
|
|
|
}
|
|
|
|
// Show a week day and time if date is in the last week
|
|
|
|
else if (daysAgo < 7) {
|
|
|
|
/* Translators: this is the week day name followed by a time
|
|
|
|
string in 12h format. i.e. "Monday, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%A, %l\u2236%M %p");
|
|
|
|
|
|
|
|
} else if (date.getYear() == now.getYear()) {
|
|
|
|
/* Translators: this is the month name and day number
|
|
|
|
followed by a time string in 12h format.
|
|
|
|
i.e. "May 25, 2:30 pm" */
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%B %d, %l\u2236%M %p");
|
|
|
|
} else {
|
|
|
|
/* Translators: this is the month name, day number, year
|
|
|
|
number followed by a time string in 12h format.
|
|
|
|
i.e. "May 25 2012, 2:30 pm"*/
|
|
|
|
// xgettext:no-c-format
|
|
|
|
format = _("%B %d %Y, %l\u2236%M %p");
|
|
|
|
}
|
2014-02-18 05:14:07 -05:00
|
|
|
}
|
2011-03-28 16:37:53 -04:00
|
|
|
return date.toLocaleFormat(format);
|
|
|
|
},
|
|
|
|
|
2011-03-07 17:10:53 -05:00
|
|
|
appendTimestamp: function() {
|
2013-11-07 22:48:51 -05:00
|
|
|
this._timestampTimeoutId = 0;
|
|
|
|
|
2010-11-25 09:29:41 -05:00
|
|
|
let lastMessageTime = this._history[0].time;
|
|
|
|
let lastMessageDate = new Date(lastMessageTime * 1000);
|
|
|
|
|
2013-09-13 08:55:07 -04:00
|
|
|
let timeLabel = new St.Label({ text: this._formatTimestamp(lastMessageDate),
|
|
|
|
style_class: 'chat-meta-message',
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.END });
|
|
|
|
|
|
|
|
this._lastMessageBox.add_actor(timeLabel);
|
2011-05-25 13:18:56 -04:00
|
|
|
|
|
|
|
this._filterMessages();
|
|
|
|
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2010-11-25 09:29:41 -05:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2011-07-07 08:42:07 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_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));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._composingTimeoutId, '[gnome-shell] this._composingStopTimeout');
|
2011-07-07 08:42:07 -04:00
|
|
|
} 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();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2012-11-03 21:11:08 -04:00
|
|
|
_createPolicy: function() {
|
2013-10-13 16:01:56 -04:00
|
|
|
return new MessageTray.NotificationApplicationPolicy('empathy');
|
2012-11-03 21:11:08 -04:00
|
|
|
},
|
|
|
|
|
2011-06-30 08:05:41 -04:00
|
|
|
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-09-15 02:10:15 -04:00
|
|
|
getIcon: function() {
|
|
|
|
return this._gicon;
|
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()));
|
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("Decline"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE, '', function(src, result) {
|
|
|
|
src.leave_channels_finish(result);
|
|
|
|
});
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
this.addAction(_("Accept"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(), function(src, result) {
|
|
|
|
src.handle_with_time_finish(result);
|
|
|
|
});
|
2011-06-30 08:05:41 -04:00
|
|
|
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);
|
|
|
|
|
2013-08-19 07:07:04 -04:00
|
|
|
this.setUrgency(MessageTray.Urgency.CRITICAL);
|
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("Decline"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE, '', function(src, result) {
|
|
|
|
src.leave_channels_finish(result);
|
|
|
|
});
|
|
|
|
this.destroy();
|
|
|
|
}));
|
2011-10-07 19:50:20 -04:00
|
|
|
/* translators: this is a button label (verb), not a noun */
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("Answer"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(), function(src, result) {
|
|
|
|
src.handle_with_time_finish(result);
|
|
|
|
});
|
2011-07-11 07:09:45 -04:00
|
|
|
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);
|
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("Decline"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.leave_channels_async(Tp.ChannelGroupChangeReason.NONE, '', function(src, result) {
|
|
|
|
src.leave_channels_finish(result);
|
|
|
|
});
|
|
|
|
this.destroy();
|
|
|
|
}));
|
|
|
|
this.addAction(_("Accept"), Lang.bind(this, function() {
|
|
|
|
dispatchOp.handle_with_time_async('', global.get_current_time(), function(src, result) {
|
|
|
|
src.handle_with_time_finish(result);
|
|
|
|
});
|
2011-08-16 11:07:40 -04:00
|
|
|
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();
|
2014-03-23 00:05:53 -04:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
iconBox.child = textureCache.load_uri_async(uri, iconBox._size, iconBox._size, scaleFactor);
|
2011-08-26 06:27:40 -04:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("Decline"), Lang.bind(this, function() {
|
|
|
|
contact.remove_async(function(src, result) {
|
|
|
|
src.remove_finish(result);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
this.addAction(_("Accept"), Lang.bind(this, function() {
|
|
|
|
// Authorize the contact and request to see his status as well
|
|
|
|
contact.authorize_publication_async(function(src, result) {
|
|
|
|
src.authorize_publication_finish(result);
|
|
|
|
});
|
2011-08-26 06:27:40 -04:00
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
contact.request_subscription_async('', function(src, result) {
|
|
|
|
src.request_subscription_finish(result);
|
|
|
|
});
|
2011-08-26 06:27:40 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
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. */
|
2012-10-30 13:55:31 -04:00
|
|
|
_("Unable to connect to %s").format(account.get_display_name()),
|
|
|
|
this._getMessage(connectionError));
|
2011-08-27 20:26:25 -04:00
|
|
|
|
|
|
|
this._account = account;
|
|
|
|
|
2013-10-13 23:06:09 -04:00
|
|
|
this.addAction(_("View account"), Lang.bind(this, function() {
|
|
|
|
let cmd = 'empathy-accounts --select-account=' +
|
|
|
|
account.get_path_suffix();
|
|
|
|
let app_info = Gio.app_info_create_from_commandline(cmd, null, 0);
|
2014-01-19 12:34:32 -05:00
|
|
|
app_info.launch([], global.create_app_launch_context(0, -1));
|
2011-08-27 20:26:25 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
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) {
|
2014-02-09 13:19:36 -05:00
|
|
|
let connectionError = account.connection_error;
|
|
|
|
|
|
|
|
if (connectionError == Tp.error_get_dbus_name(Tp.Error.CANCELLED))
|
|
|
|
this.destroy();
|
|
|
|
else
|
|
|
|
this.update(this.title, this._getMessage(connectionError));
|
2011-09-14 11:01:48 -04:00
|
|
|
}
|
2011-08-27 20:26:25 -04:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2012-10-30 13:55:31 -04:00
|
|
|
_getMessage: function(connectionError) {
|
2011-09-14 11:01:48 -04:00
|
|
|
let message;
|
|
|
|
if (connectionError in _connectionErrorMessages) {
|
|
|
|
message = _connectionErrorMessages[connectionError];
|
|
|
|
} else {
|
|
|
|
message = _("Unknown reason");
|
|
|
|
}
|
2012-10-30 13:55:31 -04:00
|
|
|
return message;
|
2011-09-14 11:01:48 -04:00
|
|
|
},
|
|
|
|
|
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
|
|
|
});
|
2012-09-02 21:23:50 -04:00
|
|
|
const Component = TelepathyClient;
|