Skip to content

Commit

Permalink
feat: allow disabling message editing
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanenkoStud committed Jan 10, 2024
1 parent 71219bc commit c862e20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/kite-chat-component/src/kite-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function getMessageActions(actions: MsgActionType[]): ContextMenuAction[] {
* @fires {CustomEvent} kite-chat.select - Chat message is selected
* @fires {CustomEvent} kite-chat.screenshot - Tab screenshot
* @attr {Boolean} open - displays chat window if true or only toggle button if false or missing
* @attr {Boolean} editing - disables message editing actions if set to false
* @attr {"light" | "dark"} theme - defines kite chat theme, using prefers-color-scheme by default
* @attr {string} heading - Chat dialog heading
* @slot {"kite-msg" | "p"} - kite-chat component contains chat messages as nested subcomponents, allowing server-side rendering
Expand All @@ -161,6 +162,9 @@ export class KiteChatElement extends
@property()
heading = '🪁Kite chat';

@property({type: Boolean})
editing = true;

@query('kite-chat-footer')
private footer!: KiteChatFooterElement;

Expand Down Expand Up @@ -259,7 +263,7 @@ export class KiteChatElement extends
this.unselectAll();
}}
@kite-chat-header.close=${this._toggleOpen}
.editable=${this.selectedElements.length === 1 && this.isSent(this.selectedElements[0])}
.editable=${this.editing && this.selectedElements.length === 1 && this.isSent(this.selectedElements[0])}
.selectedElementsCount=${this.selectedElements.length}
.heading=${this.heading}
>
Expand Down Expand Up @@ -445,7 +449,7 @@ export class KiteChatElement extends
MsgActionType.DELETE,
...(!data.files || this.webShareController.isSupportedFiles(data.files) ? [MsgActionType.SHARE] : []),
...(!data.files || this.clipboardController.isWriteSupported ? [MsgActionType.COPY] : []),
...(this.isSent(msgElement) ? [MsgActionType.EDIT] : []),
...(this.editing && this.isSent(msgElement) ? [MsgActionType.EDIT] : []),
...(data.files ? [MsgActionType.DOWNLOAD] : []),
...(msgElement.selected ? [MsgActionType.UNSELECT] : [MsgActionType.SELECT]),
MsgActionType.SELECT_ALL,
Expand Down
3 changes: 3 additions & 0 deletions packages/kite-chat/src/kite-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type KiteChatOptions = {
eagerlyConnect?: boolean;
createIfMissing?: boolean;
open?: boolean;
editing?: boolean;
userId?: string;
userName?: string;
notificationIconUrl?: string;
Expand All @@ -37,6 +38,7 @@ const DEFAULT_OPTS: Partial<KiteChatOptions> = {
eagerlyConnect: false,
createIfMissing: true,
open: false,
editing: true,
};

const KITE_USER_ID_STORE_KEY = 'KITE_USER_ID';
Expand Down Expand Up @@ -255,6 +257,7 @@ export class KiteChat {
}
element = new KiteChatElement();
this.opts.open ? element.show() : element.hide();
element.editing = !!this.opts.editing;
document.body.appendChild(element);
}
element.addEventListener(
Expand Down

0 comments on commit c862e20

Please sign in to comment.