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
@@ -12,7 +12,7 @@ hr:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Spremi"
14
14
  email_saved: "Odgovorit ćemo i e-poštom."
15
- event_resolved: "Razgovor je riješen"
15
+ event_resolved: "Zasad je riješeno. Pošaljite novu poruku kad god trebate pomoć."
16
16
  event_reopened: "Razgovor je ponovno otvoren"
17
17
  error_send: "Slanje nije uspjelo. Pokušajte ponovno."
18
18
  error_rate_limited: "Previše poruka. Pričekajte trenutak i pokušajte ponovno."
@@ -29,6 +29,7 @@ hr:
29
29
  attachment_error: "Neke datoteke nije bilo moguće poslati."
30
30
  expand: "Povećaj"
31
31
  collapse: "Smanji"
32
+ open_page: "Otvori kao stranicu"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Previše datoteka (najviše %{count})."
@@ -12,7 +12,7 @@ id:
12
12
  email_placeholder: "anda@contoh.com"
13
13
  email_save: "Simpan"
14
14
  email_saved: "Kami juga akan membalas melalui email."
15
- event_resolved: "Percakapan selesai"
15
+ event_resolved: "Selesai untuk saat ini. Kirim pesan lagi kapan pun Anda membutuhkan bantuan."
16
16
  event_reopened: "Percakapan dibuka kembali"
17
17
  error_send: "Tidak dapat mengirim. Silakan coba lagi."
18
18
  error_rate_limited: "Terlalu banyak pesan. Mohon tunggu sebentar dan coba lagi."
@@ -29,6 +29,7 @@ id:
29
29
  attachment_error: "Beberapa file tidak dapat dikirim."
30
30
  expand: "Perbesar"
31
31
  collapse: "Perkecil"
32
+ open_page: "Buka sebagai halaman"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Terlalu banyak file (maks. %{count})."
@@ -12,7 +12,7 @@ it:
12
12
  email_placeholder: "tu@esempio.com"
13
13
  email_save: "Salva"
14
14
  email_saved: "Ti risponderemo anche via e-mail."
15
- event_resolved: "Conversazione risolta"
15
+ event_resolved: "Risolto per il momento. Invia un altro messaggio quando hai bisogno di aiuto."
16
16
  event_reopened: "Conversazione riaperta"
17
17
  error_send: "Invio non riuscito. Riprova."
18
18
  error_rate_limited: "Troppi messaggi. Attendi un momento e riprova."
@@ -29,6 +29,7 @@ it:
29
29
  attachment_error: "Non è stato possibile inviare alcuni file."
30
30
  expand: "Ingrandisci"
31
31
  collapse: "Riduci"
32
+ open_page: "Apri come pagina"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Troppi file (max %{count})."
@@ -12,7 +12,7 @@ ja:
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 @@ ja:
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 @@ ko:
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 @@ ko:
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 @@ lb:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Späicheren"
14
14
  email_saved: "Mir äntweren och per E-Mail."
15
- event_resolved: "Gespréich geléist"
15
+ event_resolved: "Fir de Moment geléist. Schéckt eng nei Noriicht, wann Dir Hëllef braucht."
16
16
  event_reopened: "Gespréich nees opgemaach"
17
17
  error_send: "Konnt net geschéckt ginn. Probéiert w.e.g. nach eng Kéier."
18
18
  error_rate_limited: "Ze vill Noriichten. Waart w.e.g. e Moment a probéiert nach eng Kéier."
@@ -29,6 +29,7 @@ lb:
29
29
  attachment_error: "E puer Dateie konnten net geschéckt ginn."
30
30
  expand: "Vergréisseren"
31
31
  collapse: "Verklengeren"
32
+ open_page: "Als Säit opmaachen"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Ze vill Dateien (max %{count})."
@@ -12,7 +12,7 @@ nl:
12
12
  email_placeholder: "jij@voorbeeld.nl"
13
13
  email_save: "Opslaan"
14
14
  email_saved: "We antwoorden ook per e-mail."
15
- event_resolved: "Gesprek opgelost"
15
+ event_resolved: "Voor nu opgelost. Stuur gerust een nieuw bericht als je hulp nodig hebt."
16
16
  event_reopened: "Gesprek heropend"
17
17
  error_send: "Versturen is niet gelukt. Probeer het opnieuw."
18
18
  error_rate_limited: "Te veel berichten. Wacht even en probeer het opnieuw."
@@ -29,6 +29,7 @@ nl:
29
29
  attachment_error: "Sommige bestanden konden niet worden verzonden."
30
30
  expand: "Vergroten"
