livechat 1.2.0 → 1.4.0
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.
- checksums.yaml +4 -4
- data/AGENTS.md +8 -0
- data/CHANGELOG.md +67 -0
- data/README.md +90 -2
- data/SECURITY.md +4 -1
- data/app/controllers/livechat/chat_controller.rb +41 -0
- data/app/mailers/livechat/mailer.rb +54 -0
- data/app/views/livechat/chat/show.html.erb +30 -0
- data/app/views/livechat/conversations/_thread_panel.html.erb +7 -6
- data/app/views/livechat/mailer/new_agent_reply.text.erb +2 -2
- data/config/locales/livechat.ar.yml +2 -1
- data/config/locales/livechat.bg.yml +2 -1
- data/config/locales/livechat.bn.yml +2 -1
- data/config/locales/livechat.de.yml +2 -1
- data/config/locales/livechat.el.yml +2 -1
- data/config/locales/livechat.en.yml +2 -1
- data/config/locales/livechat.es.yml +2 -1
- data/config/locales/livechat.fr.yml +2 -1
- data/config/locales/livechat.hi.yml +2 -1
- data/config/locales/livechat.hr.yml +2 -1
- data/config/locales/livechat.id.yml +2 -1
- data/config/locales/livechat.it.yml +2 -1
- data/config/locales/livechat.ja.yml +2 -1
- data/config/locales/livechat.ko.yml +2 -1
- data/config/locales/livechat.lb.yml +2 -1
- data/config/locales/livechat.nl.yml +2 -1
- data/config/locales/livechat.pl.yml +2 -1
- data/config/locales/livechat.pt.yml +2 -1
- data/config/locales/livechat.ro.yml +2 -1
- data/config/locales/livechat.ru.yml +2 -1
- data/config/locales/livechat.th.yml +2 -1
- data/config/locales/livechat.tr.yml +2 -1
- data/config/locales/livechat.uk.yml +2 -1
- data/config/locales/livechat.ur.yml +2 -1
- data/config/locales/livechat.vi.yml +2 -1
- data/config/locales/livechat.zh-CN.yml +2 -1
- data/config/routes.rb +4 -0
- data/lib/generators/livechat/foreign_key/foreign_key_generator.rb +36 -0
- data/lib/generators/livechat/foreign_key/templates/add_livechat_messages_conversation_foreign_key.rb.tt +16 -0
- data/lib/generators/livechat/install/templates/create_livechat_tables.rb.tt +2 -1
- data/lib/generators/livechat/install/templates/initializer.rb +5 -0
- data/lib/generators/livechat/migration_helpers.rb +12 -0
- data/lib/livechat/configuration.rb +14 -0
- data/lib/livechat/dashboard.js +15 -4
- data/lib/livechat/version.rb +1 -1
- data/lib/livechat/widget.js +141 -53
- data/lib/livechat/widget.rb +7 -5
- data/lib/livechat/widget_helper.rb +12 -0
- data/lib/livechat.rb +18 -0
- metadata +5 -1
data/lib/livechat/widget.js
CHANGED
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
var recordingTimer = null;
|
|
49
49
|
var recordingCancelled = false;
|
|
50
50
|
var isOpen = false;
|
|
51
|
+
// Inline: the chat is part of the page (a [data-livechat-chat] element,
|
|
52
|
+
// from livechat_chat or the engine's chat page) instead of floating over it.
|
|
53
|
+
// Always open, never a modal, no launcher. Decided on every render, since a
|
|
54
|
+
// Turbo visit can move between a page with the element and one without.
|
|
55
|
+
var inline = false;
|
|
51
56
|
var lastFocused = null;
|
|
52
57
|
var expandBtnEl = null;
|
|
53
58
|
// Desktop-only: a bigger panel, remembered across Turbo visits. Never
|
|
@@ -122,7 +127,11 @@
|
|
|
122
127
|
applyExpanded(); // a Turbo swap makes a fresh root — restore the size class
|
|
123
128
|
syncOpenerBadges(); // a Turbo visit brings fresh openers — restamp them
|
|
124
129
|
|
|
125
|
-
if (
|
|
130
|
+
if (inline) {
|
|
131
|
+
// The page is the chat. The popover's remembered open state is left
|
|
132
|
+
// alone: it belongs to the floating panel on other pages.
|
|
133
|
+
showPanel();
|
|
134
|
+
} else if (sessionGet("livechat_open") === "1") {
|
|
126
135
|
openPanel();
|
|
127
136
|
} else {
|
|
128
137
|
// One initial fetch decides everything: thread or not, badge count.
|
|
@@ -144,7 +153,9 @@
|
|
|
144
153
|
// --- mounting ---------------------------------------------------------------
|
|
145
154
|
|
|
146
155
|
function mount() {
|
|
147
|
-
|
|
156
|
+
var host = document.querySelector("[data-livechat-chat]");
|
|
157
|
+
var parent = host || document.body;
|
|
158
|
+
if (root && root.parentNode === parent && document.body.contains(root)) return;
|
|
148
159
|
|
|
149
160
|
isOpen = false;
|
|
150
161
|
lastRenderedId = 0;
|
|
@@ -152,16 +163,27 @@
|
|
|
152
163
|
// A Turbo body swap removes the panel without closePanel() running; the
|
|
153
164
|
// documentElement (and any scroll lock on it) survives the swap.
|
|
154
165
|
unlockScroll();
|
|
166
|
+
unbindViewport();
|
|
167
|
+
// A restored Turbo snapshot carries a lifeless copy of the last root. Two
|
|
168
|
+
// roots would share every id, and lookups by id would find the copy.
|
|
169
|
+
var stale = document.querySelectorAll("#lvc-root");
|
|
170
|
+
for (var i = 0; i < stale.length; i++) stale[i].remove();
|
|
155
171
|
|
|
172
|
+
inline = !!host;
|
|
173
|
+
badgeEl = null;
|
|
156
174
|
root = document.createElement("div");
|
|
157
175
|
root.id = "lvc-root";
|
|
158
176
|
if (config.rtl) root.setAttribute("dir", "rtl");
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!config.launcher)
|
|
177
|
+
if (inline) {
|
|
178
|
+
root.className = "lvc-inline";
|
|
179
|
+
} else if (!config.launcher) {
|
|
180
|
+
// No launcher bubble to clear — the panel sits in the corner instead of
|
|
181
|
+
// hovering 66px above nothing.
|
|
182
|
+
root.className = "lvc-no-launcher";
|
|
183
|
+
}
|
|
162
184
|
|
|
163
|
-
if (config.launcher) root.appendChild(buildLauncher());
|
|
164
|
-
|
|
185
|
+
if (config.launcher && !inline) root.appendChild(buildLauncher());
|
|
186
|
+
parent.appendChild(root);
|
|
165
187
|
}
|
|
166
188
|
|
|
167
189
|
// config.accentColor rebrands the widget. Inline style properties on the
|
|
@@ -211,7 +233,7 @@
|
|
|
211
233
|
function buildPanel() {
|
|
212
234
|
var panel = document.createElement("div");
|
|
213
235
|
panel.id = "lvc-panel";
|
|
214
|
-
panel.setAttribute("role", "dialog");
|
|
236
|
+
panel.setAttribute("role", inline ? "region" : "dialog");
|
|
215
237
|
panel.setAttribute("aria-label", config.appName);
|
|
216
238
|
panel.addEventListener("keydown", trapFocus);
|
|
217
239
|
|
|
@@ -239,25 +261,9 @@
|
|
|
239
261
|
identity.appendChild(titles);
|
|
240
262
|
header.appendChild(identity);
|
|
241
263
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// Grow/shrink the desktop panel. Hidden on phones (already full-screen).
|
|
246
|
-
expandBtnEl = document.createElement("button");
|
|
247
|
-
expandBtnEl.type = "button";
|
|
248
|
-
expandBtnEl.id = "lvc-expand";
|
|
249
|
-
expandBtnEl.addEventListener("click", toggleExpand);
|
|
250
|
-
actions.appendChild(expandBtnEl);
|
|
251
|
-
|
|
252
|
-
var close = document.createElement("button");
|
|
253
|
-
close.type = "button";
|
|
254
|
-
close.id = "lvc-close";
|
|
255
|
-
close.setAttribute("aria-label", config.labels.close);
|
|
256
|
-
close.innerHTML = "×";
|
|
257
|
-
close.addEventListener("click", closePanel);
|
|
258
|
-
actions.appendChild(close);
|
|
259
|
-
|
|
260
|
-
header.appendChild(actions);
|
|
264
|
+
// Inline, the chat is the page: nothing to resize, open, or close.
|
|
265
|
+
expandBtnEl = null;
|
|
266
|
+
if (!inline) header.appendChild(buildActions());
|
|
261
267
|
panel.appendChild(header);
|
|
262
268
|
applyExpanded(); // set the panel size + the button's icon/label
|
|
263
269
|
|
|
@@ -403,6 +409,50 @@
|
|
|
403
409
|
return panel;
|
|
404
410
|
}
|
|
405
411
|
|
|
412
|
+
function buildActions() {
|
|
413
|
+
var actions = document.createElement("div");
|
|
414
|
+
actions.id = "lvc-actions";
|
|
415
|
+
|
|
416
|
+
// Grow/shrink the desktop panel. Hidden on phones (already full-screen).
|
|
417
|
+
expandBtnEl = document.createElement("button");
|
|
418
|
+
expandBtnEl.type = "button";
|
|
419
|
+
expandBtnEl.id = "lvc-expand";
|
|
420
|
+
expandBtnEl.addEventListener("click", toggleExpand);
|
|
421
|
+
actions.appendChild(expandBtnEl);
|
|
422
|
+
|
|
423
|
+
// The same chat as a page of its own (config.chat_path), when there is one.
|
|
424
|
+
if (config.chatUrl) {
|
|
425
|
+
var page = document.createElement("a");
|
|
426
|
+
page.id = "lvc-open-page";
|
|
427
|
+
page.href = chatPageUrl();
|
|
428
|
+
// A full load: the page has its own layout, not this one's.
|
|
429
|
+
page.setAttribute("data-turbo", "false");
|
|
430
|
+
page.setAttribute("aria-label", config.labels.openPage);
|
|
431
|
+
page.title = config.labels.openPage;
|
|
432
|
+
page.innerHTML = PAGE_ICON;
|
|
433
|
+
// The chat moves to the page; the popover shouldn't reopen on the next one.
|
|
434
|
+
page.addEventListener("click", function () { sessionSet("livechat_open", ""); });
|
|
435
|
+
actions.appendChild(page);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
var close = document.createElement("button");
|
|
439
|
+
close.type = "button";
|
|
440
|
+
close.id = "lvc-close";
|
|
441
|
+
close.setAttribute("aria-label", config.labels.close);
|
|
442
|
+
close.innerHTML = "×";
|
|
443
|
+
close.addEventListener("click", closePanel);
|
|
444
|
+
actions.appendChild(close);
|
|
445
|
+
return actions;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// The engine's chat page doesn't run the host's locale switching, so the
|
|
449
|
+
// link carries the widget's language along.
|
|
450
|
+
function chatPageUrl() {
|
|
451
|
+
if (!config.locale) return config.chatUrl;
|
|
452
|
+
var separator = config.chatUrl.indexOf("?") === -1 ? "?" : "&";
|
|
453
|
+
return config.chatUrl + separator + "locale=" + encodeURIComponent(config.locale);
|
|
454
|
+
}
|
|
455
|
+
|
|
406
456
|
// --- audio recording --------------------------------------------------------
|
|
407
457
|
|
|
408
458
|
function buildRecordingBar() {
|
|
@@ -670,26 +720,7 @@
|
|
|
670
720
|
// Livechat.open("…")) seeds the input — but never over a visitor's draft.
|
|
671
721
|
function openPanel(prefill) {
|
|
672
722
|
mount();
|
|
673
|
-
|
|
674
|
-
isOpen = true;
|
|
675
|
-
lastFocused = document.activeElement;
|
|
676
|
-
sessionSet("livechat_open", "1");
|
|
677
|
-
|
|
678
|
-
// The panel is built once and then hidden/shown — closing must never
|
|
679
|
-
// throw away the rendered thread or a half-written message.
|
|
680
|
-
var panel = document.getElementById("lvc-panel");
|
|
681
|
-
if (!panel) {
|
|
682
|
-
panel = buildPanel();
|
|
683
|
-
root.appendChild(panel);
|
|
684
|
-
}
|
|
685
|
-
panel.hidden = false;
|
|
686
|
-
panel.setAttribute("aria-modal", isMobileModal() ? "true" : "false");
|
|
687
|
-
if (isMobileModal()) lockScroll();
|
|
688
|
-
bindViewport(); // pin the panel above the keyboard on phones
|
|
689
|
-
setUnread(0);
|
|
690
|
-
poll();
|
|
691
|
-
schedulePoll();
|
|
692
|
-
}
|
|
723
|
+
showPanel();
|
|
693
724
|
if (inputEl) {
|
|
694
725
|
if (typeof prefill === "string" && prefill && !inputEl.value.trim()) {
|
|
695
726
|
inputEl.value = prefill;
|
|
@@ -699,7 +730,34 @@
|
|
|
699
730
|
}
|
|
700
731
|
}
|
|
701
732
|
|
|
733
|
+
// Inline, this runs once per page load and focuses nothing: a phone would
|
|
734
|
+
// otherwise raise its keyboard over the page the moment it loads.
|
|
735
|
+
function showPanel() {
|
|
736
|
+
if (isOpen) return;
|
|
737
|
+
isOpen = true;
|
|
738
|
+
lastFocused = document.activeElement;
|
|
739
|
+
if (!inline) sessionSet("livechat_open", "1");
|
|
740
|
+
|
|
741
|
+
// The panel is built once and then hidden/shown — closing must never
|
|
742
|
+
// throw away the rendered thread or a half-written message.
|
|
743
|
+
var panel = document.getElementById("lvc-panel");
|
|
744
|
+
if (!panel) {
|
|
745
|
+
panel = buildPanel();
|
|
746
|
+
root.appendChild(panel);
|
|
747
|
+
}
|
|
748
|
+
panel.hidden = false;
|
|
749
|
+
if (!inline) {
|
|
750
|
+
panel.setAttribute("aria-modal", isMobileModal() ? "true" : "false");
|
|
751
|
+
if (isMobileModal()) lockScroll();
|
|
752
|
+
bindViewport(); // pin the panel above the keyboard on phones
|
|
753
|
+
}
|
|
754
|
+
setUnread(0);
|
|
755
|
+
poll();
|
|
756
|
+
schedulePoll();
|
|
757
|
+
}
|
|
758
|
+
|
|
702
759
|
function closePanel() {
|
|
760
|
+
if (inline) return; // the page is the chat; there is nothing to close
|
|
703
761
|
isOpen = false;
|
|
704
762
|
sessionSet("livechat_open", "");
|
|
705
763
|
var panel = document.getElementById("lvc-panel");
|
|
@@ -710,8 +768,10 @@
|
|
|
710
768
|
schedulePoll();
|
|
711
769
|
}
|
|
712
770
|
|
|
771
|
+
// Never inline: the page owns its own scrolling, focus and keyboard there,
|
|
772
|
+
// and a scroll lock would pin a host page that merely contains the chat.
|
|
713
773
|
function isMobileModal() {
|
|
714
|
-
return !!(mobileModal && mobileModal.matches);
|
|
774
|
+
return !inline && !!(mobileModal && mobileModal.matches);
|
|
715
775
|
}
|
|
716
776
|
|
|
717
777
|
// --- expand / collapse (desktop) --------------------------------------------
|
|
@@ -726,6 +786,11 @@
|
|
|
726
786
|
'stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
|
|
727
787
|
'<polyline points="4 14 10 14 10 20"/><polyline points="20 10 14 10 14 4"/>' +
|
|
728
788
|
'<line x1="14" y1="10" x2="21" y2="3"/><line x1="10" y1="14" x2="3" y2="21"/></svg>';
|
|
789
|
+
var PAGE_ICON =
|
|
790
|
+
'<svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" ' +
|
|
791
|
+
'stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
|
|
792
|
+
'<path d="M14 4h6v6"/><path d="M20 4l-9 9"/>' +
|
|
793
|
+
'<path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/></svg>';
|
|
729
794
|
|
|
730
795
|
function toggleExpand() {
|
|
731
796
|
if (isMobileModal()) return;
|
|
@@ -737,7 +802,7 @@
|
|
|
737
802
|
// Reflect the current state onto the panel and the header button. A no-op on
|
|
738
803
|
// phones — the class is never added there, so the full-screen panel stands.
|
|
739
804
|
function applyExpanded() {
|
|
740
|
-
var on = expanded && !isMobileModal();
|
|
805
|
+
var on = expanded && !inline && !isMobileModal();
|
|
741
806
|
if (root) root.classList.toggle("lvc-expanded", on);
|
|
742
807
|
if (!expandBtnEl) return;
|
|
743
808
|
var label = on ? config.labels.collapse : config.labels.expand;
|
|
@@ -937,7 +1002,8 @@
|
|
|
937
1002
|
if (unreadCount > 0) {
|
|
938
1003
|
if (!badge) {
|
|
939
1004
|
badge = document.createElement("span");
|
|
940
|
-
|
|
1005
|
+
var hostClass = openers[i].getAttribute("data-livechat-badge-class");
|
|
1006
|
+
badge.className = "lvc-opener-badge" + (hostClass ? " " + hostClass : "");
|
|
941
1007
|
openers[i].appendChild(badge);
|
|
942
1008
|
}
|
|
943
1009
|
badge.textContent = unreadCount > 9 ? "9+" : String(unreadCount);
|
|
@@ -1149,13 +1215,17 @@
|
|
|
1149
1215
|
|
|
1150
1216
|
// Multipart only when there are files to carry — otherwise a plain JSON
|
|
1151
1217
|
// object, so text-only sends stay exactly as they were.
|
|
1218
|
+
//
|
|
1219
|
+
// The chat page sends no page_url: "where they got stuck" would otherwise
|
|
1220
|
+
// read "the chat page" for every message written there.
|
|
1152
1221
|
function buildMessagePayload(body) {
|
|
1222
|
+
var pageUrl = inline ? null : window.location.href;
|
|
1153
1223
|
if (!pendingFiles.length) {
|
|
1154
|
-
return { body: body, page_url:
|
|
1224
|
+
return { body: body, page_url: pageUrl, locale: config.locale };
|
|
1155
1225
|
}
|
|
1156
1226
|
var form = new FormData();
|
|
1157
1227
|
form.append("body", body);
|
|
1158
|
-
form.append("page_url",
|
|
1228
|
+
if (pageUrl) form.append("page_url", pageUrl);
|
|
1159
1229
|
form.append("locale", config.locale);
|
|
1160
1230
|
pendingFiles.forEach(function (file) { form.append("files[]", file, file.name || "voice-message.webm"); });
|
|
1161
1231
|
return form;
|
|
@@ -1244,6 +1314,9 @@
|
|
|
1244
1314
|
"#lvc-root #lvc-expand{border:none;background:none;color:var(--lvc-accent-text);cursor:pointer;" +
|
|
1245
1315
|
"padding:5px 6px;border-radius:6px;display:flex;align-items:center;justify-content:center;opacity:.9}" +
|
|
1246
1316
|
"#lvc-root #lvc-expand:hover{background:rgba(255,255,255,.15);opacity:1}" +
|
|
1317
|
+
"#lvc-root #lvc-open-page{color:var(--lvc-accent-text);padding:5px 6px;border-radius:6px;" +
|
|
1318
|
+
"display:flex;align-items:center;justify-content:center;opacity:.9}" +
|
|
1319
|
+
"#lvc-root #lvc-open-page:hover{background:rgba(255,255,255,.15);opacity:1}" +
|
|
1247
1320
|
// Desktop only: a roomier panel for long threads and image-heavy chats.
|
|
1248
1321
|
// Guarded by min-width so it can never shrink the full-screen mobile panel.
|
|
1249
1322
|
"@media(min-width:481px){#lvc-root.lvc-expanded #lvc-panel{top:20px;bottom:20px;" +
|
|
@@ -1357,8 +1430,23 @@
|
|
|
1357
1430
|
// Keep the composer box above the iPhone home indicator.
|
|
1358
1431
|
"#lvc-root #lvc-form{margin-bottom:calc(10px + env(safe-area-inset-bottom))}" +
|
|
1359
1432
|
"}" +
|
|
1433
|
+
// Inline (livechat_chat, the chat page): the panel fills its element
|
|
1434
|
+
// instead of floating. After the phone block on purpose — equal
|
|
1435
|
+
// specificity, so source order makes these win there too, including the
|
|
1436
|
+
// card's rounded border: inside a host page it is a card at any width,
|
|
1437
|
+
// not the phone popover's edge-to-edge screen. (The engine's own chat
|
|
1438
|
+
// page, which does fill the phone, squares itself off.) min-height stops
|
|
1439
|
+
// an element with no height of its own from collapsing the chat to its
|
|
1440
|
+
// header.
|
|
1441
|
+
"#lvc-root.lvc-inline{height:100%}" +
|
|
1442
|
+
"#lvc-root.lvc-inline #lvc-panel{position:relative;top:auto;right:auto;bottom:auto;left:auto;" +
|
|
1443
|
+
"z-index:auto;width:100%;max-width:none;height:100%;min-height:420px;max-height:none;box-shadow:none;" +
|
|
1444
|
+
"border:1px solid var(--lvc-border);border-radius:14px}" +
|
|
1360
1445
|
// Lives in host DOM (on data-livechat-open elements), so no #lvc-root prefix.
|
|
1361
|
-
|
|
1446
|
+
// A host that names its own badge classes gets none of this: unlayered
|
|
1447
|
+
// rules would beat its layered utility classes whatever their specificity.
|
|
1448
|
+
// :where() keeps the old single-class weight for hosts that override it.
|
|
1449
|
+
":where([data-livechat-open]:not([data-livechat-badge-class]))>.lvc-opener-badge{display:inline-flex;min-width:18px;height:18px;padding:0 5px;" +
|
|
1362
1450
|
"margin-inline-start:6px;border-radius:999px;background:#dc2626;color:#fff;" +
|
|
1363
1451
|
"font-size:11px;font-weight:700;line-height:18px;align-items:center;" +
|
|
1364
1452
|
"justify-content:center;vertical-align:middle}";
|
data/lib/livechat/widget.rb
CHANGED
|
@@ -105,12 +105,17 @@ module Livechat
|
|
|
105
105
|
accentColor: settings[:accent_color],
|
|
106
106
|
attachments: Livechat.attachments_enabled?,
|
|
107
107
|
maxAttachments: config.max_attachments,
|
|
108
|
+
chatUrl: Livechat.chat_path,
|
|
108
109
|
labels: labels(settings)
|
|
109
110
|
}
|
|
110
111
|
# Escape "</" so a value can't close the <script> block early.
|
|
111
112
|
payload.to_json.gsub('</', '<\/')
|
|
112
113
|
end
|
|
113
114
|
|
|
115
|
+
def rtl?(locale)
|
|
116
|
+
RTL_LANGUAGES.include?(locale.to_s.downcase.split(/[-_]/).first)
|
|
117
|
+
end
|
|
118
|
+
|
|
114
119
|
private
|
|
115
120
|
|
|
116
121
|
def script_src
|
|
@@ -136,7 +141,7 @@ module Livechat
|
|
|
136
141
|
emailPlaceholder: t(:email_placeholder, 'you@example.com'),
|
|
137
142
|
emailSave: t(:email_save, 'Save'),
|
|
138
143
|
emailSaved: t(:email_saved, 'We will also reply by email.'),
|
|
139
|
-
eventResolved: t(:event_resolved, '
|
|
144
|
+
eventResolved: t(:event_resolved, 'Resolved for now. Send another message whenever you need help.'),
|
|
140
145
|
eventReopened: t(:event_reopened, 'Conversation reopened'),
|
|
141
146
|
errorSend: t(:error_send, 'Could not send. Please try again.'),
|
|
142
147
|
unreadAria: t(:unread_aria, 'unread messages'),
|
|
@@ -153,6 +158,7 @@ module Livechat
|
|
|
153
158
|
attachmentError: t(:attachment_error, 'Some files could not be sent.'),
|
|
154
159
|
expand: t(:expand, 'Expand'),
|
|
155
160
|
collapse: t(:collapse, 'Collapse'),
|
|
161
|
+
openPage: t(:open_page, 'Open as a page'),
|
|
156
162
|
typing: t(:typing, '%{name} is typing...', name: t(:team, 'Support'))
|
|
157
163
|
}
|
|
158
164
|
end
|
|
@@ -160,10 +166,6 @@ module Livechat
|
|
|
160
166
|
def t(key, default, **args)
|
|
161
167
|
I18n.t(key, scope: :livechat, default: default, **args)
|
|
162
168
|
end
|
|
163
|
-
|
|
164
|
-
def rtl?(locale)
|
|
165
|
-
RTL_LANGUAGES.include?(locale.to_s.downcase.split(/[-_]/).first)
|
|
166
|
-
end
|
|
167
169
|
end
|
|
168
170
|
end
|
|
169
171
|
end
|
|
@@ -31,6 +31,18 @@ module Livechat
|
|
|
31
31
|
tag.button(label, type: 'button', data:, **options)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# The chat itself, in your page instead of floating over it: the visitor's
|
|
35
|
+
# own conversation, filling this element. Give it a height (or put it in a
|
|
36
|
+
# container that has one). The bubble stays away while it is on the page.
|
|
37
|
+
# Like livechat_button, it is only the element — livechat_tag in your
|
|
38
|
+
# layout brings the widget that fills it.
|
|
39
|
+
def livechat_chat(**options)
|
|
40
|
+
return unless Livechat.enabled?(request)
|
|
41
|
+
|
|
42
|
+
data = (options.delete(:data) { {} } || {}).merge(livechat_chat: '')
|
|
43
|
+
tag.div(data:, **options)
|
|
44
|
+
end
|
|
45
|
+
|
|
34
46
|
private
|
|
35
47
|
|
|
36
48
|
def livechat_visitor
|
data/lib/livechat.rb
CHANGED
|
@@ -43,6 +43,24 @@ module Livechat
|
|
|
43
43
|
["#{mount}/widget.js", "#{mount}/embed.js", "#{mount}/widget/", "#{mount}/attachments/"]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
# Where the visitor's chat lives as a page, or nil when chat_path is false.
|
|
47
|
+
# Link to it from your own nav:
|
|
48
|
+
#
|
|
49
|
+
# link_to "Support chat", Livechat.chat_path(locale: I18n.locale)
|
|
50
|
+
#
|
|
51
|
+
# The engine's page doesn't run your locale switching, so pass the locale
|
|
52
|
+
# for any app that isn't single-language.
|
|
53
|
+
def chat_path(locale: nil)
|
|
54
|
+
path = case config.chat_path
|
|
55
|
+
when false then return
|
|
56
|
+
when nil then config.engine_chat_path
|
|
57
|
+
else config.chat_path.to_s
|
|
58
|
+
end
|
|
59
|
+
return path if locale.blank?
|
|
60
|
+
|
|
61
|
+
"#{path}#{path.include?('?') ? '&' : '?'}locale=#{URI.encode_www_form_component(locale.to_s)}"
|
|
62
|
+
end
|
|
63
|
+
|
|
46
64
|
# Resolve a setting that may be a plain value or a per-request callable.
|
|
47
65
|
def resolve(value, request)
|
|
48
66
|
value.respond_to?(:call) ? value.call(request) : value
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: livechat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yaroslav Shmarov
|
|
@@ -53,6 +53,7 @@ files:
|
|
|
53
53
|
- app/controllers/concerns/livechat/request_context.rb
|
|
54
54
|
- app/controllers/livechat/application_controller.rb
|
|
55
55
|
- app/controllers/livechat/attachments_controller.rb
|
|
56
|
+
- app/controllers/livechat/chat_controller.rb
|
|
56
57
|
- app/controllers/livechat/conversations_controller.rb
|
|
57
58
|
- app/controllers/livechat/dashboard_controller.rb
|
|
58
59
|
- app/controllers/livechat/messages_controller.rb
|
|
@@ -64,6 +65,7 @@ files:
|
|
|
64
65
|
- app/models/livechat/conversation.rb
|
|
65
66
|
- app/models/livechat/message.rb
|
|
66
67
|
- app/views/layouts/livechat/application.html.erb
|
|
68
|
+
- app/views/livechat/chat/show.html.erb
|
|
67
69
|
- app/views/livechat/conversations/_thread_panel.html.erb
|
|
68
70
|
- app/views/livechat/conversations/index.html.erb
|
|
69
71
|
- app/views/livechat/conversations/show.html.erb
|
|
@@ -101,6 +103,8 @@ files:
|
|
|
101
103
|
- docs/screenshots/01-widget.png
|
|
102
104
|
- docs/screenshots/03-inbox.png
|
|
103
105
|
- docs/screenshots/04-conversation.png
|
|
106
|
+
- lib/generators/livechat/foreign_key/foreign_key_generator.rb
|
|
107
|
+
- lib/generators/livechat/foreign_key/templates/add_livechat_messages_conversation_foreign_key.rb.tt
|
|
104
108
|
- lib/generators/livechat/install/install_generator.rb
|
|
105
109
|
- lib/generators/livechat/install/templates/create_livechat_tables.rb.tt
|
|
106
110
|
- lib/generators/livechat/install/templates/initializer.rb
|