[polari/wip/fmuellner/tracker: 51/61] telepathyClient: Log messages to tracker



commit 4117f773d72910795a3564e9cd09452286f18720
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jul 26 21:32:00 2017 +0200

    telepathyClient: Log messages to tracker

 src/telepathyClient.js | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index ccf20d9..b57ba64 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -2,6 +2,7 @@ const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Polari = imports.gi.Polari;
 const Tp = imports.gi.TelepathyGLib;
+const Tracker = imports.gi.Tracker;
 
 const AccountsMonitor = imports.accountsMonitor;
 const Lang = imports.lang;
@@ -496,6 +497,8 @@ var TelepathyClient = new Lang.Class({
                   return;
             }
 
+            channel.connect('message-sent',
+                            Lang.bind(this, this._onMessageSent));
             channel.connect('message-received',
                             Lang.bind(this, this._onMessageReceived));
             channel.connect('pending-message-removed',
@@ -583,7 +586,34 @@ var TelepathyClient = new Lang.Class({
         this._app.send_notification(this._getIdentifyNotificationID(accountPath), notification);
     },
 
+    _logMessage: function(tpMessage, channel) {
+        let connection = Polari.util_get_tracker_connection ();
+
+        let accountId = channel.connection.get_account().get_path_suffix();
+        let isRoom = channel.handle_type == Tp.HandleType.ROOM;
+        let channelName = channel.identifier;
+
+        let message = Polari.Message.new_from_tp_message (tpMessage);
+        let res = message.to_tracker_resource(accountId, channelName, isRoom);
+
+        let nsManager = connection.get_namespace_manager();
+        let sparql = res.print_sparql_update(nsManager, null);
+        connection.update_async(sparql, 0, null, (o, res) => {
+            try {
+                connection.update_finish(res);
+            } catch (e) {
+                log('Failed to log message: ' + e.message);
+            }
+        });
+    },
+
+    _onMessageSent: function(channel, msg) {
+        this._logMessage(msg, channel);
+    },
+
     _onMessageReceived: function(channel, msg) {
+        this._logMessage(msg, channel);
+
         let [id, ] = msg.get_pending_message_id();
         let room = this._roomManager.lookupRoomByChannel(channel);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]