[polari] chatroomManager: Merge (again) with telepathyClient
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] chatroomManager: Merge (again) with telepathyClient
- Date: Thu, 8 Aug 2013 13:10:58 +0000 (UTC)
commit c9fbac5f13b9a73882ec951c7afed1dd7cae0111
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Jul 26 15:26:30 2013 +0200
chatroomManager: Merge (again) with telepathyClient
The idea of the split was to let telepathyClient handle all things
telepathy - this didn't turn out to be a good idea, so merge them
again.
src/Makefile.am | 1 -
src/chatroomManager.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++-
src/mainWindow.js | 3 -
src/telepathyClient.js | 102 ---------------------------------------------
4 files changed, 105 insertions(+), 108 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2fce7de..3f29556 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,7 +38,6 @@ dist_js_DATA = \
main.js \
mainWindow.js \
roomList.js \
- telepathyClient.js \
userList.js \
$(NULL)
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 190ed6a..2846677 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -1,3 +1,7 @@
+const Gio = imports.gi.Gio;
+const Polari = imports.gi.Polari;
+const Tp = imports.gi.TelepathyGLib;
+
const Lang = imports.lang;
const Signals = imports.signals;
@@ -15,16 +19,115 @@ const _ChatroomManager = new Lang.Class({
_init: function() {
this._rooms = {};
this._activeRoom = null;
+
+ 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_capabilities()]);
+ factory.add_channel_features([Tp.Channel.get_feature_quark_group()]);
+
+ this._accountManager.prepare_async(null,
+ Lang.bind(this, this._onPrepared));
+ },
+
+ _onPrepared: function(am, res) {
+ try {
+ am.prepare_finish(res);
+ } catch(e) {
+ let app = Gio.Application.get_default();
+ app.release(); // no point in carrying on
+ }
+
+ this._observer = Tp.SimpleObserver.new_with_am(am, true,
+ 'Polari', true, Lang.bind(this, this._observeChannels));
+
+ this._handler = Tp.SimpleHandler.new_with_am(am, false,
+ false, 'Polari', false, Lang.bind(this, this._handleChannels));
+
+ let filters = [];
+
+ let roomFilter = {};
+ roomFilter[Tp.PROP_CHANNEL_CHANNEL_TYPE] = Tp.IFACE_CHANNEL_TYPE_TEXT;
+ roomFilter[Tp.PROP_CHANNEL_TARGET_HANDLE_TYPE] = Tp.HandleType.ROOM;
+ filters.push(roomFilter);
+
+ let contactFilter = {};
+ contactFilter[Tp.PROP_CHANNEL_CHANNEL_TYPE] = Tp.IFACE_CHANNEL_TYPE_TEXT;
+ contactFilter[Tp.PROP_CHANNEL_TARGET_HANDLE_TYPE] = Tp.HandleType.CONTACT;
+ filters.push(contactFilter);
+
+ filters.forEach(Lang.bind(this,
+ function(f) {
+ this._handler.add_handler_filter(f);
+ this._observer.add_observer_filter(f);
+ }));
+ this._handler.register();
+ this._observer.register();
+ },
+
+ _observeChannels: function(observer, account, conn, channels, op, requests, context) {
+ if (conn.protocol_name != 'irc') {
+ let message = 'Not implementing non-IRC protocols';
+ context.fail(new Tp.Error({ code: Tp.Error.NOT_IMPLEMENTED,
+ message: message }));
+ return;
+ }
+
+ for (let i = 0; i < channels.length; i++) {
+ if (channels[i].get_invalidated())
+ continue;
+
+ // this is an invitation - only add it in handleChannel if accepted
+ if (channels[i].has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP) &&
+ channels[i].group_self_contact != null)
+ continue;
+
+ let room = new Polari.Room({ channel: channels[i] });
+ room.channel.connect('invalidated', Lang.bind(this,
+ function() {
+ this._removeRoom(room);
+ }));
+ this._addRoom(room);
+ }
+ context.accept();
+ },
+
+ _handleChannels: function(handler, account, conn, channels, satisfied, user_time, context) {
+ if (conn.protocol_name != 'irc') {
+ let message = 'Not implementing non-IRC protocols';
+ context.fail(new Tp.Error({ code: Tp.Error.NOT_IMPLEMENTED,
+ message: message }));
+ return;
+ }
+
+ for (let i = 0; i < channels.length; i++) {
+ if (channels[i].get_invalidated())
+ continue;
+
+ let room = this._rooms[channels[i].get_object_path()];
+ if (room)
+ continue; // already added from observer
+
+ room = new Polari.Room({ channel: channels[i] });
+ room.channel.connect('invalidated', Lang.bind(this,
+ function() {
+ this._removeRoom(room);
+ }));
+ this._addRoom(room);
+ channels[i].join_async('', null);
+ }
+ context.accept();
},
- addRoom: function(room) {
+ _addRoom: function(room) {
if (this._rooms[room.id])
return;
this._rooms[room.id] = room;
this.emit('room-added', room);
},
- removeRoom: function(room) {
+ _removeRoom: function(room) {
if (!this._rooms[room.id])
return;
delete this._rooms[room.id];
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 4d559d7..1549d86 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -11,7 +11,6 @@ const JoinDialog = imports.joinDialog;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const RoomList = imports.roomList;
-const TelepathyClient = imports.telepathyClient;
const UserList = imports.userList;
const MAX_NICK_UPDATE_TIME = 5;
@@ -27,8 +26,6 @@ const MainWindow = new Lang.Class({
this.window = builder.get_object('main_window');
this.window.application = app;
- this._tpClient = new TelepathyClient.TelepathyClient(); // should be in app
-
let overlay = builder.get_object('overlay');
overlay.add_overlay(app.notificationQueue.widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]