[polari/wip/carlosg/tracker: 413/445] telepathyClient: Log messages to tracker




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

    telepathyClient: Log messages to tracker

 src/telepathyClient.js | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
---
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index d3529b58..edb8029a 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -603,6 +603,8 @@ class TelepathyClient extends Tp.BaseClient {
                     return;
             }
 
+            channel.connect('message-sent',
+                            this._onMessageSent.bind(this));
             channel.connect('message-received',
                 this._onMessageReceived.bind(this));
             channel.connect('pending-message-removed',
@@ -693,7 +695,34 @@ class TelepathyClient extends Tp.BaseClient {
         this._app.send_notification(this._getIdentifyNotificationID(accountPath), notification);
     }
 
+    _logMessage(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(channel, msg) {
+        this._logMessage(msg, channel);
+    }
+
     _onMessageReceived(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]