feat: complete Ancestor quote bot with production-ready Docker support
This commit is contained in:
34
node_modules/matrix-js-sdk/lib/receipt-accumulator.js
generated
vendored
34
node_modules/matrix-js-sdk/lib/receipt-accumulator.js
generated
vendored
@@ -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.ReceiptAccumulator = void 0;
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _event = require("./@types/event");
|
||||
var _utils = require("./utils");
|
||||
/*
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
@@ -15,8 +24,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { EventType } from "./@types/event.js";
|
||||
import { isSupportedReceiptType, MapWithDefault, recursiveMapToObject } from "./utils.js";
|
||||
/**
|
||||
* Summarises the read receipts within a room. Used by the sync accumulator.
|
||||
*
|
||||
@@ -28,12 +35,12 @@ import { isSupportedReceiptType, MapWithDefault, recursiveMapToObject } from "./
|
||||
* returned event contains the most recently received unthreaded receipt, and
|
||||
* the most recently received receipt in each thread.
|
||||
*/
|
||||
export class ReceiptAccumulator {
|
||||
class ReceiptAccumulator {
|
||||
constructor() {
|
||||
/** user_id -\> most-recently-received unthreaded receipt */
|
||||
_defineProperty(this, "unthreadedReadReceipts", new Map());
|
||||
(0, _defineProperty2.default)(this, "unthreadedReadReceipts", new Map());
|
||||
/** thread_id -\> user_id -\> most-recently-received receipt for this thread */
|
||||
_defineProperty(this, "threadedReadReceipts", new MapWithDefault(() => new Map()));
|
||||
(0, _defineProperty2.default)(this, "threadedReadReceipts", new _utils.MapWithDefault(() => new Map()));
|
||||
}
|
||||
/**
|
||||
* Provide an unthreaded receipt for this user. Overwrites any other
|
||||
@@ -54,7 +61,6 @@ export class ReceiptAccumulator {
|
||||
/**
|
||||
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
||||
* most recently-received unthreaded receipts for each user.
|
||||
* @yields pairs of [userId, AccumulatedReceipt]
|
||||
*/
|
||||
allUnthreaded() {
|
||||
return this.unthreadedReadReceipts.entries();
|
||||
@@ -64,7 +70,6 @@ export class ReceiptAccumulator {
|
||||
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
||||
* most recently-received threaded receipts for each user, in all
|
||||
* threads.
|
||||
* @yields pairs of [userId, AccumulatedReceipt]
|
||||
*/
|
||||
*allThreaded() {
|
||||
for (const receiptsForThread of this.threadedReadReceipts.values()) {
|
||||
@@ -79,8 +84,8 @@ export class ReceiptAccumulator {
|
||||
* relevant ones to be returned later from buildAccumulatedReceiptEvent().
|
||||
*/
|
||||
consumeEphemeralEvents(events) {
|
||||
events?.forEach(e => {
|
||||
if (e.type !== EventType.Receipt || !e.content) {
|
||||
events === null || events === void 0 ? void 0 : events.forEach(e => {
|
||||
if (e.type !== _event.EventType.Receipt || !e.content) {
|
||||
// This means we'll drop unknown ephemeral events but that
|
||||
// seems okay.
|
||||
return;
|
||||
@@ -98,7 +103,7 @@ export class ReceiptAccumulator {
|
||||
// getJSON() is called.
|
||||
Object.keys(e.content).forEach(eventId => {
|
||||
Object.entries(e.content[eventId]).forEach(([key, value]) => {
|
||||
if (!isSupportedReceiptType(key)) return;
|
||||
if (!(0, _utils.isSupportedReceiptType)(key)) return;
|
||||
for (const userId of Object.keys(value)) {
|
||||
const data = e.content[eventId][key][userId];
|
||||
const receipt = {
|
||||
@@ -145,21 +150,22 @@ export class ReceiptAccumulator {
|
||||
*/
|
||||
buildAccumulatedReceiptEvent(roomId) {
|
||||
const receiptEvent = {
|
||||
type: EventType.Receipt,
|
||||
type: _event.EventType.Receipt,
|
||||
room_id: roomId,
|
||||
content: {
|
||||
// $event_id: { "m.read": { $user_id: $json } }
|
||||
}
|
||||
};
|
||||
const receiptEventContent = new MapWithDefault(() => new MapWithDefault(() => new Map()));
|
||||
const receiptEventContent = new _utils.MapWithDefault(() => new _utils.MapWithDefault(() => new Map()));
|
||||
for (const [userId, receiptData] of this.allUnthreaded()) {
|
||||
receiptEventContent.getOrCreate(receiptData.eventId).getOrCreate(receiptData.type).set(userId, receiptData.data);
|
||||
}
|
||||
for (const [userId, receiptData] of this.allThreaded()) {
|
||||
receiptEventContent.getOrCreate(receiptData.eventId).getOrCreate(receiptData.type).set(userId, receiptData.data);
|
||||
}
|
||||
receiptEvent.content = recursiveMapToObject(receiptEventContent);
|
||||
receiptEvent.content = (0, _utils.recursiveMapToObject)(receiptEventContent);
|
||||
return receiptEventContent.size > 0 ? receiptEvent : null;
|
||||
}
|
||||
}
|
||||
exports.ReceiptAccumulator = ReceiptAccumulator;
|
||||
//# sourceMappingURL=receipt-accumulator.js.map
|
||||
Reference in New Issue
Block a user