-
Notifications
You must be signed in to change notification settings - Fork 119
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
New room event #266
Merged
Merged
New room event #266
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c754fad
Fix security problem
d-gubert 1edda3c
Make calls to apps' method rethrow AppsEngineError instances
d-gubert 3bf572c
Add IPreRoomUserJoined event
d-gubert 0ab131c
Deep clone and freeze external data in the new event
d-gubert a400a81
Add the IPostRoomUserJoined event
d-gubert 8a9b347
Change freezing strategy
d-gubert bcdd3b0
Rename new Errors as Exceptions
d-gubert e654965
New "essentials" mechanism (#269)
d-gubert 7ad5ea9
Refactor exceptions
d-gubert f62d402
Add comments to the new interfaces
d-gubert b90d443
Change invitingUser to inviter
d-gubert ed39c17
Switch typing style
d-gubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* The internal exception from the framework | ||
* | ||
* It's used to signal to the outside world that | ||
* a _known_ exception has happened during the execution | ||
* of the apps. | ||
* | ||
* It's the base exception for other known classes | ||
* such as UserNotAllowedException, which is used | ||
* to inform the host that an app identified | ||
* that a user cannot perform some action, e.g. | ||
* join a room | ||
*/ | ||
export class AppsEngineException extends Error {} |
17 changes: 17 additions & 0 deletions
17
src/definition/exceptions/EssentialAppDisabledException.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AppsEngineException } from '.'; | ||
|
||
/** | ||
* This exception informs the host system that an | ||
* app essential to the execution of a system action | ||
* is disabled, so the action should be halted. | ||
* | ||
* Apps can register to be considered essential to | ||
* the execution of internal events of the framework | ||
* such as `IPreMessageSentPrevent`, `IPreRoomUserJoined`, | ||
* etc. | ||
* | ||
* This is used interally by the framework and is not | ||
* intended to be thrown manually by apps. | ||
*/ | ||
export class EssentialAppDisabledException extends AppsEngineException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { AppsEngineException } from '.'; | ||
|
||
/** | ||
* This exception informs the host system that an | ||
* app has determined that an user is not allowed | ||
* to perform a specific action. | ||
* | ||
* Currently it is expected to be thrown by the | ||
* following events: | ||
* - IPreRoomCreatePrevent | ||
* - IPreRoomUserJoined | ||
*/ | ||
export class UserNotAllowedException extends AppsEngineException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './AppsEngineException'; | ||
export * from './EssentialAppDisabledException'; | ||
export * from './UserNotAllowedException'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export enum AppInterface { | ||
// Messages | ||
IPreMessageSentPrevent = 'IPreMessageSentPrevent', | ||
IPreMessageSentExtend = 'IPreMessageSentExtend', | ||
IPreMessageSentModify = 'IPreMessageSentModify', | ||
IPostMessageSent = 'IPostMessageSent', | ||
IPreMessageDeletePrevent = 'IPreMessageDeletePrevent', | ||
IPostMessageDeleted = 'IPostMessageDeleted', | ||
IPreMessageUpdatedPrevent = 'IPreMessageUpdatedPrevent', | ||
IPreMessageUpdatedExtend = 'IPreMessageUpdatedExtend', | ||
IPreMessageUpdatedModify = 'IPreMessageUpdatedModify', | ||
IPostMessageUpdated = 'IPostMessageUpdated', | ||
// Rooms | ||
IPreRoomCreatePrevent = 'IPreRoomCreatePrevent', | ||
IPreRoomCreateExtend = 'IPreRoomCreateExtend', | ||
IPreRoomCreateModify = 'IPreRoomCreateModify', | ||
IPostRoomCreate = 'IPostRoomCreate', | ||
IPreRoomDeletePrevent = 'IPreRoomDeletePrevent', | ||
IPostRoomDeleted = 'IPostRoomDeleted', | ||
IPreRoomUserJoined = 'IPreRoomUserJoined', | ||
IPostRoomUserJoined = 'IPostRoomUserJoined', | ||
// External Components | ||
IPostExternalComponentOpened = 'IPostExternalComponentOpened', | ||
IPostExternalComponentClosed = 'IPostExternalComponentClosed', | ||
// Blocks | ||
IUIKitInteractionHandler = 'IUIKitInteractionHandler', | ||
// Livechat | ||
IPostLivechatRoomStarted = 'IPostLivechatRoomStarted', | ||
IPostLivechatRoomClosed = 'IPostLivechatRoomClosed', | ||
/** | ||
* @deprecated please use the AppMethod.EXECUTE_POST_LIVECHAT_ROOM_CLOSED method | ||
*/ | ||
ILivechatRoomClosedHandler = 'ILivechatRoomClosedHandler', | ||
IPostLivechatAgentAssigned = 'IPostLivechatAgentAssigned', | ||
IPostLivechatAgentUnassigned = 'IPostLivechatAgentUnassigned', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { IHttp, IPersistence, IRead } from '../accessors'; | ||
import { IRoomUserJoinedContext } from './IRoomUserJoinedContext'; | ||
|
||
/** | ||
* Event interface that allows an app to | ||
* register as a handler of the `IPostRoomUserJoined` | ||
* event | ||
* | ||
* This event is triggered after an user succcessfully joined | ||
* a room. | ||
* | ||
* This event does not allow an app to prevent any action from | ||
* happening. For that, see its "pre counterpart(s)": | ||
* | ||
* - IPreRoomUserJoined | ||
*/ | ||
export interface IPostRoomUserJoined { | ||
executePostRoomUserJoined(context: IRoomUserJoinedContext, read: IRead, http: IHttp, persistence: IPersistence): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IHttp, IPersistence, IRead } from '../accessors'; | ||
import { IRoomUserJoinedContext } from './IRoomUserJoinedContext'; | ||
|
||
/** | ||
* Event interface that allows an app to | ||
* register as a handler of the `IPreRoomUserJoined` | ||
* event | ||
* | ||
* This event is triggered prior to an user succcessfully | ||
* joining a room. To prevent the user from executing | ||
* such action, an app should throw the `UserNotAllowedException`. | ||
* | ||
* This event is not triggered before a room has been created. For that, | ||
* check the `IPreRoomCreate` events | ||
*/ | ||
export interface IPreRoomUserJoined { | ||
executePreRoomUserJoined(context: IRoomUserJoinedContext, read: IRead, http: IHttp, persistence: IPersistence): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IUser } from '../users'; | ||
import { IRoom } from './IRoom'; | ||
|
||
/** | ||
* The context of execution for the following events: | ||
* - IPreRoomUserJoined | ||
* - IPostRoomUserJoined | ||
*/ | ||
export interface IRoomUserJoinedContext { | ||
/** | ||
* The user that is being added to the room | ||
*/ | ||
joiningUser: IUser; | ||
/** | ||
* The room to which the user is being added | ||
*/ | ||
room: IRoom; | ||
/** | ||
* The user that has invited `joiningUser` to `room`, | ||
* if any. | ||
*/ | ||
inviter?: IUser; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a micro-optimization, but wouldn't it be better to have this array created static and as a constant instead of having to be created every time this method is called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it would be slightly more efficient, indeed it is a micro-optimization. IMO it's clearer to read it that way, everything is inside the method's body.
If time comes we need this list elsewhere, no doubt we should extract to a static array. Right now I'm more inclined to go with the "clearer" version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I’m of the opposite opinion. I think it is more clear to read the code when it is reading a named variable/constant that expresses what it is for than to declare it in the body of the method being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking what you said as a rule is generally safer, but in this specific case, we have a bunch of things helping us: short method body; short method name; clear enum items named inside the array; few items inside it.
But should the situation be different, it would be worth it to go down a different path 😃