Skip to content

Commit 0567303

Browse files
committed
wip
1 parent 94271ae commit 0567303

1 file changed

Lines changed: 66 additions & 58 deletions

File tree

apps/meteor/app/apps/server/bridges/listeners.ts

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { UIKitIncomingInteraction } from '@rocket.chat/apps-engine/definiti
1212
import type { IUIKitLivechatIncomingInteraction } from '@rocket.chat/apps-engine/definition/uikit/livechat';
1313
import type { IUserContext, IUserUpdateContext } from '@rocket.chat/apps-engine/definition/users';
1414
import type { IMessage, IRoom, IUser, ILivechatDepartment, IUpload } from '@rocket.chat/core-typings';
15+
import { inspect } from 'util';
1516

1617
type LivechatTransferData = {
1718
type: LivechatTransferEventType;
@@ -185,69 +186,76 @@ type HandleEvent =
185186
export class AppListenerBridge {
186187
constructor(private readonly orch: IAppServerOrchestrator) {}
187188

188-
// eslint-disable-next-line complexity
189189
async handleEvent(args: HandleEvent): Promise<any> {
190190
const listenerManager = this.orch.getManager().getListenerManager();
191-
if (!listenerManager.hasListeners(args.event as AppInterface)) {
191+
192+
const execute = () => {
193+
switch (args.event) {
194+
case AppInterface.IPreFileUpload:
195+
return this.uploadEvent(args);
196+
case AppInterface.IPostMessageDeleted:
197+
case AppInterface.IPostMessageReacted:
198+
case AppInterface.IPostMessageFollowed:
199+
case AppInterface.IPostMessagePinned:
200+
case AppInterface.IPostMessageStarred:
201+
case AppInterface.IPostMessageReported:
202+
case AppInterface.IPostSystemMessageSent:
203+
case AppInterface.IPreMessageSentPrevent:
204+
case AppInterface.IPreMessageSentExtend:
205+
case AppInterface.IPreMessageSentModify:
206+
case AppInterface.IPostMessageSent:
207+
case AppInterface.IPreMessageDeletePrevent:
208+
case AppInterface.IPreMessageUpdatedPrevent:
209+
case AppInterface.IPreMessageUpdatedExtend:
210+
case AppInterface.IPreMessageUpdatedModify:
211+
case AppInterface.IPostMessageUpdated:
212+
return this.messageEvent(args);
213+
case AppInterface.IPreRoomCreatePrevent:
214+
case AppInterface.IPreRoomCreateExtend:
215+
case AppInterface.IPreRoomCreateModify:
216+
case AppInterface.IPostRoomCreate:
217+
case AppInterface.IPreRoomDeletePrevent:
218+
case AppInterface.IPostRoomDeleted:
219+
case AppInterface.IPreRoomUserJoined:
220+
case AppInterface.IPostRoomUserJoined:
221+
case AppInterface.IPreRoomUserLeave:
222+
case AppInterface.IPostRoomUserLeave:
223+
return this.roomEvent(args);
224+
/**
225+
* @deprecated please prefer the AppInterface.IPostLivechatRoomClosed event
226+
*/
227+
case AppInterface.ILivechatRoomClosedHandler:
228+
case AppInterface.IPreLivechatRoomCreatePrevent:
229+
case AppInterface.IPostLivechatRoomStarted:
230+
case AppInterface.IPostLivechatRoomClosed:
231+
case AppInterface.IPostLivechatAgentAssigned:
232+
case AppInterface.IPostLivechatAgentUnassigned:
233+
case AppInterface.IPostLivechatRoomTransferred:
234+
case AppInterface.IPostLivechatGuestSaved:
235+
case AppInterface.IPostLivechatRoomSaved:
236+
case AppInterface.IPostLivechatDepartmentRemoved:
237+
case AppInterface.IPostLivechatDepartmentDisabled:
238+
return this.livechatEvent(args);
239+
case AppInterface.IPostUserCreated:
240+
case AppInterface.IPostUserUpdated:
241+
case AppInterface.IPostUserDeleted:
242+
case AppInterface.IPostUserLoggedIn:
243+
case AppInterface.IPostUserLoggedOut:
244+
case AppInterface.IPostUserStatusChanged:
245+
return this.userEvent(args);
246+
default:
247+
return this.defaultEvent(args);
248+
}
249+
};
250+
251+
const result = await execute();
252+
253+
if (!listenerManager.hasListeners(args.event)) {
254+
args.event.includes('Message') && console.debug(inspect({ args, result }, false, 10));
192255
return undefined;
193256
}
194257

195-
switch (args.event) {
196-
case AppInterface.IPreFileUpload:
197-
return this.uploadEvent(args);
198-
case AppInterface.IPostMessageDeleted:
199-
case AppInterface.IPostMessageReacted:
200-
case AppInterface.IPostMessageFollowed:
201-
case AppInterface.IPostMessagePinned:
202-
case AppInterface.IPostMessageStarred:
203-
case AppInterface.IPostMessageReported:
204-
case AppInterface.IPostSystemMessageSent:
205-
case AppInterface.IPreMessageSentPrevent:
206-
case AppInterface.IPreMessageSentExtend:
207-
case AppInterface.IPreMessageSentModify:
208-
case AppInterface.IPostMessageSent:
209-
case AppInterface.IPreMessageDeletePrevent:
210-
case AppInterface.IPreMessageUpdatedPrevent:
211-
case AppInterface.IPreMessageUpdatedExtend:
212-
case AppInterface.IPreMessageUpdatedModify:
213-
case AppInterface.IPostMessageUpdated:
214-
return this.messageEvent(args);
215-
case AppInterface.IPreRoomCreatePrevent:
216-
case AppInterface.IPreRoomCreateExtend:
217-
case AppInterface.IPreRoomCreateModify:
218-
case AppInterface.IPostRoomCreate:
219-
case AppInterface.IPreRoomDeletePrevent:
220-
case AppInterface.IPostRoomDeleted:
221-
case AppInterface.IPreRoomUserJoined:
222-
case AppInterface.IPostRoomUserJoined:
223-
case AppInterface.IPreRoomUserLeave:
224-
case AppInterface.IPostRoomUserLeave:
225-
return this.roomEvent(args);
226-
/**
227-
* @deprecated please prefer the AppInterface.IPostLivechatRoomClosed event
228-
*/
229-
case AppInterface.ILivechatRoomClosedHandler:
230-
case AppInterface.IPreLivechatRoomCreatePrevent:
231-
case AppInterface.IPostLivechatRoomStarted:
232-
case AppInterface.IPostLivechatRoomClosed:
233-
case AppInterface.IPostLivechatAgentAssigned:
234-
case AppInterface.IPostLivechatAgentUnassigned:
235-
case AppInterface.IPostLivechatRoomTransferred:
236-
case AppInterface.IPostLivechatGuestSaved:
237-
case AppInterface.IPostLivechatRoomSaved:
238-
case AppInterface.IPostLivechatDepartmentRemoved:
239-
case AppInterface.IPostLivechatDepartmentDisabled:
240-
return this.livechatEvent(args);
241-
case AppInterface.IPostUserCreated:
242-
case AppInterface.IPostUserUpdated:
243-
case AppInterface.IPostUserDeleted:
244-
case AppInterface.IPostUserLoggedIn:
245-
case AppInterface.IPostUserLoggedOut:
246-
case AppInterface.IPostUserStatusChanged:
247-
return this.userEvent(args);
248-
default:
249-
return this.defaultEvent(args);
250-
}
258+
return result;
251259
}
252260

253261
async defaultEvent(args: HandleDefaultEvent): Promise<unknown> {

0 commit comments

Comments
 (0)