Skip to content

Commit 3f81e0f

Browse files
committed
v8.3.3
1 parent c62414f commit 3f81e0f

File tree

6 files changed

+184
-138
lines changed

6 files changed

+184
-138
lines changed

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "8.3.2",
3+
"version": "8.3.3",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

published/8.3.3/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

published/latest/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GleapFrameManager.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,21 @@ export default class GleapFrameManager {
4040
this.startCommunication();
4141
}
4242

43+
isSurvey() {
44+
return this.appMode === "survey" || this.appMode === "survey_full";
45+
}
46+
4347
setAppMode(appMode) {
4448
this.appMode = appMode;
4549
this.updateFrameStyle();
4650

4751
const innerContainer = document.querySelector(
4852
".gleap-frame-container-inner"
4953
);
50-
if ((appMode === "widget" || appMode === "survey_full") && innerContainer) {
54+
if (
55+
(this.appMode === "widget" || this.appMode === "survey_full") &&
56+
innerContainer
57+
) {
5158
innerContainer.style.maxHeight = `${widgetMaxHeight}px`;
5259
}
5360
}
@@ -259,7 +266,11 @@ export default class GleapFrameManager {
259266
this.showFrameContainer(false);
260267

261268
this.updateWidgetStatus();
262-
GleapNotificationManager.getInstance().clearAllNotifications();
269+
270+
// Clear notifications only when not opening a survey.
271+
GleapNotificationManager.getInstance().clearAllNotifications(
272+
this.isSurvey()
273+
);
263274
GleapNotificationManager.getInstance().setNotificationCount(0);
264275
GleapFeedbackButtonManager.getInstance().updateFeedbackButtonState();
265276
GleapEventManager.notifyEvent("open");
@@ -304,6 +315,8 @@ export default class GleapFrameManager {
304315
this.updateWidgetStatus();
305316
GleapFeedbackButtonManager.getInstance().updateFeedbackButtonState();
306317
GleapEventManager.notifyEvent("close");
318+
GleapNotificationManager.getInstance().reloadNotificationsFromCache();
319+
307320
this.unregisterEscListener();
308321

309322
if (typeof window !== "undefined" && typeof window.focus !== "undefined") {

src/GleapNotificationManager.js

Lines changed: 165 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,195 @@
1-
import Gleap, { GleapFeedbackButtonManager, GleapConfigManager, GleapFrameManager, GleapSession } from "./Gleap";
1+
import Gleap, {
2+
GleapFeedbackButtonManager,
3+
GleapConfigManager,
4+
GleapFrameManager,
5+
GleapSession,
6+
} from "./Gleap";
27
import { loadFromGleapCache, saveToGleapCache } from "./GleapHelper";
38
import { loadIcon } from "./UI";
49

510
export default class GleapNotificationManager {
6-
notificationContainer = null;
7-
notifications = [];
8-
unreadCount = 0;
9-
unreadNotificationsKey = "unread-notifications";
10-
11-
// GleapNotificationManager singleton
12-
static instance;
13-
static getInstance() {
14-
if (!this.instance) {
15-
this.instance = new GleapNotificationManager();
16-
}
17-
return this.instance;
11+
notificationContainer = null;
12+
notifications = [];
13+
unreadCount = 0;
14+
unreadNotificationsKey = "unread-notifications";
15+
16+
// GleapNotificationManager singleton
17+
static instance;
18+
static getInstance() {
19+
if (!this.instance) {
20+
this.instance = new GleapNotificationManager();
21+
}
22+
return this.instance;
23+
}
24+
25+
/**
26+
* Injects the feedback button into the current DOM.
27+
*/
28+
injectNotificationUI() {
29+
if (this.notificationContainer) {
30+
return;
1831
}
1932

20-
/**
21-
* Injects the feedback button into the current DOM.
22-
*/
23-
injectNotificationUI() {
24-
if (this.notificationContainer) {
25-
return;
26-
}
27-
28-
var elem = document.createElement("div");
29-
elem.className = "gleap-notification-container";
30-
document.body.appendChild(elem);
31-
this.notificationContainer = elem;
32-
33-
this.updateContainerStyle();
34-
35-
// Load persisted notifications.
36-
const notificationsFromCache = loadFromGleapCache(this.unreadNotificationsKey);
37-
if (notificationsFromCache && notificationsFromCache.length > 0) {
38-
this.notifications = notificationsFromCache;
39-
this.renderNotifications();
40-
}
33+
var elem = document.createElement("div");
34+
elem.className = "gleap-notification-container";
35+
document.body.appendChild(elem);
36+
this.notificationContainer = elem;
37+
38+
this.updateContainerStyle();
39+
this.reloadNotificationsFromCache();
40+
}
41+
42+
reloadNotificationsFromCache() {
43+
// Load persisted notifications.
44+
const notificationsFromCache = loadFromGleapCache(
45+
this.unreadNotificationsKey
46+
);
47+
if (notificationsFromCache && notificationsFromCache.length > 0) {
48+
this.notifications = notificationsFromCache;
49+
this.renderNotifications();
50+
}
51+
}
52+
53+
setNotificationCount(unreadCount) {
54+
if (GleapFrameManager.getInstance().isOpened()) {
55+
this.unreadCount = 0;
56+
return;
57+
} else {
58+
this.unreadCount = unreadCount;
4159
}
4260

43-
setNotificationCount(unreadCount) {
44-
if (GleapFrameManager.getInstance().isOpened()) {
45-
this.unreadCount = 0;
46-
return;
47-
} else {
48-
this.unreadCount = unreadCount;
49-
}
61+
// Update the badge counter.
62+
GleapFeedbackButtonManager.getInstance().updateNotificationBadge(
63+
this.unreadCount
64+
);
65+
}
5066

51-
// Update the badge counter.
52-
GleapFeedbackButtonManager.getInstance().updateNotificationBadge(this.unreadCount);
67+
showNotification(notification) {
68+
if (!(this.notificationContainer && notification && notification.data)) {
69+
return;
5370
}
5471

55-
showNotification(notification) {
56-
if (!(this.notificationContainer && notification && notification.data)) {
57-
return;
58-
}
72+
const notificationsForOutbound = this.notifications.find(
73+
(e) => notification.outbound === e.outbound
74+
);
75+
if (!notificationsForOutbound) {
76+
this.notifications.push(notification);
77+
}
78+
if (this.notifications.length > 3) {
79+
this.notifications.shift();
80+
}
5981

60-
const notificationsForOutbound = this.notifications.find((e) => notification.outbound === e.outbound);
61-
if (!notificationsForOutbound) {
62-
this.notifications.push(notification);
63-
}
64-
if (this.notifications.length > 2) {
65-
this.notifications.shift();
66-
}
82+
// Persist notifications.
83+
saveToGleapCache(this.unreadNotificationsKey, this.notifications);
6784

68-
// Persist notifications.
69-
saveToGleapCache(this.unreadNotificationsKey, this.notifications);
85+
this.renderNotifications();
86+
}
7087

71-
this.renderNotifications();
88+
renderNotifications() {
89+
if (!this.notificationContainer) {
90+
return;
7291
}
7392

74-
renderNotifications() {
75-
if (!this.notificationContainer) {
76-
return;
93+
// Clear the existing notifications.
94+
this.clearAllNotifications(true);
95+
96+
// Append close button.
97+
const clearElem = document.createElement("div");
98+
clearElem.onclick = () => {
99+
this.clearAllNotifications();
100+
};
101+
clearElem.className = "gleap-notification-close";
102+
clearElem.innerHTML = loadIcon("dismiss");
103+
this.notificationContainer.appendChild(clearElem);
104+
105+
// Render the notifications.
106+
for (var i = 0; i < this.notifications.length; i++) {
107+
const notification = this.notifications[i];
108+
109+
var content = notification.data.text;
110+
111+
// Try replacing the session name.
112+
content = content.replaceAll(
113+
"{{name}}",
114+
GleapSession.getInstance().getName()
115+
);
116+
117+
const elem = document.createElement("div");
118+
elem.onclick = () => {
119+
if (notification.data.conversation) {
120+
Gleap.openConversation(notification.data.conversation.shareToken);
121+
} else if (notification.data.news) {
122+
Gleap.openNewsArticle(notification.data.news.id);
123+
} else {
124+
Gleap.open();
77125
}
78-
79-
// Clear the existing notifications.
80-
this.clearAllNotifications(true);
81-
82-
// Append close button.
83-
const clearElem = document.createElement("div");
84-
clearElem.onclick = () => {
85-
this.clearAllNotifications();
86-
};
87-
clearElem.className = "gleap-notification-close";
88-
clearElem.innerHTML = loadIcon("dismiss");
89-
this.notificationContainer.appendChild(clearElem);
90-
91-
// Render the notifications.
92-
for (var i = 0; i < this.notifications.length; i++) {
93-
const notification = this.notifications[i];
94-
95-
var content = notification.data.text;
96-
97-
// Try replacing the session name.
98-
content = content.replaceAll("{{name}}", GleapSession.getInstance().getName());
99-
100-
const elem = document.createElement("div");
101-
elem.onclick = () => {
102-
if (notification.data.conversation) {
103-
Gleap.openConversation(notification.data.conversation.shareToken);
104-
} else if (notification.data.news) {
105-
Gleap.openNewsArticle(notification.data.news.id);
106-
} else {
107-
Gleap.open();
108-
}
109-
};
110-
elem.className = "gleap-notification-item";
111-
elem.innerHTML = `
112-
${notification.data.sender && notification.data.sender.profileImageUrl && `<img src="${notification.data.sender.profileImageUrl}" />`}
126+
};
127+
elem.className = "gleap-notification-item";
128+
elem.innerHTML = `
129+
${
130+
notification.data.sender &&
131+
notification.data.sender.profileImageUrl &&
132+
`<img src="${notification.data.sender.profileImageUrl}" />`
133+
}
113134
<div class="gleap-notification-item-container">
114-
${notification.data.sender ? `<div class="gleap-notification-item-sender">${notification.data.sender.name}</div>` : ""}
135+
${
136+
notification.data.sender
137+
? `<div class="gleap-notification-item-sender">${notification.data.sender.name}</div>`
138+
: ""
139+
}
115140
<div class="gleap-notification-item-content">${content}</div>
116141
</div>`;
117-
this.notificationContainer.appendChild(elem);
118-
}
142+
this.notificationContainer.appendChild(elem);
119143
}
144+
}
120145

121-
clearAllNotifications(uiOnly = false) {
122-
if (!this.notificationContainer) {
123-
return;
124-
}
146+
clearAllNotifications(uiOnly = false) {
147+
if (!this.notificationContainer) {
148+
return;
149+
}
125150

126-
if (!uiOnly) {
127-
this.notifications = [];
128-
saveToGleapCache(this.unreadNotificationsKey, this.notifications);
129-
}
151+
if (!uiOnly) {
152+
this.notifications = [];
153+
saveToGleapCache(this.unreadNotificationsKey, this.notifications);
154+
}
130155

131-
while (this.notificationContainer.firstChild) {
132-
this.notificationContainer.removeChild(this.notificationContainer.firstChild);
133-
}
156+
while (this.notificationContainer.firstChild) {
157+
this.notificationContainer.removeChild(
158+
this.notificationContainer.firstChild
159+
);
134160
}
161+
}
135162

136-
updateContainerStyle() {
137-
if (!this.notificationContainer) {
138-
return;
139-
}
163+
updateContainerStyle() {
164+
if (!this.notificationContainer) {
165+
return;
166+
}
140167

141-
const flowConfig = GleapConfigManager.getInstance().getFlowConfig();
142-
const classLeft = "gleap-notification-container--left";
143-
const classNoButton = "gleap-notification-container--no-button";
144-
this.notificationContainer.classList.remove(classLeft);
145-
this.notificationContainer.classList.remove(classNoButton);
146-
if (
147-
flowConfig.feedbackButtonPosition === GleapFeedbackButtonManager.FEEDBACK_BUTTON_CLASSIC_LEFT ||
148-
flowConfig.feedbackButtonPosition === GleapFeedbackButtonManager.FEEDBACK_BUTTON_BOTTOM_LEFT
149-
) {
150-
this.notificationContainer.classList.add(classLeft);
151-
}
168+
const flowConfig = GleapConfigManager.getInstance().getFlowConfig();
169+
const classLeft = "gleap-notification-container--left";
170+
const classNoButton = "gleap-notification-container--no-button";
171+
this.notificationContainer.classList.remove(classLeft);
172+
this.notificationContainer.classList.remove(classNoButton);
173+
if (
174+
flowConfig.feedbackButtonPosition ===
175+
GleapFeedbackButtonManager.FEEDBACK_BUTTON_CLASSIC_LEFT ||
176+
flowConfig.feedbackButtonPosition ===
177+
GleapFeedbackButtonManager.FEEDBACK_BUTTON_BOTTOM_LEFT
178+
) {
179+
this.notificationContainer.classList.add(classLeft);
180+
}
152181

153-
if (GleapFeedbackButtonManager.getInstance().buttonHidden === null) {
154-
if (flowConfig.feedbackButtonPosition === GleapFeedbackButtonManager.FEEDBACK_BUTTON_NONE) {
155-
this.notificationContainer.classList.add(classNoButton);
156-
}
157-
} else {
158-
if (GleapFeedbackButtonManager.getInstance().buttonHidden) {
159-
this.notificationContainer.classList.add(classNoButton);
160-
}
161-
}
182+
if (GleapFeedbackButtonManager.getInstance().buttonHidden === null) {
183+
if (
184+
flowConfig.feedbackButtonPosition ===
185+
GleapFeedbackButtonManager.FEEDBACK_BUTTON_NONE
186+
) {
187+
this.notificationContainer.classList.add(classNoButton);
188+
}
189+
} else {
190+
if (GleapFeedbackButtonManager.getInstance().buttonHidden) {
191+
this.notificationContainer.classList.add(classNoButton);
192+
}
162193
}
194+
}
163195
}

0 commit comments

Comments
 (0)