first commit

This commit is contained in:
Myk
2025-07-31 23:47:20 +03:00
commit 2186b278a0
5149 changed files with 537218 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { IJoinRoomStrategy } from "./JoinRoomStrategy";
import { Appservice } from "../appservice/Appservice";
/**
* A join strategy for application services that proxies joins to an underlying join
* strategy while also trying to use the appservice's bot user to invite the underlying
* user if needed.
* @category Join strategies
*/
export declare class AppserviceJoinRoomStrategy implements IJoinRoomStrategy {
private underlyingStrategy;
private appservice;
constructor(underlyingStrategy: IJoinRoomStrategy, appservice: Appservice);
joinRoom(roomIdOrAlias: string, userId: string, apiCall: (targetRoomIdOrAlias: string) => Promise<string>): Promise<string>;
}

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppserviceJoinRoomStrategy = void 0;
/**
* A join strategy for application services that proxies joins to an underlying join
* strategy while also trying to use the appservice's bot user to invite the underlying
* user if needed.
* @category Join strategies
*/
class AppserviceJoinRoomStrategy {
underlyingStrategy;
appservice;
constructor(underlyingStrategy, appservice) {
this.underlyingStrategy = underlyingStrategy;
this.appservice = appservice;
}
async joinRoom(roomIdOrAlias, userId, apiCall) {
try {
// First just try joining via the apiCall
return await apiCall(roomIdOrAlias);
}
catch (err) {
// If the user being joined is *not* the bridge bot, try and get the bridge bot to
// join them to the room.
if (userId !== this.appservice.botUserId) {
const client = this.appservice.botIntent.underlyingClient;
const roomId = await client.resolveRoom(roomIdOrAlias);
try {
// First start with having the bridge bot invite the user to the room
await client.inviteUser(userId, roomId);
}
catch (inviteErr) {
// The invite failed - use the underlying join strategy to join the room, just in case.
// If there's no join strategy, we want to fall through to an error.
if (this.underlyingStrategy)
return this.underlyingStrategy.joinRoom(roomId, userId, apiCall);
throw inviteErr;
}
// The invite succeeded - use the underlying join strategy to join the room or just call use
// the apiCall if no strategy exists. We are expecting success.
if (this.underlyingStrategy)
return this.underlyingStrategy.joinRoom(roomId, userId, apiCall);
else
return apiCall(roomId);
}
else if (this.underlyingStrategy) {
// If the user being joined *is* the bridge bot, try and use the join strategy to join.
return this.underlyingStrategy.joinRoom(roomIdOrAlias, userId, apiCall);
}
// Finally, if all else fails, throw.
throw err;
}
}
}
exports.AppserviceJoinRoomStrategy = AppserviceJoinRoomStrategy;
//# sourceMappingURL=AppserviceJoinRoomStrategy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AppserviceJoinRoomStrategy.js","sourceRoot":"","sources":["../../src/strategies/AppserviceJoinRoomStrategy.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACH,MAAa,0BAA0B;IACf;IAA+C;IAAnE,YAAoB,kBAAqC,EAAU,UAAsB;QAArE,uBAAkB,GAAlB,kBAAkB,CAAmB;QAAU,eAAU,GAAV,UAAU,CAAY;IACzF,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,aAAqB,EAAE,MAAc,EAAE,OAAyD;QAClH,IAAI;YACA,yCAAyC;YACzC,OAAO,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;SACvC;QAAC,OAAO,GAAG,EAAE;YACV,kFAAkF;YAClF,yBAAyB;YACzB,IAAI,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;gBACtC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC;gBAC1D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;gBACvD,IAAI;oBACA,qEAAqE;oBACrE,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;iBAC3C;gBAAC,OAAO,SAAS,EAAE;oBAChB,uFAAuF;oBACvF,oEAAoE;oBACpE,IAAI,IAAI,CAAC,kBAAkB;wBAAE,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;oBAC9F,MAAM,SAAS,CAAC;iBACnB;gBAED,4FAA4F;gBAC5F,+DAA+D;gBAC/D,IAAI,IAAI,CAAC,kBAAkB;oBAAE,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;;oBACzF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;aAC/B;iBAAM,IAAI,IAAI,CAAC,kBAAkB,EAAE;gBAChC,uFAAuF;gBACvF,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;aAC3E;YAED,qCAAqC;YACrC,MAAM,GAAG,CAAC;SACb;IACL,CAAC;CACJ;AArCD,gEAqCC"}

