Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/definition/accessors/IRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IMessageRead } from './IMessageRead';
import { INotifier } from './INotifier';
import { IPersistenceRead } from './IPersistenceRead';
import { IRoomRead } from './IRoomRead';
import { IRoomSubscriptionRead } from './IRoomSubscriptionRead';
import { IUploadRead } from './IUploadRead';
import { IUserRead } from './IUserRead';

Expand All @@ -25,6 +26,9 @@ export interface IRead {
/** Gets the IRoomRead instance. */
getRoomReader(): IRoomRead;

/** Gets the IRoomSubscriptionRead instance. */
getRoomSubscriptionReader(): IRoomSubscriptionRead;

/** Gets the IUserRead instance. */
getUserReader(): IUserRead;

Expand Down
23 changes: 23 additions & 0 deletions src/definition/accessors/IRoomSubscriptionRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IRoomSubscription } from '../subscriptions';

/**
* This accessor provides methods for accessing
* subscriptions in a read-only-fashion.
*/
export interface IRoomSubscriptionRead {
/**
* Gets a list of subscriptions by a room id.
*
* @param roomId the id of the room
* @returns an iterator of subscriptions
*/
getByRoomId(roomId: string): Promise<AsyncIterableIterator<IRoomSubscription>>;

/**
* Gets a list of all the subscriptions for a user by their id.
*
* @param userId the id of the user
* @returns an iterator of subscriptions for the user
*/
getByUserId(userId: string): Promise<AsyncIterableIterator<IRoomSubscription>>;
}
2 changes: 2 additions & 0 deletions src/definition/accessors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { IRead } from './IRead';
import { IRoomBuilder } from './IRoomBuilder';
import { IRoomExtender } from './IRoomExtender';
import { IRoomRead } from './IRoomRead';
import { IRoomSubscriptionRead } from './IRoomSubscriptionRead';
import { IServerSettingRead } from './IServerSettingRead';
import { IServerSettingsModify } from './IServerSettingsModify';
import { ISettingRead } from './ISettingRead';
Expand Down Expand Up @@ -82,6 +83,7 @@ export {
IRoomBuilder,
IRoomExtender,
IRoomRead,
IRoomSubscriptionRead,
IServerSettingRead,
IServerSettingsModify,
ISettingRead,
Expand Down
32 changes: 32 additions & 0 deletions src/definition/subscriptions/IRoomSubscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { IRoom } from '../rooms';
import { IUser } from '../users';

/**
* This interface represents a user's subscription to
* a room and includes information about that user's
* settings and information in relation to the room.
*/
export interface IRoomSubscription {
/** The id of the subscription (maps to `_id`). */
id: string;
/** The room the subscription is for (kinda maps to `rid`). */
room: IRoom;
/** The user the subscription is for (kinda maps to `u`). */
user: IUser;
/** Whether the room the subscription is for is hidden from the UI (maps to `open`). */
isHidden: boolean;
/** Whether the subscription has an alert or notification for the user (maps to `alert`). */
hasAlert: boolean;
/** The actual number to display on the room's list; it is the sum of userMentionsCount and groupMentionsCount (maps to `unread`). */
unreadCount: number;
/** The number of times the user has been mentioned (maps to `userMentions`). */
userMentionsCount: number;
/** The number of times the groups a user is part of has been mentioned (maps to `groupMentions`). */
groupMentionsCount: number;
/** The date when the subscription was created (maps to `ts`). */
createdAt: Date;
/** The date when the subscription was last updated (maps to `_updatedAt`). */
updatedAt?: Date;
/** The last date/time the subscription was seen or marked as read (maps to `ls`). */
lastSeenAt?: Date;
}
1 change: 1 addition & 0 deletions src/definition/subscriptions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { IRoomSubscription } from './IRoomSubscription';
6 changes: 6 additions & 0 deletions src/server/accessors/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IPersistenceRead,
IRead,
IRoomRead,
IRoomSubscriptionRead,
IUploadRead,
IUserRead,
} from '../../definition/accessors';
Expand All @@ -16,6 +17,7 @@ export class Reader implements IRead {
private message: IMessageRead,
private persist: IPersistenceRead,
private room: IRoomRead,
private roomSubscription: IRoomSubscriptionRead,
private user: IUserRead,
private noti: INotifier,
private livechat: ILivechatRead,
Expand All @@ -38,6 +40,10 @@ export class Reader implements IRead {
return this.room;
}

public getRoomSubscriptionReader(): IRoomSubscriptionRead {
return this.roomSubscription;
}

public getUserReader(): IUserRead {
return this.user;
}
Expand Down
16 changes: 16 additions & 0 deletions src/server/accessors/RoomSubscriptionRead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IRoomSubscriptionRead } from '../../definition/accessors';
import { IRoomSubscription } from '../../definition/subscriptions';

