File tree Expand file tree Collapse file tree
apps/meteor/app/apps/server/bridges
deno-runtime/lib/accessors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @rocket.chat/apps-engine ' : minor
3+ ' @rocket.chat/meteor ' : minor
4+ ---
5+
6+ Adds an experimental API to the apps-engine that retrieves the ids of rooms the user is a member of
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { AppContactBridge } from './contact';
88import { AppDetailChangesBridge } from './details' ;
99import { AppEmailBridge } from './email' ;
1010import { AppEnvironmentalVariableBridge } from './environmental' ;
11+ import { AppExperimentalBridge } from './experimental' ;
1112import { AppHttpBridge } from './http' ;
1213import { AppInternalBridge } from './internal' ;
1314import { AppInternalFederationBridge } from './internalFederation' ;
@@ -59,6 +60,7 @@ export class RealAppBridges extends AppBridges {
5960 this . _emailBridge = new AppEmailBridge ( orch ) ;
6061 this . _contactBridge = new AppContactBridge ( orch ) ;
6162 this . _outboundMessageBridge = new OutboundCommunicationBridge ( orch ) ;
63+ this . _experimentalBridge = new AppExperimentalBridge ( orch ) ;
6264 }
6365
6466 getCommandBridge ( ) {
@@ -168,4 +170,8 @@ export class RealAppBridges extends AppBridges {
168170 getContactBridge ( ) {
169171 return this . _contactBridge ;
170172 }
173+
174+ getExperimentalBridge ( ) {
175+ return this . _experimentalBridge ;
176+ }
171177}
Original file line number Diff line number Diff line change 1+ import type { IAppServerOrchestrator } from '@rocket.chat/apps' ;
2+ import { ExperimentalBridge } from '@rocket.chat/apps-engine/server/bridges' ;
3+ import { Subscriptions } from '@rocket.chat/models' ;
4+
5+ export class AppExperimentalBridge extends ExperimentalBridge {
6+ constructor ( private readonly orch : IAppServerOrchestrator ) {
7+ super ( ) ;
8+ }
9+
10+ protected async getUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] | undefined > {
11+ this . orch . debugLog ( `The App ${ appId } is getting the room ids for the user: "${ userId } "` ) ;
12+
13+ const subscriptions = await Subscriptions . findByUserId ( userId , { projection : { rid : 1 } } ) . toArray ( ) ;
14+
15+ return subscriptions . map ( ( subscription ) => subscription . rid ) ;
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ export class AppAccessors {
253253 getThreadReader : ( ) => this . proxify ( 'getReader:getThreadReader' ) ,
254254 getRoleReader : ( ) => this . proxify ( 'getReader:getRoleReader' ) ,
255255 getContactReader : ( ) => this . proxify ( 'getReader:getContactReader' ) ,
256+ getExperimentalReader : ( ) => this . proxify ( 'getReader:getExperimentalReader' ) ,
256257 } ;
257258 }
258259
Original file line number Diff line number Diff line change 1+ /**
2+ * @description
3+ * Experimental bridge for experimental features.
4+ * Methods in this class are not guaranteed to be stable between updates as the
5+ * team evaluates the proper signature, underlying implementation and performance
6+ * impact of candidates for future APIs
7+ */
8+ export interface IExperimentalRead {
9+ /**
10+ * Fetches the IDs of the rooms that the user is a member of.
11+ *
12+ * @returns an array of room ids or undefined if the app doesn't have the proper permission
13+ * @experimental
14+ */
15+ getUserRoomIds ( userId : string ) : Promise < string [ ] | undefined > ;
16+ }
Original file line number Diff line number Diff line change 11import type { ICloudWorkspaceRead } from './ICloudWorkspaceRead' ;
22import type { IContactRead } from './IContactRead' ;
33import type { IEnvironmentRead } from './IEnvironmentRead' ;
4+ import type { IExperimentalRead } from './IExperimentalRead' ;
45import type { ILivechatRead } from './ILivechatRead' ;
56import type { IMessageRead } from './IMessageRead' ;
67import type { INotifier } from './INotifier' ;
@@ -51,4 +52,6 @@ export interface IRead {
5152
5253 getRoleReader ( ) : IRoleRead ;
5354 getContactReader ( ) : IContactRead ;
55+
56+ getExperimentalReader ( ) : IExperimentalRead ;
5457}
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export * from './IEnvironmentalVariableRead';
1111export * from './IEnvironmentRead' ;
1212export * from './IEnvironmentWrite' ;
1313export * from './IExternalComponentsExtend' ;
14+ export * from './IExperimentalRead' ;
1415export * from './IHttp' ;
1516export * from './ILivechatCreator' ;
1617export * from './ILivechatMessageBuilder' ;
Original file line number Diff line number Diff line change 1+ import type { IExperimentalRead } from '../../definition/accessors' ;
2+ import type { ExperimentalBridge } from '../bridges' ;
3+
4+ export class ExperimentalRead implements IExperimentalRead {
5+ constructor (
6+ private experimentalBridge : ExperimentalBridge ,
7+ private appId : string ,
8+ ) { }
9+
10+ public async getUserRoomIds ( userId : string ) : Promise < string [ ] | undefined > {
11+ return this . experimentalBridge . doGetUserRoomIds ( userId , this . appId ) ;
12+ }
13+ }
Original file line number Diff line number Diff line change 11import type {
22 ICloudWorkspaceRead ,
33 IEnvironmentRead ,
4+ IExperimentalRead ,
45 ILivechatRead ,
56 IMessageRead ,
67 INotifier ,
@@ -29,10 +30,10 @@ export class Reader implements IRead {
2930 private cloud : ICloudWorkspaceRead ,
3031 private videoConf : IVideoConferenceRead ,
3132 private contactRead : IContactRead ,
32-
3333 private oauthApps : IOAuthAppsReader ,
3434 private thread : IThreadRead ,
3535 private role : IRoleRead ,
36+ private experimental : IExperimentalRead ,
3637 ) { }
3738
3839 public getEnvironmentReader ( ) : IEnvironmentRead {
@@ -90,4 +91,8 @@ export class Reader implements IRead {
9091 public getContactReader ( ) : IContactRead {
9192 return this . contactRead ;
9293 }
94+
95+ public getExperimentalReader ( ) : IExperimentalRead {
96+ return this . experimental ;
97+ }
9398}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { CommandBridge } from './CommandBridge';
66import type { ContactBridge } from './ContactBridge' ;
77import type { EmailBridge } from './EmailBridge' ;
88import type { EnvironmentalVariableBridge } from './EnvironmentalVariableBridge' ;
9+ import type { ExperimentalBridge } from './ExperimentalBridge' ;
910import type { HttpBridge } from './HttpBridge' ;
1011import type { IInternalBridge } from './IInternalBridge' ;
1112import type { IInternalFederationBridge } from './IInternalFederationBridge' ;
@@ -42,6 +43,7 @@ export type Bridge =
4243 | IInternalBridge
4344 | ServerSettingBridge
4445 | EmailBridge
46+ | ExperimentalBridge
4547 | UploadBridge
4648 | UserBridge
4749 | UiInteractionBridge
@@ -106,4 +108,6 @@ export abstract class AppBridges {
106108 public abstract getRoleBridge ( ) : RoleBridge ;
107109
108110 public abstract getOutboundMessageBridge ( ) : OutboundMessageBridge ;
111+
112+ public abstract getExperimentalBridge ( ) : ExperimentalBridge ;
109113}
You can’t perform that action at this time.
0 commit comments