TelepathyClient: stop handling room invitations

Let empathy deal with these

https://bugzilla.gnome.org/show_bug.cgi?id=745503
This commit is contained in:
Giovanni Campagna 2015-03-03 00:27:48 -08:00
parent fab25e18da
commit 707cc9e315
2 changed files with 16 additions and 118 deletions

View File

@ -208,33 +208,6 @@ const TelepathyClient = new Lang.Class({
} }
}, },
_displayRoomInvitation: function(conn, channel, dispatchOp, context) {
// We can only approve the rooms if we have been invited to it
let selfContact = channel.group_get_self_contact();
if (selfContact == null) {
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
message: 'Not invited to the room' }));
return;
}
let [invited, inviter, reason, msg] = channel.group_get_local_pending_contact_info(selfContact);
if (!invited) {
context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
message: 'Not invited to the room' }));
return;
}
// FIXME: We don't have a 'chat room' icon (bgo #653737) use
// system-users for now as Empathy does.
let source = new ApproverSource(dispatchOp, _("Invitation"),
Gio.icon_new_for_string('system-users'));
Main.messageTray.add(source);
let notif = new RoomInviteNotification(source, dispatchOp, channel, inviter);
source.notify(notif);
context.accept();
},
_approveChannels: function(approver, account, conn, channels, _approveChannels: function(approver, account, conn, channels,
dispatchOp, context) { dispatchOp, context) {
let channel = channels[0]; let channel = channels[0];
@ -256,21 +229,23 @@ const TelepathyClient = new Lang.Class({
_approveTextChannel: function(account, conn, channel, dispatchOp, context) { _approveTextChannel: function(account, conn, channel, dispatchOp, context) {
let [targetHandle, targetHandleType] = channel.get_handle(); let [targetHandle, targetHandleType] = channel.get_handle();
if (targetHandleType == Tp.HandleType.CONTACT) { if (targetHandleType != Tp.HandleType.CONTACT) {
// Approve private text channels right away as we are going to handle it context.fail(new Tp.Error({ code: Tp.Error.INVALID_ARGUMENT,
dispatchOp.claim_with_async(this._tpClient, message: 'Unsupported handle type' }));
Lang.bind(this, function(dispatchOp, result) { return;
try {
dispatchOp.claim_with_finish(result);
this._handlingChannels(account, conn, [channel], false);
} catch (err) {
throw new Error('Failed to Claim channel: ' + err);
}}));
context.accept();
} else {
this._displayRoomInvitation(conn, channel, dispatchOp, context);
} }
// 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);
this._handlingChannels(account, conn, [channel], false);
} catch (err) {
log('Failed to Claim channel: ' + err);
}
}));
context.accept();
}, },
_delegatedChannelsCb: function(client, channels) { _delegatedChannelsCb: function(client, channels) {
@ -937,72 +912,4 @@ const ChatNotification = new Lang.Class({
} }
}); });
const ApproverSource = new Lang.Class({
Name: 'ApproverSource',
Extends: MessageTray.Source,
_init: function(dispatchOp, text, gicon) {
this._gicon = gicon;
this.parent(text);
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();
}));
},
_createPolicy: function() {
return new MessageTray.NotificationApplicationPolicy('empathy');
},
destroy: function() {
if (this._invalidId != 0) {
this._dispatchOp.disconnect(this._invalidId);
this._invalidId = 0;
}
this.parent();
},
getIcon: function() {
return this._gicon;
}
});
const RoomInviteNotification = new Lang.Class({
Name: 'RoomInviteNotification',
Extends: MessageTray.Notification,
_init: function(source, dispatchOp, channel, inviter) {
this.parent(source,
/* translators: argument is a room name like
* room@jabber.org for example. */
_("Invitation to %s").format(channel.get_identifier()),
/* 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. */
_("%s is inviting you to join %s").format(inviter.get_alias(), channel.get_identifier()));
this.setResident(true);
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);
});
this.destroy();
}));
}
});
const Component = TelepathyClient; const Component = TelepathyClient;

View File

@ -103,15 +103,6 @@ shell_tp_client_init (ShellTpClient *self)
/* Approver */ /* Approver */
tp_base_client_add_approver_filter (TP_BASE_CLIENT (self), filter); tp_base_client_add_approver_filter (TP_BASE_CLIENT (self), filter);
/* Approve room invitations. We don't handle or observe room channels so
* just register this filter for the approver. */
tp_base_client_take_approver_filter (TP_BASE_CLIENT (self), tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_IFACE_CHANNEL_TYPE_TEXT,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
TP_HANDLE_TYPE_ROOM,
NULL));
/* Handler */ /* Handler */
tp_base_client_add_handler_filter (TP_BASE_CLIENT (self), filter); tp_base_client_add_handler_filter (TP_BASE_CLIENT (self), filter);