31
31
  collapse: "Verkleinen"
32
+ open_page: "Openen als pagina"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Te veel bestanden (max. %{count})."
@@ -12,7 +12,7 @@ pl:
12
12
  email_placeholder: "ty@przyklad.pl"
13
13
  email_save: "Zapisz"
14
14
  email_saved: "Odpowiemy również e-mailem."
15
- event_resolved: "Rozmowa rozwiązana"
15
+ event_resolved: "Na razie sprawa jest rozwiązana. Napisz ponownie, gdy potrzebujesz pomocy."
16
16
  event_reopened: "Rozmowa wznowiona"
17
17
  error_send: "Nie udało się wysłać. Spróbuj ponownie."
18
18
  error_rate_limited: "Zbyt wiele wiadomości. Poczekaj chwilę i spróbuj ponownie."
@@ -29,6 +29,7 @@ pl:
29
29
  attachment_error: "Nie udało się wysłać niektórych plików."
30
30
  expand: "Powiększ"
31
31
  collapse: "Zmniejsz"
32
+ open_page: "Otwórz jako stronę"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Zbyt wiele plików (maks. %{count})."
@@ -12,7 +12,7 @@ pt:
12
12
  email_placeholder: "voce@exemplo.com"
13
13
  email_save: "Salvar"
14
14
  email_saved: "Também responderemos por e-mail."
15
- event_resolved: "Conversa resolvida"
15
+ event_resolved: "Resolvido por enquanto. Envie outra mensagem sempre que precisar de ajuda."
16
16
  event_reopened: "Conversa reaberta"
17
17
  error_send: "Não foi possível enviar. Tente novamente."
18
18
  error_rate_limited: "Muitas mensagens. Aguarde um momento e tente novamente."
@@ -29,6 +29,7 @@ pt:
29
29
  attachment_error: "Não foi possível enviar alguns arquivos."
30
30
  expand: "Ampliar"
31
31
  collapse: "Reduzir"
32
+ open_page: "Abrir como página"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Muitos arquivos (máx. %{count})."
@@ -12,7 +12,7 @@ ro:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Salvează"
14
14
  email_saved: "Vom răspunde și pe e-mail."
15
- event_resolved: "Conversație rezolvată"
15
+ event_resolved: "Rezolvat pentru moment. Trimiteți un alt mesaj când aveți nevoie de ajutor."
16
16
  event_reopened: "Conversație redeschisă"
17
17
  error_send: "Nu s-a putut trimite. Vă rugăm să încercați din nou."
18
18
  error_rate_limited: "Prea multe mesaje. Așteptați puțin și încercați din nou."
@@ -29,6 +29,7 @@ ro:
29
29
  attachment_error: "Unele fișiere nu au putut fi trimise."
30
30
  expand: "Mărește"
31
31
  collapse: "Micșorează"
32
+ open_page: "Deschide ca pagină"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Prea multe fișiere (max. %{count})."
@@ -12,7 +12,7 @@ ru:
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 @@ ru:
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 @@ th:
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 @@ th:
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 @@ tr:
12
12
  email_placeholder: "siz@ornek.com"
13
13
  email_save: "Kaydet"
14
14
  email_saved: "Ayrıca e-postayla da yanıtlayacağız."
15
- event_resolved: "Görüşme çözüldü"
15
+ event_resolved: "Şimdilik çözüldü. Yardıma ihtiyacınız olduğunda tekrar mesaj gönderin."
16
16
  event_reopened: "Görüşme yeniden açıldı"
17
17
  error_send: "Gönderilemedi. Lütfen tekrar deneyin."
18
18
  error_rate_limited: "Çok fazla mesaj. Lütfen biraz bekleyip tekrar deneyin."
@@ -29,6 +29,7 @@ tr:
29
29
  attachment_error: "Bazı dosyalar gönderilemedi."
30
30
  expand: "Büyüt"
31
31
  collapse: "Küçült"
32
+ open_page: "Sayfa olarak aç"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Çok fazla dosya (en fazla %{count})."
@@ -12,7 +12,7 @@ uk:
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 @@ uk:
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 @@ ur:
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 @@ ur:
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 @@ vi:
12
12
  email_placeholder: "you@example.com"
13
13
  email_save: "Lưu"
14
14
  email_saved: "Chúng tôi cũng sẽ trả lời qua email."
15
- event_resolved: "Cuộc trò chuyện đã được giải quyết"
15
+ event_resolved: "Tạm thời đã giải quyết xong. Hãy nhắn tin lại bất cứ khi nào bạn cần trợ giúp."
16
16
  event_reopened: "Cuộc trò chuyện đã được mở lại"
