diff --git a/src/lib/hooks.js b/src/lib/hooks.js index 036ee645c..654323734 100644 --- a/src/lib/hooks.js +++ b/src/lib/hooks.js @@ -151,6 +151,10 @@ const api = { store.setState({ minimized: false }); parentCall('openWidget'); }, + + reset() { + store.resetState(); + } }; const onNewMessage = (event) => { diff --git a/src/store/Store.js b/src/store/Store.js index 58e78f4b0..73137c5c1 100644 --- a/src/store/Store.js +++ b/src/store/Store.js @@ -1,6 +1,7 @@ +import { route } from 'preact-router'; import mitt from 'mitt'; - import { parentCall } from '../lib/parentCall'; +import { loadConfig } from '../lib/main'; const { localStorage, sessionStorage } = window; @@ -21,7 +22,8 @@ export default class Store { storedState = typeof storedState === 'object' ? storedState : {}; } - this._state = { ...initialState, ...storedState }; + this._initialState = initialState; + this._state = { ...initialState, ...storedState }; window.addEventListener('storage', (e) => { // Cross-tab communication @@ -87,4 +89,10 @@ export default class Store { this._state = { ...storedState, ...nonPeristable }; this.emit('change', [this._state, prevState]); } + + resetState() { + this._state = this._initialState; + loadConfig(); + route(''); + } } diff --git a/src/widget.js b/src/widget.js index ba60fb47f..42c1195a7 100644 --- a/src/widget.js +++ b/src/widget.js @@ -310,6 +310,10 @@ function minimizeWidget() { callHook('minimizeWidget'); } +function reset() { + callHook('reset'); +} + function initialize(params) { for (const method in params) { if (!params.hasOwnProperty(method)) { @@ -439,6 +443,7 @@ window.RocketChat.livechat = { hideWidget, maximizeWidget, minimizeWidget, + reset, // callbacks onChatMaximized(fn) { registerCallback('chat-maximized', fn); },