Skip to content

Commit

Permalink
Revert "Revert "feat: ILivechatCreator createAndReturnVisitor method (
Browse files Browse the repository at this point in the history
#771)""

This reverts commit 1f9c857.
  • Loading branch information
ggazzo committed Jul 12, 2024
1 parent c15cfeb commit 080cfad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/definition/accessors/ILivechatCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ export interface ILivechatCreator {
* @param agent The agent responsible for the room
*/
createRoom(visitor: IVisitor, agent: IUser, extraParams?: IExtraRoomParams): Promise<ILivechatRoom>;

/**
* @deprecated Use `createAndReturnVisitor` instead.
* Creates a Livechat visitor
*
* @param visitor Data of the visitor to be created
*/
createVisitor(visitor: IVisitor): Promise<string>;

/**
* Creates a Livechat visitor
*
* @param visitor Data of the visitor to be created
*/
createAndReturnVisitor(visitor: IVisitor): Promise<IVisitor | undefined>;

/**
* Creates a token to be used when
* creating a new livechat visitor
Expand Down
7 changes: 7 additions & 0 deletions src/server/accessors/LivechatCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ export class LivechatCreator implements ILivechatCreator {
return this.bridges.getLivechatBridge().doCreateRoom(visitor, agent, this.appId, extraParams);
}

/**
* @deprecated Use `createAndReturnVisitor` instead.
*/
public createVisitor(visitor: IVisitor): Promise<string> {
return this.bridges.getLivechatBridge().doCreateVisitor(visitor, this.appId);
}

public createAndReturnVisitor(visitor: IVisitor): Promise<IVisitor | undefined> {
return this.bridges.getLivechatBridge().doCreateAndReturnVisitor(visitor, this.appId);
}

public createToken(): string {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
Expand Down
15 changes: 15 additions & 0 deletions src/server/bridges/LivechatBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ export abstract class LivechatBridge extends BaseBridge {
}
}

/**
* @deprecated please use the `doCreateAndReturnVisitor` method instead.
*/
public async doCreateVisitor(visitor: IVisitor, appId: string): Promise<string> {
if (this.hasWritePermission(appId, 'livechat-visitor')) {
return this.createVisitor(visitor, appId);
}
}

public async doCreateAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined> {
if (this.hasWritePermission(appId, 'livechat-visitor')) {
return this.createAndReturnVisitor(visitor, appId);
}
}

public async doFindVisitors(query: object, appId: string): Promise<Array<IVisitor>> {
if (this.hasReadPermission(appId, 'livechat-visitor')) {
return this.findVisitors(query, appId);
Expand Down Expand Up @@ -160,8 +169,14 @@ export abstract class LivechatBridge extends BaseBridge {

protected abstract updateMessage(message: ILivechatMessage, appId: string): Promise<void>;

/**
* @deprecated please use `createAndReturnVisitor` instead.
* It returns the created record rather than the ID.
*/
protected abstract createVisitor(visitor: IVisitor, appId: string): Promise<string>;

protected abstract createAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined>;

/**
* @deprecated This method does not adhere to the conversion practices applied
* elsewhere in the Apps-Engine and will be removed in the next major version.
Expand Down
4 changes: 4 additions & 0 deletions tests/test-data/bridges/livechatBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class TestLivechatBridge extends LivechatBridge {
throw new Error('Method not implemented');
}

public createAndReturnVisitor(visitor: IVisitor, appId: string): Promise<IVisitor | undefined> {
throw new Error('Method not implemented');
}

public transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData, appId: string): Promise<boolean> {
throw new Error('Method not implemented');
}
Expand Down

0 comments on commit 080cfad

Please sign in to comment.