17
17
  error_send: "Không thể gửi. Vui lòng thử lại."
18
18
  error_rate_limited: "Quá nhiều tin nhắn. Vui lòng đợi một lát rồi thử lại."
@@ -29,6 +29,7 @@ vi:
29
29
  attachment_error: "Không thể gửi một số tệp."
30
30
  expand: "Mở rộng"
31
31
  collapse: "Thu gọn"
32
+ open_page: "Mở dưới dạng trang"
32
33
  typing: "%{name} is typing..."
33
34
  attachments:
34
35
  too_many: "Quá nhiều tệp (tối đa %{count})."
@@ -12,7 +12,7 @@
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 @@
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} 个)。"
data/config/routes.rb CHANGED
@@ -23,6 +23,10 @@ Livechat::Engine.routes.draw do
23
23
  # digits-only one would have made the tables bigint-only (see below).
24
24
  get 'attachments/:id', to: 'attachments#show', as: :attachment
25
25
 
26
+ # The visitor's chat as a page. No id: like the widget, it shows whoever
27
+ # loads it their own conversation. Above the catch-all for the same reason.
28
+ get 'chat', to: 'chat#show', as: :chat
29
+
26
30
  # The inbox. Flat, human URLs: the mount path IS the conversation list.
27
31
  # No `id: /\d+/` constraint: it made these routes bigint-only, which forced the
28
32
  # tables to be bigint too, and a uuid-keyed host could then never attach a file
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+ require_relative '../migration_helpers'
6
+
7
+ module Livechat
8
+ module Generators
9
+ # For apps that installed livechat before 1.4: adds the foreign key from
10
+ # livechat_messages.conversation_id to livechat_conversations. A fresh
11
+ # install already has it. Nothing in the engine changes behavior; the
12
+ # database just stops accepting a message for a conversation that does
13
+ # not exist.
14
+ #
15
+ # bin/rails generate livechat:foreign_key && bin/rails db:migrate
16
+ class ForeignKeyGenerator < Rails::Generators::Base
17
+ include ActiveRecord::Generators::Migration
18
+ include MigrationHelpers
19
+
20
+ source_root File.expand_path('templates', __dir__)
21
+
22
+ desc 'Adds the messages -> conversations foreign key to an existing livechat install.'
23
+
24
+ def create_migration_file
25
+ migration_template 'add_livechat_messages_conversation_foreign_key.rb.tt',
26
+ 'db/migrate/add_livechat_messages_conversation_foreign_key.rb'
27
+ end
28
+
29
+ def post_install
30
+ say "\nForeign key queued. Run `rails db:migrate`.", :green
31
+ say 'It fails if a message points at a conversation that no longer exists. Find those with:'
32
+ say ' Livechat::Message.where.not(conversation_id: Livechat::Conversation.select(:id))'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddLivechatMessagesConversationForeignKey < ActiveRecord::Migration<%= migration_version %>
4
+ <% if postgresql? -%>
5
+ disable_ddl_transaction!
6
+
7
+ def change
8
+ add_foreign_key :livechat_messages, :livechat_conversations, column: :conversation_id, validate: false
9
+ reversible { |direction| direction.up { validate_foreign_key :livechat_messages, :livechat_conversations } }
10
+ end
11
+ <% else -%>
12
+ def change
13
+ add_foreign_key :livechat_messages, :livechat_conversations, column: :conversation_id
14
+ end
15
+ <% end -%>
16
+ end
@@ -23,7 +23,8 @@ class CreateLivechatTables < ActiveRecord::Migration<%= migration_version %>
23
23
  create_table :livechat_messages<%= primary_key_type_option %> do |t|
24
24
  # index: false — the (conversation_id, id) index below already covers
25
25
  # lookups by conversation_id, being a leftmost prefix of it.
26
- t.references :conversation, null: false, index: false<%= foreign_key_type_option %>
26
+ t.references :conversation, null: false, index: false<%= foreign_key_type_option %>,
27
+ foreign_key: { to_table: :livechat_conversations }
27
28
  t.string :author_type, null: false
28
29
  t.string :agent_id
29
30
  t.string :agent_label
@@ -95,6 +95,11 @@ Livechat.configure do |config|
95
95
  # config.action_cable = true
96
96
  # config.action_cable_url = "/cable"
97
97
 
98
+ # The chat as a page of its own, at /livechat/chat by default: a URL the
99
+ # visitor can bookmark, opened from the panel and the reply email. Point it
100
+ # at a page of yours rendering `livechat_chat`, or false to turn it off.
101
+ # config.chat_path = "/support"
102
+
98
103
  # Default mount path used by `mount_livechat`.