View File

@@ -0,0 +1,11 @@
export interface IJoinRoomStrategy {
joinRoom(roomIdOrAlias: string, userId: string, apiCall: (targetRoomIdOrAlias: string) => Promise<string>): Promise<string>;
}
/**
* A join strategy that keeps trying to join the room on a set interval.
* @category Join strategies
*/
export declare class SimpleRetryJoinStrategy implements IJoinRoomStrategy {
private schedule;
joinRoom(roomIdOrAlias: string, userId: string, apiCall: (targetRoomIdOrAlias: string) => Promise<string>): Promise<string>;
}

View File

@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleRetryJoinStrategy = void 0;
const __1 = require("..");
/**
* A join strategy that keeps trying to join the room on a set interval.
* @category Join strategies
*/
class SimpleRetryJoinStrategy {
// Note: The schedule must not have duplicate values to avoid problems in positioning.
schedule = [
0,
1000,
30 * 1000,
5 * 60 * 1000,
15 * 60 * 1000, // 15 minutes
];
joinRoom(roomIdOrAlias, userId, apiCall) {
let currentSchedule = this.schedule[0];
const doJoin = () => waitPromise(currentSchedule).then(() => apiCall(roomIdOrAlias));
const errorHandler = err => {
__1.LogService.error("SimpleRetryJoinStrategy", (0, __1.extractRequestError)(err));
const idx = this.schedule.indexOf(currentSchedule);
if (idx === this.schedule.length - 1) {
__1.LogService.warn("SimpleRetryJoinStrategy", "Failed to join room " + roomIdOrAlias);
return Promise.reject(err);
}
else {
currentSchedule = this.schedule[idx + 1];
return doJoin().catch(errorHandler);
}
};
return doJoin().catch(errorHandler);
}
}
exports.SimpleRetryJoinStrategy = SimpleRetryJoinStrategy;
function waitPromise(interval) {
return new Promise((resolve, reject) => {
setTimeout(resolve, interval);
});
}
//# sourceMappingURL=JoinRoomStrategy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JoinRoomStrategy.js","sourceRoot":"","sources":["../../src/strategies/JoinRoomStrategy.ts"],"names":[],"mappings":";;;AAAA,0BAAqD;AAMrD;;;GAGG;AACH,MAAa,uBAAuB;IAChC,sFAAsF;IAC9E,QAAQ,GAAG;QACf,CAAC;QACD,IAAI;QACJ,EAAE,GAAG,IAAI;QACT,CAAC,GAAG,EAAE,GAAG,IAAI;QACb,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;KAChC,CAAC;IAEK,QAAQ,CAAC,aAAqB,EAAE,MAAc,EAAE,OAAyD;QAC5G,IAAI,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAEvC,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACrF,MAAM,YAAY,GAAG,GAAG,CAAC,EAAE;YACvB,cAAU,CAAC,KAAK,CAAC,yBAAyB,EAAE,IAAA,uBAAmB,EAAC,GAAG,CAAC,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YACnD,IAAI,GAAG,KAAK,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBAClC,cAAU,CAAC,IAAI,CAAC,yBAAyB,EAAE,sBAAsB,GAAG,aAAa,CAAC,CAAC;gBACnF,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC9B;iBAAM;gBACH,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;gBACzC,OAAO,MAAM,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;aACvC;QACL,CAAC,CAAC;QAEF,OAAO,MAAM,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;CACJ;AA5BD,0DA4BC;AAED,SAAS,WAAW,CAAC,QAAgB;IACjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACP,CAAC"}