From b0debddba144e014144ac6e15a774f0fd02412a4 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Thu, 10 Mar 2022 13:44:15 +0100 Subject: [PATCH 01/15] wip private mode --- package-lock.json | 2 +- src/index.ts | 1 + src/utils/types.ts | 4 +++ src/widgets/details/details-widget.ts | 5 ++- src/widgets/messagebox/messagebox-widget.ts | 5 ++- src/widgets/shared/private-mode.ts | 39 +++++++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/widgets/shared/private-mode.ts diff --git a/package-lock.json b/package-lock.json index 247e924..e31c0d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@livechat/agent-app-sdk", - "version": "1.5.1", + "version": "1.5.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/index.ts b/src/index.ts index 69ca707..666bd35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,3 +2,4 @@ export * from './widgets/details'; export * from './widgets/messagebox'; export * from './widgets/fullscreen'; export * from './widgets/shared/customer-profile'; +export * from './widgets/shared/private-mode'; diff --git a/src/utils/types.ts b/src/utils/types.ts index 601b43c..969cade 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1 +1,5 @@ export type Omit = Pick>; + +export interface KeyMap { + [key: string]: T; +} diff --git a/src/widgets/details/details-widget.ts b/src/widgets/details/details-widget.ts index a595698..96c7ee9 100644 --- a/src/widgets/details/details-widget.ts +++ b/src/widgets/details/details-widget.ts @@ -1,6 +1,7 @@ import { withAmplitude } from '../shared/amplitude'; import { withCustomerProfile } from '../shared/customer-profile'; import { withRichMessages } from '../shared/rich-messages'; +import { withPrivateMode } from '../shared/private-mode'; import { createWidget } from '../shared/widget'; import { IConnection, createConnection } from '../connection'; import assertSection from './custom-sections'; @@ -30,7 +31,9 @@ function DetailsWidget(connection: IConnection) { } ); - const widget = withAmplitude(withRichMessages(withCustomerProfile(base))); + const widget = withAmplitude( + withRichMessages(withCustomerProfile(withPrivateMode(base))) + ); return widget; } diff --git a/src/widgets/messagebox/messagebox-widget.ts b/src/widgets/messagebox/messagebox-widget.ts index ec1b181..fb8428f 100644 --- a/src/widgets/messagebox/messagebox-widget.ts +++ b/src/widgets/messagebox/messagebox-widget.ts @@ -1,6 +1,7 @@ import { createWidget } from '../shared/widget'; import { withAmplitude } from '../shared/amplitude'; import { withCustomerProfile } from '../shared/customer-profile'; +import { withPrivateMode } from '../shared/private-mode'; import { withRichMessages } from '../shared/rich-messages'; import { IConnection, createConnection } from '../connection'; import { @@ -25,7 +26,9 @@ function MessageBoxWidget(connection: IConnection) { } ); - const widget = withAmplitude(withRichMessages(withCustomerProfile(base))); + const widget = withAmplitude( + withRichMessages(withCustomerProfile(withPrivateMode(base))) + ); return widget; } diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts new file mode 100644 index 0000000..4b598f6 --- /dev/null +++ b/src/widgets/shared/private-mode.ts @@ -0,0 +1,39 @@ +import { KeyMap } from '../../utils/types'; +import { WidgetMixin, Widget, AnyWidgetApi } from './widget'; + +export interface IPrivateMode { + threads: KeyMap; + source: 'chats'; +} + +export interface IPrivateModeApi { + getPrivateModeThreads(): IPrivateMode | null; +} +export interface IPrivateModeEvents { + private_mode: IPrivateMode; +} + +export const withPrivateMode: WidgetMixin< + IPrivateModeApi, + IPrivateModeEvents +> = widget => { + let threads = null; + + /** + * Merge new threads with previously received threads + */ + function onPrivateMode(privateMode: IPrivateMode) { + console.log('@onPrivateMode', privateMode); + threads = { ...threads, ...privateMode.threads }; + console.log('@threads', threads); + } + + widget.on('private_mode', onPrivateMode); + + return { + ...widget, + getPrivateModeThreads(): IPrivateMode | null { + return threads; + } + }; +}; From 2bf0b7bd98dc1d137d5fc367b26101bd9f874d20 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Fri, 11 Mar 2022 14:26:33 +0100 Subject: [PATCH 02/15] say no to console --- src/widgets/shared/private-mode.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index 4b598f6..5a479ac 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -19,13 +19,8 @@ export const withPrivateMode: WidgetMixin< > = widget => { let threads = null; - /** - * Merge new threads with previously received threads - */ function onPrivateMode(privateMode: IPrivateMode) { - console.log('@onPrivateMode', privateMode); threads = { ...threads, ...privateMode.threads }; - console.log('@threads', threads); } widget.on('private_mode', onPrivateMode); From b23acc85dbc8a075adb6b59c715ce36d6ebc4422 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Mon, 14 Mar 2022 12:12:55 +0100 Subject: [PATCH 03/15] inform about plugin initialization --- src/widgets/connection/constants.ts | 10 ++++++++++ src/widgets/details/details-widget.ts | 7 +++++-- src/widgets/fullscreen/fullscreen-widget.ts | 13 ++++++++++--- src/widgets/messagebox/messagebox-widget.ts | 13 ++++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/widgets/connection/constants.ts diff --git a/src/widgets/connection/constants.ts b/src/widgets/connection/constants.ts new file mode 100644 index 0000000..60bbd3a --- /dev/null +++ b/src/widgets/connection/constants.ts @@ -0,0 +1,10 @@ +export enum PluginType { + MessageBox = 'messagebox', + Details = 'details', + Fullscreen = 'fullscreen' +} + +export enum PluginMessage { + Inited = 'plugin_inited', + Loaded = 'plugin_loaded' +} diff --git a/src/widgets/details/details-widget.ts b/src/widgets/details/details-widget.ts index 96c7ee9..1f67e3f 100644 --- a/src/widgets/details/details-widget.ts +++ b/src/widgets/details/details-widget.ts @@ -10,6 +10,7 @@ import { IDetailsWidgetApi, ISection } from './interfaces'; +import { PluginMessage, PluginType } from '../connection/constants'; function DetailsWidget(connection: IConnection) { const base = createWidget( @@ -22,7 +23,7 @@ function DetailsWidget(connection: IConnection) { return connection.sendMessage('watch_messages'); }, refreshSession(): Promise { - return connection.sendMessage('plugin_loaded'); + return connection.sendMessage(PluginMessage.Loaded); }, modifySection(section: ISection): Promise { assertSection(section); @@ -45,7 +46,9 @@ export default function createDetailsWidget(): Promise { return createConnection() .then(connection => { widget = DetailsWidget(connection); - return connection.sendMessage('plugin_inited'); + return connection.sendMessage(PluginMessage.Inited, { + plugin_type: PluginType.Details + }); }) .then(() => widget); } diff --git a/src/widgets/fullscreen/fullscreen-widget.ts b/src/widgets/fullscreen/fullscreen-widget.ts index a6852ea..8cc6ed7 100644 --- a/src/widgets/fullscreen/fullscreen-widget.ts +++ b/src/widgets/fullscreen/fullscreen-widget.ts @@ -2,6 +2,7 @@ import { createWidget } from '../shared/widget'; import { withAmplitude } from '../shared/amplitude'; import { IConnection, createConnection } from '../connection'; import { IFullscreenWidgetApi, IFullscreenWidgetEvents } from './interfaces'; +import { PluginMessage, PluginType } from '../connection/constants'; function FullscreenWidget(connection: IConnection) { const base = createWidget( @@ -22,7 +23,13 @@ export interface IFullscreenWidget extends ReturnType {} export default function createFullscreenWidget(): Promise { - return createConnection().then(connection => - FullscreenWidget(connection) - ); + let widget: IFullscreenWidget; + return createConnection() + .then(connection => { + widget = FullscreenWidget(connection); + connection.sendMessage(PluginMessage.Inited, { + plugin_type: PluginType.Fullscreen + }); + }) + .then(() => widget); } diff --git a/src/widgets/messagebox/messagebox-widget.ts b/src/widgets/messagebox/messagebox-widget.ts index fb8428f..58c391c 100644 --- a/src/widgets/messagebox/messagebox-widget.ts +++ b/src/widgets/messagebox/messagebox-widget.ts @@ -9,6 +9,7 @@ import { IMessageBoxWidgetEvents, IRichMessage } from './interfaces'; +import { PluginType, PluginMessage } from '../connection/constants'; function MessageBoxWidget(connection: IConnection) { const base = createWidget( @@ -37,7 +38,13 @@ export interface IMessageBoxWidget extends ReturnType {} export default function createMessageBoxWidget(): Promise { - return createConnection().then(connection => - MessageBoxWidget(connection) - ); + let widget: IMessageBoxWidget; + return createConnection().then(connection => { + widget = MessageBoxWidget(connection); + return connection + .sendMessage(PluginMessage.Inited, { + plugin_type: PluginType.MessageBox + }) + .then(() => widget); + }); } From 0925bde6cd9afcd135f581bc2e9bdcdd564ec97b Mon Sep 17 00:00:00 2001 From: shwarcu Date: Mon, 14 Mar 2022 12:40:42 +0100 Subject: [PATCH 04/15] new minor version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a299d6..4c8baa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@livechat/agent-app-sdk", - "version": "1.5.2", + "version": "1.6.0", "description": "SDK for extending LiveChat's Agent App", "license": "MIT", "repository": { From d21efea72d4683f5a02321fc2b7b0ddfb53d1573 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Mon, 14 Mar 2022 13:20:20 +0100 Subject: [PATCH 05/15] update readme --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/README.md b/README.md index a2920b9..affa521 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,21 @@ interface ICustomerDetailsSectionButtonClick { The `buttonId` property reflects the `id` specified for the button in the section definition. +#### `private_mode` + +Emitted when agent toggles private mode in Chats section. The handler gets the following payload: + +```ts +interface IPrivateMode { + threads: { + [key: string]: boolean; + }; + source: 'chats'; +} +``` + +_String_ key is thread ID and boolean represents state of private mode. True means enabled private mode, false means disabled private mode. + ### Methods #### `getCustomerProfile(): ICustomerProfile | null` @@ -170,6 +185,17 @@ widget.modifySection(section); The `title` of a given section has to match the one specified in the initial state. Otherwise, the section won't change. Also, the Agent App ignores the commands without valid section definitions. Make sure that the definition you're sending is correct. +#### `getPrivateModeThreads(): IPrivateMode | null` + +Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. + +```ts +{ + source: 'chats', + threads: { R80Q1FDEGX: true, R80Q1HDKP4: true } +} +``` + ## MessageBox widget (`IMessageBoxWidget`) ### Events @@ -182,6 +208,21 @@ Emitted after the widget is opened in the MessageBox. The handler will get a `IC Emitted after the message is sent by the agent. Keep in mind that the message has to be set with [`putMessage`] method in order to be sent. +#### `private_mode` + +Emitted when agent toggles private mode in Chats section. The handler gets the following payload: + +```ts +interface IPrivateMode { + threads: { + [key: string]: boolean; + }; + source: 'chats'; +} +``` + +_String_ key is thread ID and boolean represents state of private mode. True means enabled private mode, false means disabled private mode. + ### Methods #### `putMessage(msg: IRichMessage | string): Promise` @@ -206,6 +247,17 @@ widget.putMessage(richMessage); Gets the customer profile recorded most recently. Returns the `ICustomerProfile` object, which is identical to the one emitted by the `customer_profile` event or `null` (if no profile was registered). +#### `getPrivateModeThreads(): IPrivateMode | null` + +Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. + +```ts +{ + source: 'chats', + threads: { R80Q1FDEGX: true, R80Q1HDKP4: true } +} +``` + ### Rich Message object format - `custom_id`, `properties` and `elements` are optional From 64c90e5749365921e35179b75fde7c9569eec7d0 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Wed, 23 Mar 2022 17:24:18 +0100 Subject: [PATCH 06/15] update ignorelist --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index faa2954..94678b8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules dist types .rpt2_cache +.DS_Store \ No newline at end of file From 8e4d02b2a086139e2b03e411792d6e2847428c9a Mon Sep 17 00:00:00 2001 From: shwarcu Date: Wed, 23 Mar 2022 17:29:12 +0100 Subject: [PATCH 07/15] add missing newline --- src/widgets/shared/private-mode.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index 5a479ac..0d1c24b 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -9,6 +9,7 @@ export interface IPrivateMode { export interface IPrivateModeApi { getPrivateModeThreads(): IPrivateMode | null; } + export interface IPrivateModeEvents { private_mode: IPrivateMode; } From 70ff94d3d0476ee70e5f65e0593925f7f43f3b91 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Wed, 23 Mar 2022 17:32:17 +0100 Subject: [PATCH 08/15] use better name for public api method --- README.md | 4 ++-- src/widgets/shared/private-mode.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index affa521..4f06692 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ widget.modifySection(section); The `title` of a given section has to match the one specified in the initial state. Otherwise, the section won't change. Also, the Agent App ignores the commands without valid section definitions. Make sure that the definition you're sending is correct. -#### `getPrivateModeThreads(): IPrivateMode | null` +#### `getPrivateModeState(): IPrivateMode | null` Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. @@ -247,7 +247,7 @@ widget.putMessage(richMessage); Gets the customer profile recorded most recently. Returns the `ICustomerProfile` object, which is identical to the one emitted by the `customer_profile` event or `null` (if no profile was registered). -#### `getPrivateModeThreads(): IPrivateMode | null` +#### `getPrivateModeState(): IPrivateMode | null` Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index 0d1c24b..a0e2885 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -7,7 +7,7 @@ export interface IPrivateMode { } export interface IPrivateModeApi { - getPrivateModeThreads(): IPrivateMode | null; + getPrivateModeState(): IPrivateMode | null; } export interface IPrivateModeEvents { @@ -28,7 +28,7 @@ export const withPrivateMode: WidgetMixin< return { ...widget, - getPrivateModeThreads(): IPrivateMode | null { + getPrivateModeState(): IPrivateMode | null { return threads; } }; From c1698eb737d9b2226ba82514ea3ae8dfca005e8a Mon Sep 17 00:00:00 2001 From: shwarcu Date: Wed, 23 Mar 2022 17:52:28 +0100 Subject: [PATCH 09/15] fix getPrivateModeState not returning source property that is in the interface --- src/widgets/shared/private-mode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index a0e2885..0e0e00f 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -29,7 +29,7 @@ export const withPrivateMode: WidgetMixin< return { ...widget, getPrivateModeState(): IPrivateMode | null { - return threads; + return { source: 'chats', threads }; } }; }; From 3448968bc8fbb4b92471f8dcd848d56203724c0a Mon Sep 17 00:00:00 2001 From: shwarcu Date: Thu, 7 Apr 2022 15:07:38 +0200 Subject: [PATCH 10/15] missing EOL --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 94678b8..a6a980d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ node_modules dist types .rpt2_cache -.DS_Store \ No newline at end of file +.DS_Store From 7ead2bea6de54146f7102a297e1c70cdde73c666 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Thu, 7 Apr 2022 15:11:20 +0200 Subject: [PATCH 11/15] simplify createMessageBoxWidget --- src/widgets/messagebox/messagebox-widget.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/widgets/messagebox/messagebox-widget.ts b/src/widgets/messagebox/messagebox-widget.ts index 58c391c..6a79202 100644 --- a/src/widgets/messagebox/messagebox-widget.ts +++ b/src/widgets/messagebox/messagebox-widget.ts @@ -38,13 +38,11 @@ export interface IMessageBoxWidget extends ReturnType {} export default function createMessageBoxWidget(): Promise { - let widget: IMessageBoxWidget; return createConnection().then(connection => { - widget = MessageBoxWidget(connection); return connection .sendMessage(PluginMessage.Inited, { plugin_type: PluginType.MessageBox }) - .then(() => widget); + .then(() => MessageBoxWidget(connection)); }); } From 7fcc91fa777a8f07838c22da9c3fed8e9b02a1a6 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Thu, 7 Apr 2022 15:36:09 +0200 Subject: [PATCH 12/15] more accurate private mode interface --- src/widgets/shared/private-mode.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index 0e0e00f..bbf41b0 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -1,17 +1,17 @@ import { KeyMap } from '../../utils/types'; import { WidgetMixin, Widget, AnyWidgetApi } from './widget'; -export interface IPrivateMode { +export interface IPrivateModeUpdate { threads: KeyMap; source: 'chats'; } export interface IPrivateModeApi { - getPrivateModeState(): IPrivateMode | null; + getPrivateModeState(): IPrivateModeUpdate | null; } export interface IPrivateModeEvents { - private_mode: IPrivateMode; + private_mode: IPrivateModeUpdate; } export const withPrivateMode: WidgetMixin< @@ -20,7 +20,7 @@ export const withPrivateMode: WidgetMixin< > = widget => { let threads = null; - function onPrivateMode(privateMode: IPrivateMode) { + function onPrivateMode(privateMode: IPrivateModeUpdate) { threads = { ...threads, ...privateMode.threads }; } @@ -28,7 +28,7 @@ export const withPrivateMode: WidgetMixin< return { ...widget, - getPrivateModeState(): IPrivateMode | null { + getPrivateModeState(): IPrivateModeUpdate | null { return { source: 'chats', threads }; } }; From 9813be6411b2a7b32d7cc96daf1bf66bed2c8f9e Mon Sep 17 00:00:00 2001 From: shwarcu Date: Mon, 11 Apr 2022 13:53:51 +0200 Subject: [PATCH 13/15] rename interface --- README.md | 12 ++++++------ src/widgets/shared/private-mode.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4f06692..5caa889 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ The `buttonId` property reflects the `id` specified for the button in the sectio Emitted when agent toggles private mode in Chats section. The handler gets the following payload: ```ts -interface IPrivateMode { +interface IPrivateModeData { threads: { [key: string]: boolean; }; @@ -185,9 +185,9 @@ widget.modifySection(section); The `title` of a given section has to match the one specified in the initial state. Otherwise, the section won't change. Also, the Agent App ignores the commands without valid section definitions. Make sure that the definition you're sending is correct. -#### `getPrivateModeState(): IPrivateMode | null` +#### `getPrivateModeState(): IPrivateModeData | null` -Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. +Gets threads with private mode recorded most recently. Returns the `IPrivateModeData` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. ```ts { @@ -213,7 +213,7 @@ Emitted after the message is sent by the agent. Keep in mind that the message ha Emitted when agent toggles private mode in Chats section. The handler gets the following payload: ```ts -interface IPrivateMode { +interface IPrivateModeData { threads: { [key: string]: boolean; }; @@ -247,9 +247,9 @@ widget.putMessage(richMessage); Gets the customer profile recorded most recently. Returns the `ICustomerProfile` object, which is identical to the one emitted by the `customer_profile` event or `null` (if no profile was registered). -#### `getPrivateModeState(): IPrivateMode | null` +#### `getPrivateModeState(): IPrivateModeData | null` -Gets threads with private mode recorded most recently. Returns the `IPrivateMode` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. +Gets threads with private mode recorded most recently. Returns the `IPrivateModeData` object, which is identical to the one emitted by the `private_mode` event or `null` (if no profile was registered). It may contain information about multiple threads, for example, when widget was initialized after agent has toggled private mode for some threads. ```ts { diff --git a/src/widgets/shared/private-mode.ts b/src/widgets/shared/private-mode.ts index bbf41b0..215a51a 100644 --- a/src/widgets/shared/private-mode.ts +++ b/src/widgets/shared/private-mode.ts @@ -1,17 +1,17 @@ import { KeyMap } from '../../utils/types'; -import { WidgetMixin, Widget, AnyWidgetApi } from './widget'; +import { WidgetMixin } from './widget'; -export interface IPrivateModeUpdate { +export interface IPrivateModeData { threads: KeyMap; source: 'chats'; } export interface IPrivateModeApi { - getPrivateModeState(): IPrivateModeUpdate | null; + getPrivateModeState(): IPrivateModeData | null; } export interface IPrivateModeEvents { - private_mode: IPrivateModeUpdate; + private_mode: IPrivateModeData; } export const withPrivateMode: WidgetMixin< @@ -20,7 +20,7 @@ export const withPrivateMode: WidgetMixin< > = widget => { let threads = null; - function onPrivateMode(privateMode: IPrivateModeUpdate) { + function onPrivateMode(privateMode: IPrivateModeData) { threads = { ...threads, ...privateMode.threads }; } @@ -28,7 +28,7 @@ export const withPrivateMode: WidgetMixin< return { ...widget, - getPrivateModeState(): IPrivateModeUpdate | null { + getPrivateModeState(): IPrivateModeData | null { return { source: 'chats', threads }; } }; From ebae79a9498a933b8505aab3166c6a3827d72ddb Mon Sep 17 00:00:00 2001 From: Maciej Szwarc <58426925+shwarcu@users.noreply.github.com> Date: Mon, 11 Jul 2022 12:45:00 +0200 Subject: [PATCH 14/15] Update src/widgets/fullscreen/fullscreen-widget.ts Co-authored-by: Maciej Walaszczyk --- src/widgets/fullscreen/fullscreen-widget.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/widgets/fullscreen/fullscreen-widget.ts b/src/widgets/fullscreen/fullscreen-widget.ts index 8cc6ed7..0c12bd5 100644 --- a/src/widgets/fullscreen/fullscreen-widget.ts +++ b/src/widgets/fullscreen/fullscreen-widget.ts @@ -26,10 +26,8 @@ export default function createFullscreenWidget(): Promise { let widget: IFullscreenWidget; return createConnection() .then(connection => { - widget = FullscreenWidget(connection); - connection.sendMessage(PluginMessage.Inited, { + return connection.sendMessage(PluginMessage.Inited, { plugin_type: PluginType.Fullscreen - }); - }) - .then(() => widget); + }).then(() => FullscreenWidget(connection)); + }); } From a2f17674805a6e0f2094eeadfaef81f8a78ead40 Mon Sep 17 00:00:00 2001 From: shwarcu Date: Mon, 11 Jul 2022 17:44:37 +0200 Subject: [PATCH 15/15] remove unused variable --- src/widgets/fullscreen/fullscreen-widget.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/fullscreen/fullscreen-widget.ts b/src/widgets/fullscreen/fullscreen-widget.ts index 0c12bd5..1fc80c5 100644 --- a/src/widgets/fullscreen/fullscreen-widget.ts +++ b/src/widgets/fullscreen/fullscreen-widget.ts @@ -23,11 +23,11 @@ export interface IFullscreenWidget extends ReturnType {} export default function createFullscreenWidget(): Promise { - let widget: IFullscreenWidget; - return createConnection() - .then(connection => { - return connection.sendMessage(PluginMessage.Inited, { + return createConnection().then(connection => { + return connection + .sendMessage(PluginMessage.Inited, { plugin_type: PluginType.Fullscreen - }).then(() => FullscreenWidget(connection)); - }); + }) + .then(() => FullscreenWidget(connection)); + }); }