import { IRoomSubscriptionBridge } from '../bridges';

export class RoomSubscriptionRead implements IRoomSubscriptionRead {
constructor(private subscriptionBridge: IRoomSubscriptionBridge, private appId: string) { }

public getByRoomId(roomId: string): Promise<AsyncIterableIterator<IRoomSubscription>> {
return this.subscriptionBridge.getByRoomId(roomId, this.appId);
}

public getByUserId(userId: string): Promise<AsyncIterableIterator<IRoomSubscription>> {
return this.subscriptionBridge.getByUserId(userId, this.appId);
}
}
2 changes: 2 additions & 0 deletions src/server/accessors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Reader } from './Reader';
import { RoomBuilder } from './RoomBuilder';
import { RoomExtender } from './RoomExtender';
import { RoomRead } from './RoomRead';
import { RoomSubscriptionRead } from './RoomSubscriptionRead';
import { ServerSettingRead } from './ServerSettingRead';
import { ServerSettingsModify } from './ServerSettingsModify';
import { SettingRead } from './SettingRead';
Expand Down Expand Up @@ -57,6 +58,7 @@ export {
RoomBuilder,
RoomExtender,
RoomRead,
RoomSubscriptionRead,
ServerSettingRead,
ServerSettingsModify,
SettingRead,
Expand Down
2 changes: 2 additions & 0 deletions src/server/bridges/AppBridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ILivechatBridge } from './ILivechatBridge';
import { IMessageBridge } from './IMessageBridge';
import { IPersistenceBridge } from './IPersistenceBridge';
import { IRoomBridge } from './IRoomBridge';
import { IRoomSubscriptionBridge } from './IRoomSubscriptionBridge';
import { IServerSettingBridge } from './IServerSettingBridge';
import { IUiInteractionBridge } from './IUiInteractionBridge';
import { IUploadBridge } from './IUploadBridge';
Expand All @@ -27,6 +28,7 @@ export abstract class AppBridges {
public abstract getPersistenceBridge(): IPersistenceBridge;
public abstract getAppActivationBridge(): IAppActivationBridge;
public abstract getRoomBridge(): IRoomBridge;
public abstract getRoomSubscriptionBridge(): IRoomSubscriptionBridge;
public abstract getInternalBridge(): IInternalBridge;
public abstract getServerSettingBridge(): IServerSettingBridge;
public abstract getUploadBridge(): IUploadBridge;
Expand Down
7 changes: 7 additions & 0 deletions src/server/bridges/IRoomSubscriptionBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IRoomSubscription } from '../../definition/subscriptions';

export interface IRoomSubscriptionBridge {
getByRoomId(roomId: string, appId: string): Promise<AsyncIterableIterator<IRoomSubscription>>;

getByUserId(userId: string, appId: string): Promise<AsyncIterableIterator<IRoomSubscription>>;
}
2 changes: 2 additions & 0 deletions src/server/bridges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ILivechatBridge } from './ILivechatBridge';
import { IMessageBridge } from './IMessageBridge';
import { IPersistenceBridge } from './IPersistenceBridge';
import { IRoomBridge } from './IRoomBridge';
import { IRoomSubscriptionBridge } from './IRoomSubscriptionBridge';
import { IServerSettingBridge } from './IServerSettingBridge';
import { IUiInteractionBridge } from './IUiInteractionBridge';
import { IUploadBridge } from './IUploadBridge';
Expand All @@ -29,6 +30,7 @@ export {
IAppCommandBridge,
IAppApiBridge,
IRoomBridge,
IRoomSubscriptionBridge,
IInternalBridge,
IServerSettingBridge,
IUserBridge,
Expand Down
5 changes: 3 additions & 2 deletions src/server/compiler/AppCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class AppCompiler {
types: ['node'],
// Set this to true if you would like to see the module resolution process
traceResolution: false,
lib: ['lib.esnext.d.ts'],
};

this.libraryFiles = {};
Expand Down Expand Up @@ -122,7 +123,7 @@ export class AppCompiler {
return resolvedModules.push(rs.resolvedModule);
}

console.log(`Failed to resolve module: ${ moduleName }`);
console.warn(`Failed to resolve module: ${ moduleName }`);
}

