[polari/wip/fmuellner/tracker: 31/38] logger: Add LogWalker for traversing a channel's logs
- From: Gitlab Administrative User <gitlab src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/tracker: 31/38] logger: Add LogWalker for traversing a channel's logs
- Date: Mon, 30 Oct 2017 23:55:48 +0000 (UTC)
commit aa12d2419aa0d46878662d574eb78ca5b90b2815
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Jan 8 16:10:17 2016 +0100
logger: 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/logger.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
---
diff --git a/src/logger.js b/src/logger.js
index 5424cff..4e67088 100644
--- a/src/logger.js
+++ b/src/logger.js
@@ -1,3 +1,4 @@
+const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Polari = imports.gi.Polari;
@@ -129,3 +130,49 @@ var GenericQuery = class {
}
}
};
+
+var LogWalker = class {
+ constructor(room) {
+ this._room = room;
+ this._query = null;
+ }
+
+ getEvents(numEvents, callback) {
+ let returnFunc = r => {
+ callback(r.reverse().map(m => {
+ let { text, sender, isAction, isSelf } = m;
+ let timestamp = new Date(m.time).toLocaleFormat('%s');
+ let dt = GLib.DateTime.new_from_unix_utc(timestamp);
+ return new Polari.Message(text, sender, dt, isAction, isSelf);
+ }));
+ };
+
+ if (!this._query) {
+ this._query = new GenericQuery(numEvents);
+
+ let sparql = `
+ select polari:text(?msg) as ?text
+ polari:nick(?sender) as ?sender
+ polari:time(?msg) as ?time
+ (exists { ?msg a polari:ActionMessage }) as ?isAction
+ (exists { ?sender a polari:SelfContact }) as ?isSelf
+ { ?msg a polari:Message;
+ polari:sender ?sender;
+ polari:channel ?chan .
+ ?chan polari:account ?account;
+ polari:name "${this._room.channel_name}" .
+ ?account polari:id "${this._room.account.get_path_suffix()}"
+ } order by desc(?time) desc(tracker:id(?msg))
+ `
+ this._query.run(sparql, null, returnFunc);
+ } else {
+ this._query.next(numEvents, null, returnFunc);
+ }
+ }
+
+ isEnd() {
+ if (this._query)
+ return this._query.isClosed();
+ return false;
+ }
+};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]