99
104
  # Override only if you mount the engine manually.
100
105
  # config.mount_path = "/livechat"
@@ -38,6 +38,18 @@ module Livechat
38
38
  config = Rails.configuration.generators
39
39
  config.options[config.orm][:primary_key_type]
40
40
  end
41
+
42
+ # Adding a foreign key to a table that already holds rows validates every
43
+ # row while it locks out writes. On PostgreSQL the key can go in
44
+ # unvalidated and be validated in a second statement that does not block
45
+ # writes, which is also the only shape strong_migrations accepts. That
46
+ # second statement must run outside the migration's transaction.
47
+ #
48
+ # Decided at generate time, like the key type, so the migration holds
49
+ # plain code rather than an adapter check.
50
+ def postgresql?
51
+ ActiveRecord::Base.connection_db_config.adapter.to_s.include?('postg')
52
+ end
41
53
  end
42
54
  end
43
55
  end
@@ -143,6 +143,16 @@ module Livechat
143
143
  # this in sync with the `mount` line in your routes.
144
144
  attr_accessor :mount_path
145
145
 
146
+ # The chat as a page of its own — a URL a visitor can bookmark, that the
147
+ # reply email links to, and that the panel's "open as a page" icon opens.
148
+ # It shows whoever loads it their own conversation, resolved the same way
149
+ # the widget resolves it (signed-in id or guest cookie); the URL never
150
+ # names a conversation. nil serves the engine's page at
151
+ # `<mount_path>/chat`. A path or URL of your own (a page rendering
152
+ # `livechat_chat` in your layout) takes its place, and the engine's page
153
+ # redirects there. false turns the page off.
154
+ attr_accessor :chat_path
155
+
146
156
  def initialize
147
157
  @app_name = nil
148
158
  @enabled = ->(_request) { true }
@@ -166,6 +176,7 @@ module Livechat
166
176
  @on_agent_message = ->(_message) {}
167
177
  @rate_limit = { to: 30, within: 60 }
168
178
  @mount_path = '/livechat'
179
+ @chat_path = nil
169
180
  @attach_files = true
170
181
  @storage_service = nil
171
182
  @max_attachments = 5
@@ -177,6 +188,9 @@ module Livechat
177
188
 
178
189
  def widget_endpoint = "#{mount_path.chomp('/')}/widget"
179
190
 
191
+ # The engine's own chat page, whatever chat_path says.
192
+ def engine_chat_path = "#{mount_path.chomp('/')}/chat"
193
+
180
194
  def agent_email_list
181
195
  list = agent_emails
182
196
  list = list.call if list.respond_to?(:call)
@@ -2,10 +2,9 @@
2
2
  * livechat dashboard — the little JavaScript the inbox needs, served as a
3
3
  * same-origin script so it works under strict CSPs (no inline handlers).
4
4
  *
5
- * On a conversation page it polls for new messages every few seconds. If the
6
- * reply box is empty the page just reloads to show them; if the agent is
7
- * mid-sentence it shows a "New messages" link instead — a reload must never
8
- * eat a half-written reply. Cmd/Ctrl+Enter sends.
5
+ * Thread polling appends new messages without disturbing a reply draft.
6
+ * The inbox list reloads only while the agent is not typing or searching.
7
+ * Cmd/Ctrl+Enter sends; submitting a reply restores focus after navigation.
9
8
  */
10
9
  (function () {
11
10
  "use strict";
@@ -359,6 +358,18 @@
359
358
  thread.appendChild(typingEl);
360
359
 
361
360
  if (replyBox) {
361
+ // Remember only the form destination for one navigation, not a draft.
362
+ // Ordinary visits to the split-pane inbox keep their existing focus.
363
+ var focusKey = "livechat:reply-focus";
364
+ try {
365
+ var focusAction = window.sessionStorage.getItem(focusKey);
366
+ window.sessionStorage.removeItem(focusKey);
367
+ if (focusAction === replyBox.form.action) replyBox.focus();
368
+ } catch (e) { /* storage may be disabled; the reply still submits */ }
369
+ replyBox.form.addEventListener("submit", function () {
370
+ try { window.sessionStorage.setItem(focusKey, replyBox.form.action); }
371
+ catch (e) { /* storage may be disabled */ }
372
+ });
362
373
  replyBox.addEventListener("keydown", function (event) {
363
374
  if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
364
375
  event.preventDefault();
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Livechat
4
- VERSION = '1.2.0'
4
+ VERSION = '1.4.0'
5
5
  end