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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +8 -0
  3. data/CHANGELOG.md +67 -0
  4. data/README.md +90 -2
  5. data/SECURITY.md +4 -1
  6. data/app/controllers/livechat/chat_controller.rb +41 -0
  7. data/app/mailers/livechat/mailer.rb +54 -0
  8. data/app/views/livechat/chat/show.html.erb +30 -0
  9. data/app/views/livechat/conversations/_thread_panel.html.erb +7 -6
  10. data/app/views/livechat/mailer/new_agent_reply.text.erb +2 -2
  11. data/config/locales/livechat.ar.yml +2 -1
  12. data/config/locales/livechat.bg.yml +2 -1
  13. data/config/locales/livechat.bn.yml +2 -1
  14. data/config/locales/livechat.de.yml +2 -1
  15. data/config/locales/livechat.el.yml +2 -1
  16. data/config/locales/livechat.en.yml +2 -1
  17. data/config/locales/livechat.es.yml +2 -1
  18. data/config/locales/livechat.fr.yml +2 -1
  19. data/config/locales/livechat.hi.yml +2 -1
  20. data/config/locales/livechat.hr.yml +2 -1
  21. data/config/locales/livechat.id.yml +2 -1
  22. data/config/locales/livechat.it.yml +2 -1
  23. data/config/locales/livechat.ja.yml +2 -1
  24. data/config/locales/livechat.ko.yml +2 -1
  25. data/config/locales/livechat.lb.yml +2 -1
  26. data/config/locales/livechat.nl.yml +2 -1
  27. data/config/locales/livechat.pl.yml +2 -1
  28. data/config/locales/livechat.pt.yml +2 -1
  29. data/config/locales/livechat.ro.yml +2 -1
  30. data/config/locales/livechat.ru.yml +2 -1
  31. data/config/locales/livechat.th.yml +2 -1
  32. data/config/locales/livechat.tr.yml +2 -1
  33. data/config/locales/livechat.uk.yml +2 -1
  34. data/config/locales/livechat.ur.yml +2 -1
  35. data/config/locales/livechat.vi.yml +2 -1
  36. data/config/locales/livechat.zh-CN.yml +2 -1
  37. data/config/routes.rb +4 -0
  38. data/lib/generators/livechat/foreign_key/foreign_key_generator.rb +36 -0
  39. data/lib/generators/livechat/foreign_key/templates/add_livechat_messages_conversation_foreign_key.rb.tt +16 -0
  40. data/lib/generators/livechat/install/templates/create_livechat_tables.rb.tt +2 -1
  41. data/lib/generators/livechat/install/templates/initializer.rb +5 -0
  42. data/lib/generators/livechat/migration_helpers.rb +12 -0
  43. data/lib/livechat/configuration.rb +14 -0
  44. data/lib/livechat/dashboard.js +15 -4
  45. data/lib/livechat/version.rb +1 -1
  46. data/lib/livechat/widget.js +141 -53
  47. data/lib/livechat/widget.rb +7 -5
  48. data/lib/livechat/widget_helper.rb +12 -0
  49. data/lib/livechat.rb +18 -0
  50. metadata +5 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 771d11b3c4a9a70c254bbe8f403fe4196f1aff26395fd31d023638b261fcea50
4
- data.tar.gz: cc8ef5bf1ef7dc04f66eff71481297782ea8496ada69f7bc48cab57fe3e5bfca
3
+ metadata.gz: 30216b783d33b09f017da6e0c611acea286f2a030dd141a8290990c22d603d34
4
+ data.tar.gz: 9179d65b0c2dcb0163129d1997a29ea53fb3591962f89622bd1aa09ed3203e09
5
5
  SHA512:
6
- metadata.gz: 4e9dcd6248961f6785a85fb77c79d3fbc7c5a4d79871ef7cffc7b137615c81467f77aeab2354475fd1f69ed9233ab4759eec426a52ad1aaf14cb009527e4bd0b
7
- data.tar.gz: a214328cf56cede8a3179256e30e7fc9756d4e725d69001bc396c2d0343b2beb911f0644866f6b0bf74cad4ddba026f0b0bc83f7b901ab8f96960e7106e78d6f
6
+ metadata.gz: 314d2125fe8b08a5f0efe477dcbac8466d71fd5b41d967cae27c6011d50aa583e42efe62c7144c97a66a923c1a83fdb22401448742ebc93f78188c29711bbec0
7
+ data.tar.gz: 7c151123a05f1105800f5b446b1271ca0e7dd560e475578a363d7ded0875e360e54075c1cdafc0aa86ac84a38bcd6c3b556eb523ec068382b035ecfcfa0d4c6b
data/AGENTS.md CHANGED
@@ -77,9 +77,12 @@ Then in the running app: load any page, confirm the bubble appears bottom-right,
77
77
  | The launcher bubble | On by default. `config.show_launcher = false` to remove it |
78
78
  | Your own element | `<%= livechat_button %>`, or any element with `data-livechat-open` |
79
79
  | JavaScript | `window.Livechat.open()` |
