Skip to content
29 changes: 29 additions & 0 deletions src/bridge/MatrixHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,35 @@ export class MatrixHandler {
}
// get the virtual IRC user for this user
promises.push((async () => {
const entry = await this.ircBridge.getStore().getRoom(event.room_id, room.server.domain, room.channel);
// is this a portal room?
const delayTime = ["alias", "join"].includes(
(entry?.data?.origin as string|null) ?? "unknown"
//TODO: pull these two numbers from the config file
) ? 3600 : 0;

if (delayTime > 0) {
let remaining = delayTime;
const firstSeen = await this.ircBridge.getStore().getAccountFirstSeen(user.getId());
if (firstSeen === null) {
await this.ircBridge.getStore().setAccountFirstSeen(user.getId(), new Date());
} else {
remaining = Math.max(0, ((firstSeen.getTime() / 1000) + delayTime) - (new Date().getTime() / 1000));
}

if (remaining > 0) {
await this.membershipQueue.leave(
event.room_id,
user.getId(),
req,
true,
`Please wait ${remaining} seconds`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to let the user know why they are waiting :). Either a message to their admin room, or a link to a page.

this.ircBridge.appServiceUserId,
);
return;
}
}

let bridgedClient: BridgedClient|null = null;
try {
bridgedClient = await this.ircBridge.getBridgedClient(
Expand Down
4 changes: 4 additions & 0 deletions src/datastore/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@ export interface DataStore {

getRoomCount(): Promise<number>;

getAccountFirstSeen(userId: string): Promise<Date|null>;

setAccountFirstSeen(userId: string, when: Date): Promise<void>;

destroy(): Promise<void>;
}
9 changes: 9 additions & 0 deletions src/datastore/NedbDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,15 @@ export class NeDBDataStore implements DataStore {
log.debug("Finished migrating rooms in database");
}

//TODO
public async getAccountFirstSeen(userId: string): Promise<Date|null> {
return null;
}

//TODO
public async setAccountFirstSeen(userId: string, when: Date): Promise<void> {
}

public async destroy() {
// This will no-op
}
Expand Down
9 changes: 9 additions & 0 deletions src/datastore/postgres/PgDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,15 @@ export class PgDataStore implements DataStore {
return res.rows[0];
}

//TODO
public async getAccountFirstSeen(userId: string): Promise<Date|null> {
return null;
}

//TODO
public async setAccountFirstSeen(userId: string, when: Date): Promise<void> {
}

public async destroy() {
log.info("Destroy called");
if (this.hasEnded) {
Expand Down