@meetelise/chat 1.20.12 → 1.20.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,10 @@ import { installLauncher } from "./Launcher";
16
16
  import "./MEChat.css";
17
17
  import { getRawAvailabilities } from "../getAvailabilities";
18
18
  import { StyleInfo } from "lit/directives/style-map";
19
+ import addMinutes from "date-fns/addMinutes";
20
+ import formatISO from "date-fns/formatISO";
21
+ import parseISO from "date-fns/parseISO";
22
+ import isPast from "date-fns/isPast";
19
23
 
20
24
  export interface Options {
21
25
  building: string;
@@ -221,15 +225,18 @@ export class MEChat extends LitElement {
221
225
  }
222
226
  (talkjsPopupElement as HTMLElement).style.zIndex = "99999999999";
223
227
  this.popup = popup;
224
- const hasAutoOpened = sessionStorage.getItem("hasAutoOpened");
225
- if (building.autoOpenChatWidget && !hasAutoOpened) {
228
+ const autoOpenedTimestamp = sessionStorage.getItem("autoOpenedTimestamp");
229
+ const shouldAutoOpen =
230
+ !autoOpenedTimestamp ||
231
+ (autoOpenedTimestamp && isPast(parseISO(autoOpenedTimestamp)));
232
+ if (building.autoOpenChatWidget && shouldAutoOpen) {
226
233
  this.popup.show();
227
234
  this.hideLauncher = true;
228
235
  this.hasMounted = true;
229
- sessionStorage.setItem("hasAutoOpened", "true");
230
- window.addEventListener("beforeunload", () => {
231
- sessionStorage.removeItem("hasAutoOpened");
232
- });
236
+ sessionStorage.setItem(
237
+ "autoOpenedTimestamp",
238
+ formatISO(addMinutes(new Date(), 15))
239
+ );
233
240
  }
234
241
  };
235
242