80
+ | A page of its own | `/livechat/chat` — link it with `Livechat.chat_path(locale: I18n.locale)` |
80
81
 
81
82
  A visitor has **one conversation**, not a queue of tickets — writing again reopens the same thread. Signed-in visitors keep it across devices (keyed by user id); guests are tracked by cookie.
82
83
 
84
+ **The chat as a page.** `/livechat/chat` shows the visitor's conversation filling the window; the panel's icon and the reply email link to it. It names no conversation — it resolves the visitor exactly like the widget — so do not add an id or token to that URL. If the user wants it inside their own layout, render `<%= livechat_chat style: "height: 70vh" %>` in one of their pages (it is only the element; the layout's `livechat_tag` fills it) and set `config.chat_path = "/that/page"`. `config.chat_path = false` removes the page and the icon.
85
+
83
86
  ### Email notifications need two settings, not one
84
87
 
85
88
  ```ruby
@@ -166,6 +169,7 @@ Everything is optional; a fresh install works with zero config. Full list with c
166
169
  | `allowed_attachment_types` | `nil` | Content-type allowlist |
167
170
  | `action_cable`, `action_cable_url` | `false`, `"/cable"` | Opt-in push |
168
171
  | `rate_limit` | `{ to: 30, within: 60 }` | Rails 7.2+; ignored on 7.1. `nil` disables |
172
+ | `chat_path` | `<mount_path>/chat` | The chat as a page; a path of the host's own page rendering `livechat_chat`, or `false` |
169
173
  | `mount_path` | `"/livechat"` | Keep in sync with `mount_livechat at:` |
170
174
  | `on_visitor_message`, `on_agent_message` | no-ops | Run inline after save — Slack, Noticed, push |
171
175
 
@@ -177,11 +181,15 @@ Turbo Drive and strict nonce-based CSP work out of the box. 26 locales ship with
177
181
  | --- | --- |
178
182
  | `NameError` for one of your own helpers in the inbox | `isolate_namespace` scopes `helper` to the engine. Use `config.base_controller_class` so the inbox inherits your helpers, rather than `agent_layout` alone. |
179
183
  | `NotNullViolation` attaching a file on a uuid-keyed app | The tables were generated bigint. Set `primary_key_type` in `config.generators` before installing, or migrate them to uuid. |
184
+ | `livechat:foreign_key` migration fails on an existing key | It is an upgrade generator for installs made before the key existed; a fresh install already has it |
185
+ | `livechat:foreign_key` migration fails validating the key | Messages point at a deleted conversation. Find them with `Livechat::Message.where.not(conversation_id: Livechat::Conversation.select(:id))` |
180
186
  | `/livechat` returns 403 "Set Livechat.config.authorize_agent to grant access" | Exactly what it says: still at the development-only default |
181
187
  | No bubble on the page | `livechat_tag` missing from the rendered layout, `config.enabled` false, or `show_launcher = false` with no opener of your own |
182
188
  | No notification emails | `mailer_from` not set — `agent_emails` alone does nothing |
183
189
  | Messages only appear on refresh | Expected: polling is the default. `config.action_cable = true` (with `/cable` mounted) for push |
184
190
  | No attachment button | Active Storage not installed, or `attach_files = false` |
191
+ | `livechat_chat` renders an empty box | `livechat_tag` is not in the layout — the helper is only the element the widget fills |
192
+ | The chat in a page is stuck at 420px tall | Its element has no height, so the minimum applies. Give it one (`style: "height: 70vh"`) or a container that has one |
185
193
  | `undefined local variable current_user` in the initializer | A gate lambda treated its argument as a controller. It is a `request` |
186
194
  | Widget loads on a static site but every message 422s | The embedding origin is not in `allowed_embed_origins`. A static page has no CSRF token |
187
195
  | Widget on a static site never finds its thread | It is pointed at another origin. The widget sends `credentials: "same-origin"` — proxy the mount path instead of linking across hosts |
data/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0 - 2026-11-21
4
+
5
+ - Add the chat as a page. `<mount_path>/chat` (default `/livechat/chat`) shows
6
+ the visitor their own conversation filling the window, so a visitor has a
7
+ URL for their chat: link it from your nav with `Livechat.chat_path`. The URL
8
+ names no conversation. It is resolved from the signed-in id or guest cookie,
9
+ like the widget, so a forwarded link shows a stranger only their own empty
10
+ chat. Guests keep it only in the browser that holds their cookie.
11
+ - Add `livechat_chat`, the same chat filling an element of your own page and
12
+ layout, and `config.chat_path` to point everything at that page (the
13
+ engine's page then redirects there) or `false` to turn the page off.
14
+ - The widget panel gets an "open as a page" icon. For guests, the reply
15
+ email's "Continue the conversation" link opens the chat page on the origin
16
+ they last wrote from, instead of that page itself. Signed-in visitors keep
17
+ the link to their last page, which can send them through the host's sign-in;
18
+ the engine's page cannot, and would show a signed-out reader an empty chat.
19
+ A host `chat_path` is linked for everyone. Messages written on the chat page
20
+ do not overwrite the "where they got stuck" page URL.
21
+ - `Livechat.chat_path(locale:)` adds the language to a nav link: the engine's
22
+ page does not run the host's locale switching.
23
+ - Costs: one new public, session-bearing route under the mount path, so a host
24
+ rule matching everything under it (an embed proxy, a CSP or cache rule) now
25
+ covers an HTML page too. One new locale key, `open_page`, in all 26
26
+ locales. The chat page needs no migration. The widget now removes a stale
27
+ copy of its root that a restored Turbo snapshot carries, before mounting a
28
+ fresh one.
29
+ - Messages get a foreign key to their conversation. Fresh installs create
30
+ it; existing installs add it with
31
+ `bin/rails generate livechat:foreign_key && bin/rails db:migrate`. Every
32
+ deletion in the engine already went through `destroy`, so nothing changes in
33
+ normal use, but a bulk `delete_all` on conversations used to leave their
34
+ messages behind and now raises instead. On PostgreSQL the generated
35
+ migration adds the key unvalidated and validates it in a second statement,
36
+ so it does not block writes and strong_migrations accepts it.
37
+ - Costs of the key: a host that deletes conversations with `delete_all` must
38
+ delete their messages first or use `destroy`. The migration fails if
39
+ messages already point at a deleted conversation; the generator prints the
40
+ query that finds them. Elsewhere than PostgreSQL it is a plain
41
+ `add_foreign_key`, which on MySQL can rebuild and lock `livechat_messages`
42
+ while it runs: run it at a quiet moment on a large table.
43
+
44
+ ## 1.3.0 - 2026-11-14
45
+
46
+ - Add `data-livechat-badge-class` to `data-livechat-open` elements. The unread
47
+ badge on that opener gets the host's classes and none of the built-in style,
48
+ so a Tailwind or daisyUI app can use its own badge without overriding ours.
49
+ The built-in style is injected outside any cascade layer, so before this a
50
+ host had to outrank it with a more specific selector of its own. Openers
51
+ without the attribute look and behave as before.
52
+
53
+ ## 1.2.2 - 2026-10-18
54
+
55
+ - Clarify the widget's resolved message in all 26 locales: visitors can send
56
+ another message whenever they need help. Follow-ups keep the same thread
57
+ and history; different questions still share one open/resolved status.
58
+ The longer guidance can wrap across more than one line in the timeline.
59
+
60
+ ## 1.2.1 - 2026-10-18
61
+
62
+ - Bind the inbox status form's CSRF token to the actual resolve or reopen
63
+ destination. Status changes and replies use local forms so older host apps
64
+ do not require Rails UJS to supply their tokens; CSRF checks stay enabled.
65
+ - Return focus to the agent composer after a reply, including Ctrl/Cmd+Enter
66
+ in the split-pane inbox. One form-destination marker is kept in per-tab
67
+ session storage for the next navigation; message bodies are not stored.
68
+ Ordinary inbox visits keep their existing focus behavior.
69
+
3
70
  ## 1.2.0 - 2026-10-18
4
71
 
5
72
  - Add Rails edge CI and experimental Ruby 4.0+ Ractor request support. The host
data/README.md CHANGED
@@ -62,6 +62,7 @@ the things it should not do. It ships inside the gem, so
62
62
  | | |
63
63
  | ------------- | ------------------------------------------------------------------------ |
64
64
  | **Widget** | Chat bubble, expandable panel, drafts preserved, unread badges |
65
+ | **Chat page** | The same chat as a page with a URL — for your nav and the reply email |
65
66
  | **Inbox** | Open / resolved tabs, search across everything, who-worked-what column |
66
67
  | **Team** | Any teammate answers any thread; every reply signed with its author |
67
68
  | **Email** | Both directions — one per unread stretch, not one per message |
@@ -96,6 +97,11 @@ the things it should not do. It ships inside the gem, so
96
97
  resolve it when done. A visitor writing again reopens it.
97
98
  4. The visitor sees the reply in the widget, or by email when they're gone.
98
99
 
100
+ Each visitor has one ongoing conversation. Resolving it marks the current
101
+ exchange as handled; the visitor can send another message at any time to
102
+ reopen that same thread, with the history intact. Different questions share
103
+ one open/resolved status.
104
+
99
105
  **Realtime is polling, on purpose:** ~4s while the panel is open, ~30s in the
100
106
  background, nothing at all for visitors who never wrote. No Action Cable, no
101
107
  Redis, no infrastructure. At support-chat volume you will not notice; your ops
@@ -152,6 +158,7 @@ Everything is optional — a fresh install works with zero config. In
152
158
  | `action_cable` | `false` | Opt into push delivery |
153
159
  | `action_cable_url` | `"/cable"` | Match your `mount ActionCable...` |
154
160
  | `rate_limit` | `{ to: 30, within: 1.minute }` | Per-IP throttle (Rails 7.2+). `nil` disables |
161
+ | `chat_path` | `<mount_path>/chat` | The chat as a page. A path of your own, or `false` for none — see [The chat as a page](#the-chat-as-a-page) |
155
162
  | `mount_path` | `"/livechat"` | Keep in sync with `mount` in `routes.rb` |
156
163
 
157
164
  A typical initializer:
@@ -367,13 +374,24 @@ to a stream the server signed for it. Under a strict CSP, allow the socket with
367
374
  | `window.Livechat.open()` / `.close()` | `open("Hi, I need help with…")` prefills the box — never over a visitor's draft |
368
375
  | `data-livechat-open` | Any element opens the panel on click |
369
376
  | `data-livechat-message="…"` | Prefill from that element — great for contextual buttons |
377
+ | `data-livechat-badge-class="…"` | Classes for that element's unread badge, in place of the built-in style |
370
378
  | `<%= livechat_button %>` | A plain, unstyled opener button |
371
379
  | `<%= livechat_button("Ask about this order", message: "I need help with order ##{@order.id}") %>` | Open and prefill in one helper |
372
380
  | `config.show_launcher = false` | Hide the bubble entirely |
381
+ | `<%= livechat_chat %>` | The chat filling an element of your page — see below |
373
382
 
374
383
  While replies are unread, every `data-livechat-open` element carries a small
375
384
  count badge — so hiding the launcher never hides the answer.
376
385
 
386
+ The badge has a plain red style of its own. To match your design system, name
387
+ your own classes on the opener; the built-in style then steps aside:
388
+
389
+ ```erb
390
+ <button data-livechat-open data-livechat-badge-class="badge badge-error badge-xs ms-auto">
391
+ Contact support
392
+ </button>
393
+ ```
394
+
377
395
  Contextual buttons are where a Rails app beats a generic support widget:
378
396
 
379
397
  ```erb
@@ -389,6 +407,56 @@ Contextual buttons are where a Rails app beats a generic support widget:
389
407
  </button>
390
408
  ```
391
409
 
410
+ ## The chat as a page
411
+
412
+ The bubble is for asking from where you are. Some visitors want the chat
413
+ somewhere they can go back to — a Support link in your nav, a tab of its own,
414
+ the link in the reply email. That is `/livechat/chat`: the visitor's
415
+ conversation filling the window, the same thread the bubble opens.
416
+
417
+ ```erb
418
+ <%= link_to "Support chat", Livechat.chat_path(locale: I18n.locale) %>
419
+ ```
420
+
421
+ The engine's page doesn't run your app's locale switching, hence `locale:`.
422
+ The panel has an icon that opens it, passing the language along by itself.
423
+
424
+ **The URL is the same for everyone.** Like the widget, the page finds the
425
+ visitor's conversation from their signed-in id or guest cookie, never from
426
+ the URL, so a forwarded link shows a stranger their own empty chat and
427
+ nothing else. It also means the page shows a thread only to a browser that
428
+ already carries the visitor's identity: a signed-in session, or the guest
429
+ cookie of the browser they wrote from. The engine's page can't send anyone to
430
+ your sign-in, so a signed-out user who opens it sees an empty chat.
431
+
432
+ That is why the reply email's "Continue the conversation" link goes to the
433
+ chat page for guests, but to the last page they wrote from for signed-in
434
+ visitors — your page asks them to sign in, and the thread is there after. With
435
+ `chat_path` pointing at a page of your own (which can require sign-in), the
436
+ email links that page for everyone.
437
+
438
+ The engine's page is deliberately bare: your app name, the chat, nothing of
439
+ your layout. To have the chat inside your own layout and navigation, render
440
+ it in a page of yours and point `chat_path` there — the panel's icon and the
441
+ email follow, and `/livechat/chat` redirects to it:
442
+
443
+ ```erb
444
+ <%# app/views/support/show.html.erb %>
445
+ <%= livechat_chat style: "height: 70vh" %>
446
+ ```
447
+
448
+ ```ruby
449
+ config.chat_path = "/support" # or false: no chat page, no icon
450
+ ```
451
+
452
+ `livechat_chat` is only the element; the `livechat_tag` already in your layout
453
+ fills it. Give it a height, or put it in something that has one. While it is on
454
+ the page the bubble stays away, and every `data-livechat-open` element there
455
+ moves focus into it.
456
+
457
+ Messages written on the chat page don't count as "the page they were on" for
458
+ your team — the inbox keeps showing the last page where they used the bubble.
459
+
392
460
  ## Compatibility and public API
393
461
 
394
462
  The following are the model and integration contracts that 1.x will keep
@@ -401,8 +469,10 @@ stable under semantic versioning:
401
469
  its persisted fields, optional `files`, documented scopes, author/read
402
470
  predicates, `public_label`, `attached_files`, and `preview`.
403
471
  - `Livechat.configure`, `mount_livechat`, `livechat_tag`, `livechat_button`,
404
- `window.Livechat.open/close`, `data-livechat-open`, and
405
- `data-livechat-message`.
472
+ `livechat_chat`, `Livechat.chat_path`, `window.Livechat.open/close`,
473
+ `data-livechat-open`, and `data-livechat-message`.
474
+ - The chat page under the mount path (`chat`), including its `locale`
475
+ parameter.
406
476
  - The `embed.js` endpoint under the mount path, including its `locale`
407
477
  parameter. The markup it writes is private — embed the endpoint, not a copy
408
478
  of its output.
@@ -415,6 +485,20 @@ HTML, and widget implementation objects are private. Incompatible changes to
415
485
  the public list above wait for a new major version; a deprecation normally
416
486
  ships first.
417
487
 
488
+ ### Upgrading to 1.4
489
+
490
+ The chat page needs nothing. One optional migration gives
491
+ `livechat_messages` the foreign key fresh installs now create, so a bulk
492
+ `delete_all` on conversations can no longer leave their messages behind:
493
+
494
+ ```bash
495
+ bin/rails generate livechat:foreign_key && bin/rails db:migrate
496
+ ```
497
+
498
+ On PostgreSQL it goes in without blocking writes. It fails if messages
499
+ already point at a deleted conversation; the generator prints the query that
500
+ finds them.
501
+
418
502
  ### Upgrading from 0.x
419
503
 
420
504
  There is no migration, initializer change, constant alias, or model rename.
@@ -465,6 +549,10 @@ the same host hooks (`base_controller_class` to inherit your admin's controller,
465
549
  two-pane layout, colour tokens and components in all five, scoped so it cannot
466
550
  touch your own CSS — and migrations that follow your app's `primary_key_type`.
467
551
 
552
+ ## Affiliation
553
+
554
+ An independent open-source Rails engine. Not affiliated with or endorsed by the company behind livechat.com.
555
+
468
556
  ## License
469
557
 
470
558
  MIT.
data/SECURITY.md CHANGED
@@ -23,7 +23,10 @@ users have had a reasonable opportunity to upgrade.
23
23
  The widget and visitor endpoints are controlled by `config.enabled`; the agent
24
24
  inbox is separately protected by `authorize_agent` and fails closed outside
25
25
  development until the host grants access. A visitor can read only the
26
- conversation resolved from their signed-in id or opaque guest cookie. Every
26
+ conversation resolved from their signed-in id or opaque guest cookie. The chat
27
+ page (`<mount_path>/chat`) is a public page under the same gate and the same
28
+ rule: its URL names no conversation, so possessing the link grants nothing.
29
+ Every
27
30
  authorized agent can read and answer every conversation in the mounted inbox.
28
31
  Livechat 1.x does not provide tenant-isolated agent inboxes.
29
32
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Livechat
4
+ # GET <mount_path>/chat — the visitor's chat as a page of its own.
5
+ #
6
+ # Public, like the widget: it hangs off ApplicationController, never the
7
+ # inbox's base controller. It names no conversation. The page carries the
8
+ # widget in its inline mode, and the widget resolves the thread from the
9
+ # signed-in id or guest cookie as it does everywhere else, so the URL is the
10
+ # same for everyone and a leaked link shows a stranger only their own chat.
11
+ #
12
+ # Unlike the widget's endpoints this is an HTML page with a CSRF token, so
13
+ # it needs the session and stays out of Livechat.public_paths.
14
+ class ChatController < ApplicationController
15
+ # Explicit, or Rails' implied lookup finds layouts/livechat/application —
16
+ # the inbox's shell.
17
+ layout false
18
+
19
+ before_action :require_enabled
20
+
21
+ def show
22
+ return head :not_found unless Livechat.chat_path
23
+ # A host that put the chat on a page of its own: send people there.
24
+ if Livechat.chat_path != Livechat.config.engine_chat_path
25
+ return redirect_to(Livechat.chat_path(locale: params[:locale].presence), allow_other_host: true)
26
+ end
27
+
28
+ I18n.with_locale(page_locale) { render :show }
29
+ end
30
+
31
+ private
32
+
33
+ # This page doesn't run the host's locale switching, so a link carries the
34
+ # visitor's language as ?locale= (the panel's icon and the reply email
35
+ # both do). Anything the app doesn't have falls back.
36
+ def page_locale
37
+ requested = params[:locale].to_s
38
+ I18n.available_locales.map(&:to_s).include?(requested) ? requested : I18n.locale
39
+ end
40
+ end
41
+ end
@@ -26,6 +26,7 @@ module Livechat
26
26
  def new_agent_reply(message)
27
27
  @message = message
28
28
  @conversation = message.conversation
29
+ @chat_url = chat_url(@conversation)
29
30
  assign_unread_digest(message, @conversation.messages.from_agent)
30
31
 
31
32
  mail from: Livechat.config.mailer_from,
@@ -52,6 +53,59 @@ module Livechat
52
53
  nil
53
54
  end
54
55
 
56
+ # Where the visitor continues: the chat page, on the origin they wrote
57
+ # from. That origin is where their guest cookie lives — a marketing site
58
+ # proxying the mount path is a different origin from the app's own host,
59
+ # and a link to the app's host would open an empty chat there. A page of
60
+ # the host's own (chat_path outside the mount) prefers the mailer host,
61
+ # since only the mount path is proxied. Without the chat page, it is the
62
+ # page they last wrote from, as before.
63
+ #
64
+ # A signed-in visitor keeps that last page when the target is the engine's
65
+ # page: theirs is usually behind the host's login, which takes a
66
+ # signed-out reader through sign-in and back to their thread. The engine's
67
+ # page can't ask the host to sign anyone in, and would show them an empty
68
+ # guest chat instead.
69
+ def chat_url(conversation)
70
+ path = Livechat.chat_path
71
+ return conversation.page_url unless path
72
+ return path if path.match?(%r{\Ahttps?://}i)
73
+ if conversation.visitor_id.present? && conversation.page_url.present? &&
74
+ path == Livechat.config.engine_chat_path
75
+ return conversation.page_url
76
+ end
77
+
78
+ origins = [origin_of(conversation.page_url), mailer_origin]
79
+ origins.reverse! unless path.start_with?(Livechat.config.engine_chat_path)
80
+ origin = origins.compact.first
81
+ return unless origin
82
+
83
+ url = "#{origin}#{path}"
84
+ locale = conversation.locale.presence
85
+ return url unless locale
86
+
87
+ separator = path.include?('?') ? '&' : '?'
88
+ "#{url}#{separator}locale=#{URI.encode_www_form_component(locale)}"
89
+ end
90
+
91
+ def origin_of(url)
92
+ uri = URI.parse(url.to_s)
93
+ return unless uri.host && %w[http https].include?(uri.scheme)
94
+
95
+ URI::Generic.build(scheme: uri.scheme, host: uri.host, port: uri.port == uri.default_port ? nil : uri.port).to_s
96
+ rescue URI::InvalidURIError
97
+ nil
98
+ end
99
+
100
+ def mailer_origin
101
+ options = ActionMailer::Base.default_url_options.merge(default_url_options)
102
+ return unless options[:host]
103
+
104
+ ActionDispatch::Http::URL.full_url_for(options.slice(:host, :protocol, :port).merge(path: '')).chomp('/')
105
+ rescue StandardError
106
+ nil
107
+ end
108
+
55
109
  def assign_unread_digest(message, side)
56
110
  scope = side.unread.where(id: message.id..).chronological
57
111
  unread_count = scope.count
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html lang="<%= I18n.locale %>"<%= ' dir="rtl"'.html_safe if Livechat::Widget.rtl?(I18n.locale) %>>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title><%= Livechat.app_name %></title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
7
+ <%# A personal page: whoever loads it sees their own chat. Nothing to index. %>
8
+ <meta name="robots" content="noindex">
9
+ <%= csrf_meta_tags %>
10
+ <%= csp_meta_tag %>
11
+ <%# Only the page frame. The chat styles itself, as it does on any page. %>
12
+ <style<%= %( nonce="#{content_security_policy_nonce}").html_safe if content_security_policy_nonce %>>
13
+ html, body { height: 100%; margin: 0; }
14
+ body { background: #f6f7f9; display: flex; justify-content: center; }
15
+ .lvc-chat-page { width: 100%; max-width: 760px; height: 100dvh; padding: 24px; box-sizing: border-box; }
16
+ @media (prefers-color-scheme: dark) { body { background: #111418; } }
17
+ /* On a phone this page is the whole screen, so the chat goes edge to edge.
18
+ One class more than the widget's own card rule, so it wins whatever the
19
+ order the two stylesheets land in. */
20
+ @media (max-width: 480px) {
21
+ .lvc-chat-page { padding: 0; }
22
+ .lvc-chat-page #lvc-root.lvc-inline #lvc-panel { border: none; border-radius: 0; }
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <%= livechat_chat class: 'lvc-chat-page' %>
28
+ <%= livechat_tag %>
29
+ </body>
30
+ </html>
@@ -13,18 +13,19 @@
13
13
  </p>
14
14
  </div>
15
15
  <%# The shared status switch: the state it is in is lit and inert, the other
16
- one submits to its own route via `formaction`. One form, no JS, and
17
- clicking the lit half cannot log a reopen of an already-open chat. %>
18
- <%= form_with url: resolve_conversation_path(conversation), method: :post, class: 'status-switch' do %>
16
+ one submits to its own route. The form action must match that route
17
+ so Rails binds its per-form CSRF token to the actual submission. %>
18
+ <% status_path = conversation.open? ? resolve_conversation_path(conversation) : reopen_conversation_path(conversation) %>
19
+ <%= form_with url: status_path, method: :post, local: true, class: 'status-switch' do %>
19
20
  <% if conversation.open? %>
20
21
  <button type="button" class="status-open current" aria-current="true">
21
22
  <%= t('livechat.statuses.open', default: 'Open') %>
22
23
  </button>
23
- <button formaction="<%= resolve_conversation_path(conversation) %>" class="status-resolved">
24
+ <button type="submit" class="status-resolved">
24
25
  <%= t('livechat.statuses.resolved', default: 'Resolved') %>
25
26
  </button>
26
27
  <% else %>
27
- <button formaction="<%= reopen_conversation_path(conversation) %>" class="status-open">
28
+ <button type="submit" class="status-open">
28
29
  <%= t('livechat.statuses.open', default: 'Open') %>
29
30
  </button>
30
31
  <button type="button" class="status-resolved current" aria-current="true">
@@ -70,7 +71,7 @@
70
71
  <%# One bordered composer box (matches the visitor widget): the reply on top,
71
72
  a toolbar row below with tools on the left and send on the right. %>
72
73
  <%= form_with url: conversation_messages_path(conversation), method: :post,
73
- multipart: true, class: 'reply',
74
+ multipart: true, local: true, class: 'reply',
74
75
  data: {
75
76
  record_audio: t('livechat.dashboard.record_audio', default: 'Record audio'),
76
77
  stop_recording: t('livechat.dashboard.stop_recording', default: 'Stop recording'),
@@ -11,6 +11,6 @@
11
11
  ...and <%= @more_count %> more unread <%= @more_count == 1 ? 'reply' : 'replies' %>.
12
12
  <% end %>
13
13
 
14
- <% if @conversation.page_url.present? %>
15
- <%= t('livechat.mail.continue', default: 'Continue the conversation') %>: <%= @conversation.page_url %>
14
+ <% if @chat_url.present? %>
15
+ <%= t('livechat.mail.continue', default: 'Continue the conversation') %>: <%= @chat_url %>
16
16
  <% end %>
@@ -12,7 +12,7 @@ ar:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "حفظ"
14
14
  email_saved: "سنرد أيضًا عبر البريد الإلكتروني."
15
- event_resolved: "تم حل المحادثة"
15
+ event_resolved: "تم الحل حاليًا. أرسل رسالة أخرى متى احتجت إلى مساعدة."
16
16
  event_reopened: "تمت إعادة فتح المحادثة"
17
17
  error_send: "تعذر الإرسال. يرجى المحاولة مرة أخرى."
18
18
  error_rate_limited: "رسائل كثيرة جدًا. يرجى الانتظار قليلًا والمحاولة مرة أخرى."
@@ -29,6 +29,7 @@ ar:
29
29
  attachment_error: "تعذر إرسال بعض الملفات."
30
30
  expand: "تكبير"
31
31
  collapse: "تصغير"
32
+ open_page: "فتح كصفحة"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "ملفات كثيرة جدًا (بحد أقصى %{count})."
@@ -12,7 +12,7 @@ bg:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Запази"
14
14
  email_saved: "Ще отговорим и по имейл."
15
- event_resolved: "Разговорът е разрешен"
15
+ event_resolved: "Засега въпросът е решен. Изпратете ново съобщение, когато имате нужда от помощ."
16
16
  event_reopened: "Разговорът е отворен отново"
17
17
  error_send: "Изпращането не бе успешно. Моля, опитайте отново."
18
18
  error_rate_limited: "Твърде много съобщения. Моля, изчакайте малко и опитайте отново."
@@ -29,6 +29,7 @@ bg:
29
29
  attachment_error: "Някои файлове не можаха да бъдат изпратени."
30
30
  expand: "Уголеми"
31
31
  collapse: "Смали"
32
+ open_page: "Отвори като страница"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Твърде много файлове (макс. %{count})."
@@ -12,7 +12,7 @@ bn:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "সংরক্ষণ করুন"
14
14
  email_saved: "আমরা ইমেইলেও উত্তর দেব।"
15
- event_resolved: "কথোপকথন সমাধান হয়েছে"
15
+ event_resolved: "আপাতত সমাধান হয়েছে। সাহায্যের প্রয়োজন হলে আবার বার্তা পাঠান।"
16
16
  event_reopened: "কথোপকথন আবার খোলা হয়েছে"
17
17
  error_send: "পাঠানো যায়নি। অনুগ্রহ করে আবার চেষ্টা করুন।"
18
18
  error_rate_limited: "অনেক বেশি বার্তা। একটু অপেক্ষা করে আবার চেষ্টা করুন।"
@@ -29,6 +29,7 @@ bn:
29
29
  attachment_error: "কিছু ফাইল পাঠানো যায়নি।"
30
30
  expand: "বড় করুন"
31
31
  collapse: "ছোট করুন"
32
+ open_page: "পৃষ্ঠা হিসেবে খুলুন"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "অনেক বেশি ফাইল (সর্বোচ্চ %{count})।"
@@ -12,7 +12,7 @@ de:
12
12
  email_placeholder: "sie@beispiel.de"
13
13
  email_save: "Speichern"
14
14
  email_saved: "Wir antworten auch per E-Mail."
15
- event_resolved: "Unterhaltung gelöst"
15
+ event_resolved: "Vorerst erledigt. Schreib uns jederzeit wieder, wenn du Hilfe brauchst."
16
16
  event_reopened: "Unterhaltung wieder geöffnet"
17
17
  error_send: "Senden fehlgeschlagen. Bitte versuchen Sie es erneut."
18
18
  error_rate_limited: "Zu viele Nachrichten. Bitte warten Sie einen Moment und versuchen Sie es erneut."
@@ -29,6 +29,7 @@ de:
29
29
  attachment_error: "Einige Dateien konnten nicht gesendet werden."
30
30
  expand: "Vergrößern"
31
31
  collapse: "Verkleinern"
32
+ open_page: "Als Seite öffnen"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Zu viele Dateien (max. %{count})."
@@ -12,7 +12,7 @@ el:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Αποθήκευση"
14
14
  email_saved: "Θα απαντήσουμε επίσης μέσω email."
15
- event_resolved: "Η συνομιλία επιλύθηκε"
15
+ event_resolved: "Το θέμα λύθηκε προς το παρόν. Στείλτε νέο μήνυμα όποτε χρειαστείτε βοήθεια."
16
16
  event_reopened: "Η συνομιλία άνοιξε ξανά"
17
17
  error_send: "Δεν ήταν δυνατή η αποστολή. Δοκιμάστε ξανά."
18
18
  error_rate_limited: "Πάρα πολλά μηνύματα. Περιμένετε λίγο και δοκιμάστε ξανά."
@@ -29,6 +29,7 @@ el:
29
29
  attachment_error: "Ορισμένα αρχεία δεν ήταν δυνατό να σταλούν."
30
30
  expand: "Μεγέθυνση"
31
31
  collapse: "Σμίκρυνση"
32
+ open_page: "Άνοιγμα ως σελίδα"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Πάρα πολλά αρχεία (έως %{count})."
@@ -12,7 +12,7 @@ en:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Save"
14
14
  email_saved: "We will also reply by email."
15
- event_resolved: "Conversation resolved"
15
+ event_resolved: "Resolved for now. Send another message whenever you need help."
16
16
  event_reopened: "Conversation reopened"
17
17
  error_send: "Could not send. Please try again."
18
18
  error_rate_limited: "Too many messages. Please wait a moment and try again."
@@ -29,6 +29,7 @@ en:
29
29
  attachment_error: "Some files could not be sent."
30
30
  expand: "Expand"
31
31
  collapse: "Collapse"
32
+ open_page: "Open as a page"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Too many files (max %{count})."
@@ -12,7 +12,7 @@ es:
12
12
  email_placeholder: "tu@ejemplo.com"
13
13
  email_save: "Guardar"
14
14
  email_saved: "También te responderemos por correo."
15
- event_resolved: "Conversación resuelta"
15
+ event_resolved: "Resuelto por ahora. Envía otro mensaje cuando necesites ayuda."
16
16
  event_reopened: "Conversación reabierta"
17
17
  error_send: "No se pudo enviar. Inténtalo de nuevo."
18
18
  error_rate_limited: "Demasiados mensajes. Espera un momento e inténtalo de nuevo."
@@ -29,6 +29,7 @@ es:
29
29
  attachment_error: "No se pudieron enviar algunos archivos."
30
30
  expand: "Ampliar"
31
31
  collapse: "Reducir"
32
+ open_page: "Abrir como página"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Demasiados archivos (máx. %{count})."
@@ -12,7 +12,7 @@ fr:
12
12
  email_placeholder: "vous@exemple.fr"
13
13
  email_save: "Enregistrer"
14
14
  email_saved: "Nous répondrons également par e-mail."
15
- event_resolved: "Conversation résolue"
15
+ event_resolved: "Résolu pour le moment. Envoyez un autre message dès que vous avez besoin d’aide."
16
16
  event_reopened: "Conversation rouverte"
17
17
  error_send: "Échec de l'envoi. Veuillez réessayer."
18
18
  error_rate_limited: "Trop de messages. Veuillez patienter un instant et réessayer."
@@ -29,6 +29,7 @@ fr:
29
29
  attachment_error: "Certains fichiers n'ont pas pu être envoyés."
30
30
  expand: "Agrandir"
31
31
  collapse: "Réduire"
32
+ open_page: "Ouvrir en pleine page"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Trop de fichiers (max %{count})."
@@ -12,7 +12,7 @@ hi:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "सहेजें"
14
14
  email_saved: "हम ईमेल से भी जवाब देंगे।"
15
- event_resolved: "बातचीत सुलझा दी गई"
15
+ event_resolved: "फ़िलहाल समस्या हल हो गई है। जब भी मदद चाहिए, फिर से संदेश भेजें।"
16
16
  event_reopened: "बातचीत फिर से खोली गई"
17
17
  error_send: "भेजा नहीं जा सका। कृपया फिर से कोशिश करें।"
18
18
  error_rate_limited: "बहुत सारे संदेश। कृपया थोड़ी देर रुककर फिर से कोशिश करें।"
@@ -29,6 +29,7 @@ hi:
29
29
  attachment_error: "कुछ फ़ाइलें भेजी नहीं जा सकीं।"
30
30
  expand: "बड़ा करें"
31
31
  collapse: "छोटा करें"
32
+ open_page: "पेज के रूप में खोलें"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "बहुत सारी फ़ाइलें (अधिकतम %{count})।"