/**
Expand Down Expand Up @@ -195,7 +196,7 @@ export class AppCompiler {

if (moduleNames.length > resolvedModules.length) {
const failedCount = moduleNames.length - resolvedModules.length;
console.log(`Failed to resolved ${ failedCount } modules for ${ info.name } v${ info.version }!`);
console.warn(`Failed to resolved ${ failedCount } modules for ${ info.name } v${ info.version }!`);
}

return resolvedModules;
Expand Down
4 changes: 3 additions & 1 deletion src/server/managers/AppAccessorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
PersistenceRead,
Reader,
RoomRead,
RoomSubscriptionRead,
ServerSettingRead,
ServerSettingsModify,
SettingRead,
Expand Down Expand Up @@ -128,12 +129,13 @@ export class AppAccessorManager {
const msg = new MessageRead(this.bridges.getMessageBridge(), appId);
const persist = new PersistenceRead(this.bridges.getPersistenceBridge(), appId);
const room = new RoomRead(this.bridges.getRoomBridge(), appId);
const subscr = new RoomSubscriptionRead(this.bridges.getRoomSubscriptionBridge(), appId);
const user = new UserRead(this.bridges.getUserBridge(), appId);
const noti = new Notifier(this.bridges.getUserBridge(), this.bridges.getMessageBridge(), appId);
const livechat = new LivechatRead(this.bridges.getLivechatBridge(), appId);
const upload = new UploadRead(this.bridges.getUploadBridge(), appId);

this.readers.set(appId, new Reader(env, msg, persist, room, user, noti, livechat, upload));
this.readers.set(appId, new Reader(env, msg, persist, room, subscr, user, noti, livechat, upload));
}

return this.readers.get(appId);
Expand Down
9 changes: 6 additions & 3 deletions tests/server/accessors/Reader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Expect, SetupFixture, Test } from 'alsatian';
import { IEnvironmentRead, ILivechatRead, IMessageRead, INotifier, IPersistenceRead, IRoomRead, IUploadRead, IUserRead } from '../../../src/definition/accessors';
import { IEnvironmentRead, ILivechatRead, IMessageRead, INotifier, IPersistenceRead, IRoomRead, IRoomSubscriptionRead, IUploadRead, IUserRead } from '../../../src/definition/accessors';

import { Reader } from '../../../src/server/accessors';

Expand All @@ -8,6 +8,7 @@ export class ReaderAccessorTestFixture {
private msg: IMessageRead;
private pr: IPersistenceRead;
private rm: IRoomRead;
private sb: IRoomSubscriptionRead;
private ur: IUserRead;
private ni: INotifier;
private livechat: ILivechatRead;
Expand All @@ -19,6 +20,7 @@ export class ReaderAccessorTestFixture {
this.msg = {} as IMessageRead;
this.pr = {} as IPersistenceRead;
this.rm = {} as IRoomRead;
this.sb = {} as IRoomSubscriptionRead;
this.ur = {} as IUserRead;
this.ni = {} as INotifier;
this.livechat = {} as ILivechatRead;
Expand All @@ -27,14 +29,15 @@ export class ReaderAccessorTestFixture {

@Test()
public useReader() {
Expect(() => new Reader(this.env, this.msg, this.pr, this.rm, this.ur, this.ni, this.livechat, this.upload)).not.toThrow();
Expect(() => new Reader(this.env, this.msg, this.pr, this.rm, this.sb, this.ur, this.ni, this.livechat, this.upload)).not.toThrow();

const rd = new Reader(this.env, this.msg, this.pr, this.rm, this.ur, this.ni, this.livechat, this.upload);
const rd = new Reader(this.env, this.msg, this.pr, this.rm, this.sb, this.ur, this.ni, this.livechat, this.upload);
Expect(rd.getEnvironmentReader()).toBeDefined();
Expect(rd.getMessageReader()).toBeDefined();
Expect(rd.getNotifier()).toBeDefined();
Expect(rd.getPersistenceReader()).toBeDefined();
Expect(rd.getRoomReader()).toBeDefined();
Expect(rd.getRoomSubscriptionReader()).toBeDefined();
Expect(rd.getUserReader()).toBeDefined();
Expect(rd.getLivechatReader()).toBeDefined();
Expect(rd.getUploadReader()).toBeDefined();
Expand Down
1 change: 1 addition & 0 deletions tests/server/compiler/AppCompiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AppCompilerTestFixture {
emitDecoratorMetadata: true,
experimentalDecorators: true,
traceResolution: false,
lib: ['lib.esnext.d.ts'],
};

Expect((compiler as any).compilerOptions).toEqual(expectedOptions);
Expand Down
8 changes: 8 additions & 0 deletions tests/test-data/bridges/appBridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IMessageBridge,
IPersistenceBridge,
IRoomBridge,
IRoomSubscriptionBridge,
IServerSettingBridge,
IUiInteractionBridge,
IUploadBridge,
Expand All @@ -27,6 +28,7 @@ import { TestsMessageBridge } from './messageBridge';
import { TestsPersisBridge } from './persisBridge';
import { TestsRoomBridge } from './roomBridge';
import { TestsServerSettingBridge } from './serverSettingBridge';
import { TestsSubscriptionBridge } from './subscriptionBridge';
import { TestsUiIntegrationBridge } from './uiIntegrationBridge';
import { TestUploadBridge } from './uploadBridge';
import { TestsUserBridge } from './userBridge';
Expand All @@ -41,6 +43,7 @@ export class TestsAppBridges extends AppBridges {
private readonly msgBridge: TestsMessageBridge;
private readonly persisBridge: TestsPersisBridge;
private readonly roomBridge: TestsRoomBridge;
private readonly subscriptionBridge: TestsSubscriptionBridge;
private readonly internalBridge: TestsInternalBridge;
private readonly userBridge: TestsUserBridge;
private readonly httpBridge: TestsHttpBridge;
Expand All @@ -59,6 +62,7 @@ export class TestsAppBridges extends AppBridges {
this.msgBridge = new TestsMessageBridge();
this.persisBridge = new TestsPersisBridge();
this.roomBridge = new TestsRoomBridge();
this.subscriptionBridge = new TestsSubscriptionBridge();
this.internalBridge = new TestsInternalBridge();
this.userBridge = new TestsUserBridge();
this.httpBridge = new TestsHttpBridge();
Expand Down Expand Up @@ -111,6 +115,10 @@ export class TestsAppBridges extends AppBridges {
return this.roomBridge;
}

public getRoomSubscriptionBridge(): IRoomSubscriptionBridge {
return this.subscriptionBridge;
}

public getInternalBridge(): IInternalBridge {
return this.internalBridge;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/test-data/bridges/subscriptionBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IRoomSubscription } from '../../../src/definition/subscriptions';
import { IRoomSubscriptionBridge } from '../../../src/server/bridges';

export class TestsSubscriptionBridge implements IRoomSubscriptionBridge {
public getByRoomId(roomId: string, appId: string): Promise<AsyncIterableIterator<IRoomSubscription>> {
throw new Error('Method not implemented.');
}

public getByUserId(userId: string, appId: string): Promise<AsyncIterableIterator<IRoomSubscription>> {
throw new Error('Method not implemented.');
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"experimentalDecorators": true,
"moduleResolution": "node",
"types": ["node"],
"lib": ["es2017", "dom"],
"lib": ["es2018", "dom"],
Comment thread
shiqimei marked this conversation as resolved.
"outDir": "."
},
"exclude": [
Expand Down