feat: complete Ancestor quote bot with production-ready Docker support

This commit is contained in:
unfunny
2026-09-13 14:14:38 -04:00
parent f2016da05a
commit fe7351a7dc
1145 changed files with 30890 additions and 97684 deletions

View File

@@ -1,4 +1,13 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TimelineWindow = exports.TimelineIndex = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _eventTimeline = require("./models/event-timeline");
var _logger = require("./logger");
/*
Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -15,10 +24,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { EventTimeline } from "./models/event-timeline.js";
import { logger } from "./logger.js";
import { RoomEvent } from "./models/room.js";
/**
* @internal
*/
@@ -28,18 +33,15 @@ const DEBUG = false;
* @internal
*/
/* istanbul ignore next */
const debuglog = DEBUG ? logger.log.bind(logger) : function () {};
const debuglog = DEBUG ? _logger.logger.log.bind(_logger.logger) : function () {};
/**
* the number of times we ask the server for more events before giving up
* this is currently higher than it needs to be to workaround lack of a filter
* for excluding thread responses from main timeline pagination which can cause
* giving up incorrectly - https://github.com/matrix-org/matrix-spec-proposals/pull/3874
*
* @internal
*/
const DEFAULT_PAGINATE_LOOP_LIMIT = 10;
export class TimelineWindow {
const DEFAULT_PAGINATE_LOOP_LIMIT = 5;
class TimelineWindow {
/**
* Construct a TimelineWindow.
*
@@ -53,10 +55,6 @@ export class TimelineWindow {
* are received from /sync; you should arrange to call {@link TimelineWindow#paginate}
* on {@link RoomEvent.Timeline} events.
*
* <p>Note that constructing an instance of this class for a room adds a
* listener for RoomEvent.Timeline events which is never removed. In theory
* this should not cause a leak since the EventEmitter uses weak mappings.
*
* @param client - MatrixClient to be used for context/pagination
* requests.
*
@@ -65,18 +63,17 @@ export class TimelineWindow {
* @param opts - Configuration options for this window
*/
constructor(client, timelineSet, opts = {}) {
_defineProperty(this, "windowLimit", void 0);
this.client = client;
this.timelineSet = timelineSet;
(0, _defineProperty2.default)(this, "windowLimit", void 0);
// these will be TimelineIndex objects; they delineate the 'start' and
// 'end' of the window.
//
// start.index is inclusive; end.index is exclusive.
_defineProperty(this, "start", void 0);
_defineProperty(this, "end", void 0);
_defineProperty(this, "eventCount", 0);
this.client = client;
this.timelineSet = timelineSet;
(0, _defineProperty2.default)(this, "start", void 0);
(0, _defineProperty2.default)(this, "end", void 0);
(0, _defineProperty2.default)(this, "eventCount", 0);
this.windowLimit = opts.windowLimit || 1000;
timelineSet.room?.on(RoomEvent.Timeline, this.onTimelineEvent.bind(this));
}
/**
@@ -135,10 +132,12 @@ export class TimelineWindow {
* otherwise.
*/
getTimelineIndex(direction) {
if (direction == EventTimeline.BACKWARDS) {
return this.start ?? null;
} else if (direction == EventTimeline.FORWARDS) {
return this.end ?? null;
if (direction == _eventTimeline.EventTimeline.BACKWARDS) {
var _this$start;
return (_this$start = this.start) !== null && _this$start !== void 0 ? _this$start : null;
} else if (direction == _eventTimeline.EventTimeline.FORWARDS) {
var _this$end;
return (_this$end = this.end) !== null && _this$end !== void 0 ? _this$end : null;
} else {
throw new Error("Invalid direction '" + direction + "'");
}
@@ -160,35 +159,19 @@ export class TimelineWindow {
debuglog("TimelineWindow: no timeline yet");
return false;
}
const count = direction == EventTimeline.BACKWARDS ? tl.retreat(size) : tl.advance(size);
const count = direction == _eventTimeline.EventTimeline.BACKWARDS ? tl.retreat(size) : tl.advance(size);
if (count) {
this.eventCount += count;
debuglog("TimelineWindow: increased cap by " + count + " (now " + this.eventCount + ")");
// remove some events from the other end, if necessary
const excess = this.eventCount - this.windowLimit;
if (excess > 0) {
this.unpaginate(excess, direction != EventTimeline.BACKWARDS);
this.unpaginate(excess, direction != _eventTimeline.EventTimeline.BACKWARDS);
}
return true;
}
return false;
}
onTimelineEvent(_event, _room, _atStart, removed) {
if (removed) {
this.onEventRemoved();
}
}
/**
* If an event was removed, meaning this window is longer than the timeline,
* shorten the window.
*/
onEventRemoved() {
const events = this.getEvents();
if (events.length > 0 && events[events.length - 1] === undefined && this.end) {
this.end.index--;
}
}
/**
* Check if this window can be extended
@@ -209,7 +192,7 @@ export class TimelineWindow {
debuglog("TimelineWindow: no timeline yet");
return false;
}
if (direction == EventTimeline.BACKWARDS) {
if (direction == _eventTimeline.EventTimeline.BACKWARDS) {
if (tl.index > tl.minIndex()) {
return true;
}
@@ -275,7 +258,7 @@ export class TimelineWindow {
}
debuglog("TimelineWindow: starting request");
const prom = this.client.paginateEventTimeline(tl.timeline, {
backwards: direction == EventTimeline.BACKWARDS,
backwards: direction == _eventTimeline.EventTimeline.BACKWARDS,
limit: size
}).finally(function () {
tl.pendingPaginate = undefined;
@@ -347,7 +330,9 @@ export class TimelineWindow {
// iterate through each timeline between this.start and this.end
// (inclusive).
let timeline = this.start.timeline;
// eslint-disable-next-line no-constant-condition
while (timeline) {
var _this$end2, _this$end3;
const events = timeline.getEvents();
// For the first timeline in the chain, we want to start at
@@ -363,7 +348,7 @@ export class TimelineWindow {
if (timeline === this.start.timeline) {
startIndex = this.start.index + timeline.getBaseIndex();
}
if (timeline === this.end?.timeline) {
if (timeline === ((_this$end2 = this.end) === null || _this$end2 === void 0 ? void 0 : _this$end2.timeline)) {
endIndex = this.end.index + timeline.getBaseIndex();
}
for (let i = startIndex; i < endIndex; i++) {
@@ -371,10 +356,10 @@ export class TimelineWindow {
}
// if we're not done, iterate to the next timeline.
if (timeline === this.end?.timeline) {
if (timeline === ((_this$end3 = this.end) === null || _this$end3 === void 0 ? void 0 : _this$end3.timeline)) {
break;
} else {
timeline = timeline.getNeighbouringTimeline(EventTimeline.FORWARDS);
timeline = timeline.getNeighbouringTimeline(_eventTimeline.EventTimeline.FORWARDS);
}
}
return result;
@@ -385,12 +370,13 @@ export class TimelineWindow {
* A thing which contains a timeline reference, and an index into it.
* @internal
*/
export class TimelineIndex {
exports.TimelineWindow = TimelineWindow;
class TimelineIndex {
// index: the indexes are relative to BaseIndex, so could well be negative.
constructor(timeline, index) {
_defineProperty(this, "pendingPaginate", void 0);
this.timeline = timeline;
this.index = index;
(0, _defineProperty2.default)(this, "pendingPaginate", void 0);
}
/**
@@ -451,7 +437,7 @@ export class TimelineIndex {
// the index is already at the start/end of the current timeline.
//
// next see if there is a neighbouring timeline to switch to.
const neighbour = this.timeline.getNeighbouringTimeline(delta < 0 ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS);
const neighbour = this.timeline.getNeighbouringTimeline(delta < 0 ? _eventTimeline.EventTimeline.BACKWARDS : _eventTimeline.EventTimeline.FORWARDS);
if (neighbour) {
this.timeline = neighbour;
if (delta < 0) {
@@ -477,4 +463,5 @@ export class TimelineIndex {
return this.advance(delta * -1) * -1;
}
}
exports.TimelineIndex = TimelineIndex;
//# sourceMappingURL=timeline-window.js.map