Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally make users wait to join bridged rooms #1645

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
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);
jesopo marked this conversation as resolved.
Show resolved Hide resolved
// 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>;
jesopo marked this conversation as resolved.
Show resolved Hide resolved

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