[polari/wip/fmuellner/tracker: 46/48] logManager: Add LogWalker for traversing a channel's logs
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/tracker: 46/48] logManager: Add LogWalker for traversing a channel's logs
- Date: Mon, 20 Mar 2017 21:33:58 +0000 (UTC)
commit 1de59f38c75fc63512b79bdbae8d70d204396b8a
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Jan 8 16:10:17 2016 +0100
logManager: Add LogWalker for traversing a channel's logs
We still use tp-logger for the history in the chat log. While it works
well enough in that case, it is odd to use two completely different
components for log handling, so add our own tracker-based LogWalker
implementation as a replacement.
src/logManager.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/logManager.js b/src/logManager.js
index ef2472f..6ceaa2f 100644
--- a/src/logManager.js
+++ b/src/logManager.js
@@ -1,6 +1,7 @@
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Tracker = imports.gi.Tracker;
+const Tp = imports.gi.TelepathyGLib;
let _logManager = null;
@@ -141,6 +142,55 @@ const GenericQuery = new Lang.Class({
}
});
+const LogWalker = new Lang.Class({
+ Name: 'LogWalker',
+
+ _init: function(connection, room) {
+ this._connection = connection;
+ this._room = room;
+ this._query = null;
+ },
+
+ getEvents: function(numEvents, callback) {
+ if (!this._query) {
+ this._query = new GenericQuery(this._connection, numEvents);
+
+ let roomFilter;
+ if (this._room.type == Tp.HandleType.ROOM)
+ roomFilter = ' filter (nie:title (?chan) = "%s") ';
+ else
+ roomFilter = '?chan nmo:hasParticipant ?participant .' +
+ '?participant fts:match "%s"';
+
+ let sparql = (
+ 'select nie:plainTextContent(?msg) as ?message ' +
+ ' if (nmo:from(?msg) = nco:default-contact-me,' +
+ ' "%s", nco:nickname(nmo:from(?msg))) as ?sender ' +
+ // FIXME: how do we handle the "real" message type?
+ ' %d as ?messageType ' +
+ ' ?timestamp ' +
+ '{ ?msg a nmo:IMMessage; ' +
+ ' nie:contentCreated ?timestamp; ' +
+ ' nmo:communicationChannel ?chan . ' +
+ // FIXME: filter by account
+ roomFilter +
+ '}'
+ ).format(this._room.account.nickname,
+ Tp.ChannelTextMessageType.NORMAL,
+ this._room.channel_name);
+ this._query.run(sparql, null, r => callback(r.reverse()))
+ } else {
+ this._query.next(numEvents, null, r => callback(r.reverse()));
+ }
+ },
+
+ isEnd: function() {
+ if (this._query)
+ return this._query.isClosed();
+ return false;
+ }
+});
+
const _LogManager = new Lang.Class({
Name: 'LogManager',
@@ -151,5 +201,9 @@ const _LogManager = new Lang.Class({
query: function(sparql, cancellable, callback) {
let query = new GenericQuery(this._connection);
query.run(sparql, cancellable, callback);
+ },
+
+ walkEvents: function(room) {
+ return new LogWalker(this._connection, room);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]