From d319e63607b0cd6f85455ec02c17ec105bae1e75 Mon Sep 17 00:00:00 2001 From: oguhpereira Date: Tue, 14 Jul 2020 20:47:42 -0300 Subject: [PATCH 1/5] [FEAT] Configurable character limit on live chat * added new input for character limit setting --- .../client/views/app/livechatAppearance.html | 4 ++++ app/livechat/client/views/app/livechatAppearance.js | 13 +++++++++++++ app/livechat/server/api/lib/appearance.js | 1 + app/livechat/server/api/lib/livechat.js | 1 + app/livechat/server/config.js | 7 +++++++ app/livechat/server/lib/Livechat.js | 1 + app/livechat/server/methods/getInitialData.js | 1 + app/livechat/server/methods/saveAppearance.js | 1 + 8 files changed, 29 insertions(+) diff --git a/app/livechat/client/views/app/livechatAppearance.html b/app/livechat/client/views/app/livechatAppearance.html index 531bbfabbe4e..4fe3c858d445 100644 --- a/app/livechat/client/views/app/livechatAppearance.html +++ b/app/livechat/client/views/app/livechatAppearance.html @@ -16,6 +16,10 @@

{{_ "Settings"}}

+
+ + +
diff --git a/app/livechat/client/views/app/livechatAppearance.js b/app/livechat/client/views/app/livechatAppearance.js index 6fcca80a9e1b..8756bec15b48 100644 --- a/app/livechat/client/views/app/livechatAppearance.js +++ b/app/livechat/client/views/app/livechatAppearance.js @@ -11,6 +11,9 @@ import { APIClient } from '../../../../utils/client'; const getSettingFromAppearance = (instance, settingName) => instance.appearance.get() && instance.appearance.get().find((setting) => setting._id === settingName); Template.livechatAppearance.helpers({ + limitTextLength() { + return Template.instance().limitTextLength.get(); + }, color() { return Template.instance().color.get(); }, @@ -110,6 +113,7 @@ Template.livechatAppearance.onCreated(async function() { this.appearance = new ReactiveVar([]); this.title = new ReactiveVar(null); this.color = new ReactiveVar(null); + this.limitTextLength = new ReactiveVar(null); this.showAgentInfo = new ReactiveVar(null); this.showAgentEmail = new ReactiveVar(null); @@ -132,6 +136,7 @@ Template.livechatAppearance.onCreated(async function() { const livechatTitle = getSettingFromAppearance(this, 'Livechat_title'); const livechatTitleColor = getSettingFromAppearance(this, 'Livechat_title_color'); + const livechatTitleLimitTextLength = getSettingFromAppearance(this, 'Livechat_title_character_limit'); const livechatShowAgentInfo = getSettingFromAppearance(this, 'Livechat_show_agent_info'); const livechatShowAgentEmail = getSettingFromAppearance(this, 'Livechat_show_agent_email'); const livechatDisplayOfflineForm = getSettingFromAppearance(this, 'Livechat_display_offline_form'); @@ -150,6 +155,7 @@ Template.livechatAppearance.onCreated(async function() { this.title.set(livechatTitle && livechatTitle.value); this.color.set(livechatTitleColor && livechatTitleColor.value); + this.limitTextLength.set(livechatTitleLimitTextLength && livechatTitleLimitTextLength.value); this.showAgentInfo.set(livechatShowAgentInfo && livechatShowAgentInfo.value); this.showAgentEmail.set(livechatShowAgentEmail && livechatShowAgentEmail.value); this.displayOfflineForm.set(livechatDisplayOfflineForm && livechatDisplayOfflineForm.value); @@ -187,6 +193,9 @@ Template.livechatAppearance.events({ const settingTitleColor = getSettingFromAppearance(instance, 'Livechat_title_color'); instance.color.set(settingTitleColor && settingTitleColor.value); + const settingTitleLimitTextLength = getSettingFromAppearance(instance, 'Livechat_title_character_limit'); + instance.limitTextLength.set(settingTitleLimitTextLength && settingTitleLimitTextLength.value); + const settingShowAgentInfo = getSettingFromAppearance(instance, 'Livechat_show_agent_info'); instance.showAgentInfo.set(settingShowAgentInfo && settingShowAgentInfo.value); @@ -240,6 +249,10 @@ Template.livechatAppearance.events({ _id: 'Livechat_title_color', value: instance.color.get(), }, + { + _id: 'Livechat_title_character_limit', + value: instance.limitTextLength.get(), + }, { _id: 'Livechat_show_agent_info', value: instance.showAgentInfo.get(), diff --git a/app/livechat/server/api/lib/appearance.js b/app/livechat/server/api/lib/appearance.js index 8d2f6b79963c..ef5265be0d16 100644 --- a/app/livechat/server/api/lib/appearance.js +++ b/app/livechat/server/api/lib/appearance.js @@ -10,6 +10,7 @@ export async function findAppearance({ userId }) { $in: [ 'Livechat_title', 'Livechat_title_color', + 'Livechat_title_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', 'Livechat_display_offline_form', diff --git a/app/livechat/server/api/lib/livechat.js b/app/livechat/server/api/lib/livechat.js index 4626ce819b35..a1f4572aa87f 100644 --- a/app/livechat/server/api/lib/livechat.js +++ b/app/livechat/server/api/lib/livechat.js @@ -111,6 +111,7 @@ export function settings() { forceAcceptDataProcessingConsent: initSettings.Livechat_force_accept_data_processing_consent, showConnecting: initSettings.Livechat_Show_Connecting, agentHiddenInfo: initSettings.Livechat_show_agent_info === false, + limitTextLength: parseInt(initSettings.Livechat_title_character_limit), }, theme: { title: initSettings.Livechat_title, diff --git a/app/livechat/server/config.js b/app/livechat/server/config.js index 780425f68b29..507fd5f02118 100644 --- a/app/livechat/server/config.js +++ b/app/livechat/server/config.js @@ -27,6 +27,13 @@ Meteor.startup(function() { public: true, }); + settings.add('Livechat_title_character_limit', null, { + type: 'int', + group: 'Omnichannel', + section: 'Livechat', + public: true, + }); + settings.add('Livechat_display_offline_form', true, { type: 'boolean', group: 'Omnichannel', diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index 0214768ee06b..a277bb9dcf00 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -428,6 +428,7 @@ export const Livechat = { Settings.findNotHiddenPublic([ 'Livechat_title', 'Livechat_title_color', + 'Livechat_title_character_limit', 'Livechat_enabled', 'Livechat_registration_form', 'Livechat_allow_switching_departments', diff --git a/app/livechat/server/methods/getInitialData.js b/app/livechat/server/methods/getInitialData.js index 9b7a2f22a705..e9022ec8bc4e 100644 --- a/app/livechat/server/methods/getInitialData.js +++ b/app/livechat/server/methods/getInitialData.js @@ -66,6 +66,7 @@ Meteor.methods({ info.title = initSettings.Livechat_title; info.color = initSettings.Livechat_title_color; + info.limitTextLength = initSettings.Livechat_title_character_limit; info.enabled = initSettings.Livechat_enabled; info.registrationForm = initSettings.Livechat_registration_form; info.offlineTitle = initSettings.Livechat_offline_title; diff --git a/app/livechat/server/methods/saveAppearance.js b/app/livechat/server/methods/saveAppearance.js index 99e57ce6ef2e..708355f725ef 100644 --- a/app/livechat/server/methods/saveAppearance.js +++ b/app/livechat/server/methods/saveAppearance.js @@ -12,6 +12,7 @@ Meteor.methods({ const validSettings = [ 'Livechat_title', 'Livechat_title_color', + 'Livechat_title_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', 'Livechat_display_offline_form', From be43cf1037149bf5550c436e0ef7902603d3a0dc Mon Sep 17 00:00:00 2001 From: oguhpereira Date: Mon, 27 Jul 2020 23:26:00 -0300 Subject: [PATCH 2/5] [FIX] Configurable character limit on live chat * Adding translation * Changing label to Livechat_message_character_limit * Removing unused function --- app/livechat/client/views/app/livechatAppearance.html | 2 +- app/livechat/client/views/app/livechatAppearance.js | 10 +++++----- app/livechat/server/api/lib/appearance.js | 2 +- app/livechat/server/api/lib/livechat.js | 2 +- app/livechat/server/config.js | 2 +- app/livechat/server/lib/Livechat.js | 2 +- app/livechat/server/methods/getInitialData.js | 1 - app/livechat/server/methods/saveAppearance.js | 2 +- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 1 + packages/rocketchat-i18n/i18n/pt.i18n.json | 1 + 11 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/livechat/client/views/app/livechatAppearance.html b/app/livechat/client/views/app/livechatAppearance.html index 4fe3c858d445..ca0077ac0321 100644 --- a/app/livechat/client/views/app/livechatAppearance.html +++ b/app/livechat/client/views/app/livechatAppearance.html @@ -17,7 +17,7 @@

{{_ "Settings"}}

- +
diff --git a/app/livechat/client/views/app/livechatAppearance.js b/app/livechat/client/views/app/livechatAppearance.js index 8756bec15b48..40aef1d0e764 100644 --- a/app/livechat/client/views/app/livechatAppearance.js +++ b/app/livechat/client/views/app/livechatAppearance.js @@ -136,7 +136,7 @@ Template.livechatAppearance.onCreated(async function() { const livechatTitle = getSettingFromAppearance(this, 'Livechat_title'); const livechatTitleColor = getSettingFromAppearance(this, 'Livechat_title_color'); - const livechatTitleLimitTextLength = getSettingFromAppearance(this, 'Livechat_title_character_limit'); + const livechatMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_message_character_limit'); const livechatShowAgentInfo = getSettingFromAppearance(this, 'Livechat_show_agent_info'); const livechatShowAgentEmail = getSettingFromAppearance(this, 'Livechat_show_agent_email'); const livechatDisplayOfflineForm = getSettingFromAppearance(this, 'Livechat_display_offline_form'); @@ -155,7 +155,7 @@ Template.livechatAppearance.onCreated(async function() { this.title.set(livechatTitle && livechatTitle.value); this.color.set(livechatTitleColor && livechatTitleColor.value); - this.limitTextLength.set(livechatTitleLimitTextLength && livechatTitleLimitTextLength.value); + this.limitTextLength.set(livechatMessageCharacterLimit && livechatMessageCharacterLimit.value); this.showAgentInfo.set(livechatShowAgentInfo && livechatShowAgentInfo.value); this.showAgentEmail.set(livechatShowAgentEmail && livechatShowAgentEmail.value); this.displayOfflineForm.set(livechatDisplayOfflineForm && livechatDisplayOfflineForm.value); @@ -193,8 +193,8 @@ Template.livechatAppearance.events({ const settingTitleColor = getSettingFromAppearance(instance, 'Livechat_title_color'); instance.color.set(settingTitleColor && settingTitleColor.value); - const settingTitleLimitTextLength = getSettingFromAppearance(instance, 'Livechat_title_character_limit'); - instance.limitTextLength.set(settingTitleLimitTextLength && settingTitleLimitTextLength.value); + const settinglivechatMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_message_character_limit'); + instance.limitTextLength.set(settinglivechatMessageCharacterLimit && settinglivechatMessageCharacterLimit.value); const settingShowAgentInfo = getSettingFromAppearance(instance, 'Livechat_show_agent_info'); instance.showAgentInfo.set(settingShowAgentInfo && settingShowAgentInfo.value); @@ -250,7 +250,7 @@ Template.livechatAppearance.events({ value: instance.color.get(), }, { - _id: 'Livechat_title_character_limit', + _id: 'Livechat_message_character_limit', value: instance.limitTextLength.get(), }, { diff --git a/app/livechat/server/api/lib/appearance.js b/app/livechat/server/api/lib/appearance.js index ef5265be0d16..5985c8236822 100644 --- a/app/livechat/server/api/lib/appearance.js +++ b/app/livechat/server/api/lib/appearance.js @@ -10,7 +10,7 @@ export async function findAppearance({ userId }) { $in: [ 'Livechat_title', 'Livechat_title_color', - 'Livechat_title_character_limit', + 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', 'Livechat_display_offline_form', diff --git a/app/livechat/server/api/lib/livechat.js b/app/livechat/server/api/lib/livechat.js index a1f4572aa87f..dbf7197d6904 100644 --- a/app/livechat/server/api/lib/livechat.js +++ b/app/livechat/server/api/lib/livechat.js @@ -111,7 +111,7 @@ export function settings() { forceAcceptDataProcessingConsent: initSettings.Livechat_force_accept_data_processing_consent, showConnecting: initSettings.Livechat_Show_Connecting, agentHiddenInfo: initSettings.Livechat_show_agent_info === false, - limitTextLength: parseInt(initSettings.Livechat_title_character_limit), + limitTextLength: parseInt(initSettings.Livechat_message_character_limit), }, theme: { title: initSettings.Livechat_title, diff --git a/app/livechat/server/config.js b/app/livechat/server/config.js index 507fd5f02118..1b1df0c58992 100644 --- a/app/livechat/server/config.js +++ b/app/livechat/server/config.js @@ -27,7 +27,7 @@ Meteor.startup(function() { public: true, }); - settings.add('Livechat_title_character_limit', null, { + settings.add('Livechat_message_character_limit', 0, { type: 'int', group: 'Omnichannel', section: 'Livechat', diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index c75eff1f35de..ea80f15716b9 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -428,7 +428,7 @@ export const Livechat = { Settings.findNotHiddenPublic([ 'Livechat_title', 'Livechat_title_color', - 'Livechat_title_character_limit', + 'Livechat_message_character_limit', 'Livechat_enabled', 'Livechat_registration_form', 'Livechat_allow_switching_departments', diff --git a/app/livechat/server/methods/getInitialData.js b/app/livechat/server/methods/getInitialData.js index e9022ec8bc4e..9b7a2f22a705 100644 --- a/app/livechat/server/methods/getInitialData.js +++ b/app/livechat/server/methods/getInitialData.js @@ -66,7 +66,6 @@ Meteor.methods({ info.title = initSettings.Livechat_title; info.color = initSettings.Livechat_title_color; - info.limitTextLength = initSettings.Livechat_title_character_limit; info.enabled = initSettings.Livechat_enabled; info.registrationForm = initSettings.Livechat_registration_form; info.offlineTitle = initSettings.Livechat_offline_title; diff --git a/app/livechat/server/methods/saveAppearance.js b/app/livechat/server/methods/saveAppearance.js index 708355f725ef..8f6e73b1ce8c 100644 --- a/app/livechat/server/methods/saveAppearance.js +++ b/app/livechat/server/methods/saveAppearance.js @@ -12,7 +12,7 @@ Meteor.methods({ const validSettings = [ 'Livechat_title', 'Livechat_title_color', - 'Livechat_title_character_limit', + 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', 'Livechat_display_offline_form', diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index d67614ef3b0a..cd9559d34497 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2271,6 +2271,7 @@ "Livechat_Take_Confirm": "Do you want to take this client?", "Livechat_title": "Livechat Title", "Livechat_title_color": "Livechat Title Background Color", + "Livechat_message_character_limit": "Livechat message character limit", "Livechat_transcript_already_requested_warning": "The transcript of this chat has already been requested and will be sent as soon as the conversation ends.", "Livechat_transcript_request_has_been_canceled": "The chat transcription request has been canceled.", "Livechat_transcript_has_been_requested": "The chat transcript has been requested.", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index bdd58b9d87e3..ea593425fbdd 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2016,6 +2016,7 @@ "Livechat_Take_Confirm": "Você quer levar esse cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", + "Livechat_message_character_limit": "Limite de caracteres da mensagem de livechat", "Livechat_transcript_already_requested_warning": "A transcrição deste bate-papo já foi solicitada e será enviada assim que a conversa for encerrada.", "Livechat_transcript_request_has_been_canceled": "A requisição de transcrição do bate-papo foi cancelada.", "Livechat_transcript_has_been_requested": "A transcrição do bate-papo foi requisitada.", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index 19ea03e9b024..08f0776d5fa0 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -1894,6 +1894,7 @@ "Livechat_Take_Confirm": "Quer levar este cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", + "Livechat_message_character_limit": "Limite de caracteres da mensagem de livechat", "Livechat_transcript_sent": "Transcrição de Livechat enviada", "Livechat_Users": "Utilizadores Livechat", "LiveStream & Broadcasting": "Livestream e Broadcasting", From 570fa49c7c7516f88dec57573d7b9c3c5649f50d Mon Sep 17 00:00:00 2001 From: oguhpereira Date: Tue, 28 Jul 2020 21:22:30 -0300 Subject: [PATCH 3/5] [FEAT] Message_Characther_Limit Translation --- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 1 + packages/rocketchat-i18n/i18n/pt.i18n.json | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 9881e76ba547..8a07e8b2affc 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2444,6 +2444,7 @@ "Message_AudioRecorderEnabled_Description": "Requires 'audio/mp3' files to be an accepted media type within 'File Upload' settings.", "Message_BadWordsFilterList": "Add Bad Words to the Blacklist", "Message_BadWordsFilterListDescription": "Add List of Comma-separated list of bad words to filter", + "Message_Characther_Limit": "Message Characther Limit", "MessageBox_view_mode": "MessageBox View Mode", "message_counter": "__counter__ message", "message_counter_plural": "__counter__ messages", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index ea593425fbdd..c4a5ba5f50be 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2169,6 +2169,7 @@ "Message_AudioRecorderEnabled_Description": "Requer arquivos 'audio / mp3' para ser um tipo de mídia aceito dentro das configurações 'Upload de arquivo'.", "Message_BadWordsFilterList": "Adicione palavrões para a lista negra", "Message_BadWordsFilterListDescription": "Adicione palavrões separados por vírgula para filtrar", + "Message_Characther_Limit": "Limite do caráter da mensagem", "message_counter": "__counter__ mensagem", "message_counter_plural": "__counter__ mensagens", "Message_DateFormat": "Formato de Data", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index 08f0776d5fa0..6ae317395741 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -2022,6 +2022,7 @@ "Message_AudioRecorderEnabled_Description": "Requer arquivos 'áudio / mp3' para ser um tipo de leitor aceite dentro das configurações 'Carregar ficheiro'.", "Message_BadWordsFilterList": "Adicione palavrões para a lista negra", "Message_BadWordsFilterListDescription": "Adicione palavrões separados por vírgula para filtrar", + "Message_Characther_Limit": "Limite do caráter da mensagem", "Message_DateFormat": "Formato de Data", "Message_DateFormat_Description": "Veja também: Moment.js", "Message_deleting_blocked": "Esta mensagem não pode ser mais apagada", From fc173a007026b245747ad5f62d42c0c79abdbf5c Mon Sep 17 00:00:00 2001 From: oguhpereira Date: Fri, 31 Jul 2020 22:34:58 -0300 Subject: [PATCH 4/5] [FEAT] Configurable Character Limit * adding new option to display character limit * Validating if the limitTextLength is greater than Message_MaxAllowedSizeimport * setting Message_MaxAllowedSizeimport as the default of limitTextLength --- .../client/views/app/livechatAppearance.html | 9 +++++++++ .../client/views/app/livechatAppearance.js | 14 +++++++++++++- app/livechat/server/api/lib/appearance.js | 1 + app/livechat/server/api/lib/livechat.js | 17 ++++++++++++++++- app/livechat/server/config.js | 7 +++++++ app/livechat/server/lib/Livechat.js | 1 + app/livechat/server/methods/saveAppearance.js | 1 + packages/rocketchat-i18n/i18n/en.i18n.json | 1 + packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 3 ++- packages/rocketchat-i18n/i18n/pt.i18n.json | 3 ++- 10 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/livechat/client/views/app/livechatAppearance.html b/app/livechat/client/views/app/livechatAppearance.html index ca0077ac0321..84191f086d78 100644 --- a/app/livechat/client/views/app/livechatAppearance.html +++ b/app/livechat/client/views/app/livechatAppearance.html @@ -16,6 +16,15 @@

{{_ "Settings"}}

+
+ +
+ + + + +
+
diff --git a/app/livechat/client/views/app/livechatAppearance.js b/app/livechat/client/views/app/livechatAppearance.js index 40aef1d0e764..91be60cd1b51 100644 --- a/app/livechat/client/views/app/livechatAppearance.js +++ b/app/livechat/client/views/app/livechatAppearance.js @@ -11,6 +11,9 @@ import { APIClient } from '../../../../utils/client'; const getSettingFromAppearance = (instance, settingName) => instance.appearance.get() && instance.appearance.get().find((setting) => setting._id === settingName); Template.livechatAppearance.helpers({ + showLimitTextLength() { + return Template.instance().showLimitTextLength.get(); + }, limitTextLength() { return Template.instance().limitTextLength.get(); }, @@ -113,8 +116,8 @@ Template.livechatAppearance.onCreated(async function() { this.appearance = new ReactiveVar([]); this.title = new ReactiveVar(null); this.color = new ReactiveVar(null); + this.showLimitTextLength = new ReactiveVar(null); this.limitTextLength = new ReactiveVar(null); - this.showAgentInfo = new ReactiveVar(null); this.showAgentEmail = new ReactiveVar(null); this.displayOfflineForm = new ReactiveVar(null); @@ -136,6 +139,7 @@ Template.livechatAppearance.onCreated(async function() { const livechatTitle = getSettingFromAppearance(this, 'Livechat_title'); const livechatTitleColor = getSettingFromAppearance(this, 'Livechat_title_color'); + const livechatShowMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_show_message_character_limit'); const livechatMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_message_character_limit'); const livechatShowAgentInfo = getSettingFromAppearance(this, 'Livechat_show_agent_info'); const livechatShowAgentEmail = getSettingFromAppearance(this, 'Livechat_show_agent_email'); @@ -155,6 +159,7 @@ Template.livechatAppearance.onCreated(async function() { this.title.set(livechatTitle && livechatTitle.value); this.color.set(livechatTitleColor && livechatTitleColor.value); + this.showLimitTextLength.set(livechatShowMessageCharacterLimit && livechatShowMessageCharacterLimit.value); this.limitTextLength.set(livechatMessageCharacterLimit && livechatMessageCharacterLimit.value); this.showAgentInfo.set(livechatShowAgentInfo && livechatShowAgentInfo.value); this.showAgentEmail.set(livechatShowAgentEmail && livechatShowAgentEmail.value); @@ -193,6 +198,9 @@ Template.livechatAppearance.events({ const settingTitleColor = getSettingFromAppearance(instance, 'Livechat_title_color'); instance.color.set(settingTitleColor && settingTitleColor.value); + const settinglivechatShowMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_show_message_character_limit'); + instance.showLimitTextLength.set(settinglivechatShowMessageCharacterLimit && settinglivechatShowMessageCharacterLimit.value); + const settinglivechatMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_message_character_limit'); instance.limitTextLength.set(settinglivechatMessageCharacterLimit && settinglivechatMessageCharacterLimit.value); @@ -249,6 +257,10 @@ Template.livechatAppearance.events({ _id: 'Livechat_title_color', value: instance.color.get(), }, + { + _id: 'Livechat_show_message_character_limit', + value: instance.showLimitTextLength.get(), + }, { _id: 'Livechat_message_character_limit', value: instance.limitTextLength.get(), diff --git a/app/livechat/server/api/lib/appearance.js b/app/livechat/server/api/lib/appearance.js index 5985c8236822..b1524355cfb6 100644 --- a/app/livechat/server/api/lib/appearance.js +++ b/app/livechat/server/api/lib/appearance.js @@ -10,6 +10,7 @@ export async function findAppearance({ userId }) { $in: [ 'Livechat_title', 'Livechat_title_color', + 'Livechat_show_message_character_limit', 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', diff --git a/app/livechat/server/api/lib/livechat.js b/app/livechat/server/api/lib/livechat.js index dbf7197d6904..2c3e9b56f0c4 100644 --- a/app/livechat/server/api/lib/livechat.js +++ b/app/livechat/server/api/lib/livechat.js @@ -6,6 +6,7 @@ import { LivechatRooms, LivechatVisitors, LivechatDepartment, LivechatTrigger } import { Livechat } from '../../lib/Livechat'; import { callbacks } from '../../../../callbacks/server'; import { normalizeAgent } from '../../lib/Helper'; +import { settings as ClientSettings } from '../../../../settings'; export function online(department) { return Livechat.online(department); @@ -66,6 +67,19 @@ export function findOpenRoom(token, departmentId) { return room; } +export function findLimitTextLength({ Livechat_show_message_character_limit, Livechat_message_character_limit}) { + if (!Livechat_show_message_character_limit) { + return false; + } + const messageMaxAllowedSize = ClientSettings.get('Message_MaxAllowedSize'); + + if (Livechat_message_character_limit && messageMaxAllowedSize > Livechat_message_character_limit) { + return Livechat_message_character_limit; + } + + return messageMaxAllowedSize; +} + export function getRoom({ guest, rid, roomInfo, agent, extraParams }) { const token = guest && guest.token; @@ -94,6 +108,7 @@ export function settings() { const departments = findDepartments(); const sound = `${ Meteor.absoluteUrl() }sounds/chime.mp3`; const emojis = Meteor.call('listEmojiCustom'); + const limitTextLength = findLimitTextLength(initSettings); return { enabled: initSettings.Livechat_enabled, @@ -111,7 +126,7 @@ export function settings() { forceAcceptDataProcessingConsent: initSettings.Livechat_force_accept_data_processing_consent, showConnecting: initSettings.Livechat_Show_Connecting, agentHiddenInfo: initSettings.Livechat_show_agent_info === false, - limitTextLength: parseInt(initSettings.Livechat_message_character_limit), + limitTextLength, }, theme: { title: initSettings.Livechat_title, diff --git a/app/livechat/server/config.js b/app/livechat/server/config.js index 1b1df0c58992..2d7a2b3fcb7a 100644 --- a/app/livechat/server/config.js +++ b/app/livechat/server/config.js @@ -27,6 +27,13 @@ Meteor.startup(function() { public: true, }); + settings.add('Livechat_show_message_character_limit', false, { + type: 'int', + group: 'Omnichannel', + section: 'Livechat', + public: true, + }); + settings.add('Livechat_message_character_limit', 0, { type: 'int', group: 'Omnichannel', diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index ea80f15716b9..17d0af3bc489 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -428,6 +428,7 @@ export const Livechat = { Settings.findNotHiddenPublic([ 'Livechat_title', 'Livechat_title_color', + 'Livechat_show_message_character_limit', 'Livechat_message_character_limit', 'Livechat_enabled', 'Livechat_registration_form', diff --git a/app/livechat/server/methods/saveAppearance.js b/app/livechat/server/methods/saveAppearance.js index 8f6e73b1ce8c..b03005fe8d76 100644 --- a/app/livechat/server/methods/saveAppearance.js +++ b/app/livechat/server/methods/saveAppearance.js @@ -12,6 +12,7 @@ Meteor.methods({ const validSettings = [ 'Livechat_title', 'Livechat_title_color', + 'Livechat_show_message_character_limit', 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 8a07e8b2affc..3b83ccc66239 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2272,6 +2272,7 @@ "Livechat_Take_Confirm": "Do you want to take this client?", "Livechat_title": "Livechat Title", "Livechat_title_color": "Livechat Title Background Color", + "Livechat_show_message_character_limit": "Livechat message character limit", "Livechat_message_character_limit": "Livechat message character limit", "Livechat_transcript_already_requested_warning": "The transcript of this chat has already been requested and will be sent as soon as the conversation ends.", "Livechat_transcript_request_has_been_canceled": "The chat transcription request has been canceled.", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index c4a5ba5f50be..64779bc7ed71 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2016,7 +2016,8 @@ "Livechat_Take_Confirm": "Você quer levar esse cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", - "Livechat_message_character_limit": "Limite de caracteres da mensagem de livechat", + "Livechat_show_message_character_limit": "Exibir Limite de caracteres da mensagem no livechat", + "Livechat_message_character_limit": "Limite de caracteres da mensagem no livechat", "Livechat_transcript_already_requested_warning": "A transcrição deste bate-papo já foi solicitada e será enviada assim que a conversa for encerrada.", "Livechat_transcript_request_has_been_canceled": "A requisição de transcrição do bate-papo foi cancelada.", "Livechat_transcript_has_been_requested": "A transcrição do bate-papo foi requisitada.", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index 6ae317395741..ef2872ced037 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -1894,7 +1894,8 @@ "Livechat_Take_Confirm": "Quer levar este cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", - "Livechat_message_character_limit": "Limite de caracteres da mensagem de livechat", + "Livechat_show_message_character_limit": "Exibir Limite de caracteres da mensagem no livechat", + "Livechat_message_character_limit": "Limite de caracteres da mensagem no livechat", "Livechat_transcript_sent": "Transcrição de Livechat enviada", "Livechat_Users": "Utilizadores Livechat", "LiveStream & Broadcasting": "Livestream e Broadcasting", From e41ede46c1619fe12723905922e8ebc8530a59f8 Mon Sep 17 00:00:00 2001 From: oguhpereira Date: Sat, 1 Aug 2020 11:41:37 -0300 Subject: [PATCH 5/5] [FEAT] Change character limit * Review changes pull-request * Changing Livechat_show_message_character_limit to Livechat_enable_message_character_limit * Saving limitTextLength with parseInt * Adding checkbox options showLimitTextLength * changing translation showLimitTextLengthFormTrueChecked --- .../client/views/app/livechatAppearance.html | 2 +- .../client/views/app/livechatAppearance.js | 19 +++++++++++++------ app/livechat/server/api/lib/appearance.js | 2 +- app/livechat/server/api/lib/livechat.js | 19 ++----------------- app/livechat/server/config.js | 4 ++-- app/livechat/server/lib/Livechat.js | 3 ++- app/livechat/server/methods/saveAppearance.js | 2 +- packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 2 +- packages/rocketchat-i18n/i18n/pt.i18n.json | 2 +- 10 files changed, 25 insertions(+), 32 deletions(-) diff --git a/app/livechat/client/views/app/livechatAppearance.html b/app/livechat/client/views/app/livechatAppearance.html index 84191f086d78..ea0fc5b5f182 100644 --- a/app/livechat/client/views/app/livechatAppearance.html +++ b/app/livechat/client/views/app/livechatAppearance.html @@ -17,7 +17,7 @@

{{_ "Settings"}}

- +
diff --git a/app/livechat/client/views/app/livechatAppearance.js b/app/livechat/client/views/app/livechatAppearance.js index 91be60cd1b51..e33662678024 100644 --- a/app/livechat/client/views/app/livechatAppearance.js +++ b/app/livechat/client/views/app/livechatAppearance.js @@ -11,8 +11,15 @@ import { APIClient } from '../../../../utils/client'; const getSettingFromAppearance = (instance, settingName) => instance.appearance.get() && instance.appearance.get().find((setting) => setting._id === settingName); Template.livechatAppearance.helpers({ - showLimitTextLength() { - return Template.instance().showLimitTextLength.get(); + showLimitTextLengthFormTrueChecked() { + if (Template.instance().showLimitTextLength.get()) { + return 'checked'; + } + }, + showLimitTextLengthFormFalseChecked() { + if (!Template.instance().showLimitTextLength.get()) { + return 'checked'; + } }, limitTextLength() { return Template.instance().limitTextLength.get(); @@ -139,7 +146,7 @@ Template.livechatAppearance.onCreated(async function() { const livechatTitle = getSettingFromAppearance(this, 'Livechat_title'); const livechatTitleColor = getSettingFromAppearance(this, 'Livechat_title_color'); - const livechatShowMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_show_message_character_limit'); + const livechatShowMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_enable_message_character_limit'); const livechatMessageCharacterLimit = getSettingFromAppearance(this, 'Livechat_message_character_limit'); const livechatShowAgentInfo = getSettingFromAppearance(this, 'Livechat_show_agent_info'); const livechatShowAgentEmail = getSettingFromAppearance(this, 'Livechat_show_agent_email'); @@ -198,7 +205,7 @@ Template.livechatAppearance.events({ const settingTitleColor = getSettingFromAppearance(instance, 'Livechat_title_color'); instance.color.set(settingTitleColor && settingTitleColor.value); - const settinglivechatShowMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_show_message_character_limit'); + const settinglivechatShowMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_enable_message_character_limit'); instance.showLimitTextLength.set(settinglivechatShowMessageCharacterLimit && settinglivechatShowMessageCharacterLimit.value); const settinglivechatMessageCharacterLimit = getSettingFromAppearance(instance, 'Livechat_message_character_limit'); @@ -258,12 +265,12 @@ Template.livechatAppearance.events({ value: instance.color.get(), }, { - _id: 'Livechat_show_message_character_limit', + _id: 'Livechat_enable_message_character_limit', value: instance.showLimitTextLength.get(), }, { _id: 'Livechat_message_character_limit', - value: instance.limitTextLength.get(), + value: parseInt(instance.limitTextLength.get()), }, { _id: 'Livechat_show_agent_info', diff --git a/app/livechat/server/api/lib/appearance.js b/app/livechat/server/api/lib/appearance.js index b1524355cfb6..12798f0de52c 100644 --- a/app/livechat/server/api/lib/appearance.js +++ b/app/livechat/server/api/lib/appearance.js @@ -10,7 +10,7 @@ export async function findAppearance({ userId }) { $in: [ 'Livechat_title', 'Livechat_title_color', - 'Livechat_show_message_character_limit', + 'Livechat_enable_message_character_limit', 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', diff --git a/app/livechat/server/api/lib/livechat.js b/app/livechat/server/api/lib/livechat.js index 2c3e9b56f0c4..bb4a7b4bb75f 100644 --- a/app/livechat/server/api/lib/livechat.js +++ b/app/livechat/server/api/lib/livechat.js @@ -6,7 +6,6 @@ import { LivechatRooms, LivechatVisitors, LivechatDepartment, LivechatTrigger } import { Livechat } from '../../lib/Livechat'; import { callbacks } from '../../../../callbacks/server'; import { normalizeAgent } from '../../lib/Helper'; -import { settings as ClientSettings } from '../../../../settings'; export function online(department) { return Livechat.online(department); @@ -67,19 +66,6 @@ export function findOpenRoom(token, departmentId) { return room; } -export function findLimitTextLength({ Livechat_show_message_character_limit, Livechat_message_character_limit}) { - if (!Livechat_show_message_character_limit) { - return false; - } - const messageMaxAllowedSize = ClientSettings.get('Message_MaxAllowedSize'); - - if (Livechat_message_character_limit && messageMaxAllowedSize > Livechat_message_character_limit) { - return Livechat_message_character_limit; - } - - return messageMaxAllowedSize; -} - export function getRoom({ guest, rid, roomInfo, agent, extraParams }) { const token = guest && guest.token; @@ -108,8 +94,6 @@ export function settings() { const departments = findDepartments(); const sound = `${ Meteor.absoluteUrl() }sounds/chime.mp3`; const emojis = Meteor.call('listEmojiCustom'); - const limitTextLength = findLimitTextLength(initSettings); - return { enabled: initSettings.Livechat_enabled, settings: { @@ -126,7 +110,8 @@ export function settings() { forceAcceptDataProcessingConsent: initSettings.Livechat_force_accept_data_processing_consent, showConnecting: initSettings.Livechat_Show_Connecting, agentHiddenInfo: initSettings.Livechat_show_agent_info === false, - limitTextLength, + limitTextLength: initSettings.Livechat_enable_message_character_limit + && (initSettings.Livechat_message_character_limit || initSettings.Message_MaxAllowedSize), }, theme: { title: initSettings.Livechat_title, diff --git a/app/livechat/server/config.js b/app/livechat/server/config.js index 2d7a2b3fcb7a..2b59ad4d7772 100644 --- a/app/livechat/server/config.js +++ b/app/livechat/server/config.js @@ -27,8 +27,8 @@ Meteor.startup(function() { public: true, }); - settings.add('Livechat_show_message_character_limit', false, { - type: 'int', + settings.add('Livechat_enable_message_character_limit', false, { + type: 'boolean', group: 'Omnichannel', section: 'Livechat', public: true, diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index 3ce7625db243..69bfee85c89d 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -428,8 +428,9 @@ export const Livechat = { Settings.findNotHiddenPublic([ 'Livechat_title', 'Livechat_title_color', - 'Livechat_show_message_character_limit', + 'Livechat_enable_message_character_limit', 'Livechat_message_character_limit', + 'Message_MaxAllowedSize', 'Livechat_enabled', 'Livechat_registration_form', 'Livechat_allow_switching_departments', diff --git a/app/livechat/server/methods/saveAppearance.js b/app/livechat/server/methods/saveAppearance.js index b03005fe8d76..44a3749d81b4 100644 --- a/app/livechat/server/methods/saveAppearance.js +++ b/app/livechat/server/methods/saveAppearance.js @@ -12,7 +12,7 @@ Meteor.methods({ const validSettings = [ 'Livechat_title', 'Livechat_title_color', - 'Livechat_show_message_character_limit', + 'Livechat_enable_message_character_limit', 'Livechat_message_character_limit', 'Livechat_show_agent_info', 'Livechat_show_agent_email', diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 3b83ccc66239..f7669b35057c 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2272,7 +2272,7 @@ "Livechat_Take_Confirm": "Do you want to take this client?", "Livechat_title": "Livechat Title", "Livechat_title_color": "Livechat Title Background Color", - "Livechat_show_message_character_limit": "Livechat message character limit", + "Livechat_enable_message_character_limit": "Enable message character limit", "Livechat_message_character_limit": "Livechat message character limit", "Livechat_transcript_already_requested_warning": "The transcript of this chat has already been requested and will be sent as soon as the conversation ends.", "Livechat_transcript_request_has_been_canceled": "The chat transcription request has been canceled.", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index 64779bc7ed71..11c41c103317 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -2016,7 +2016,7 @@ "Livechat_Take_Confirm": "Você quer levar esse cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", - "Livechat_show_message_character_limit": "Exibir Limite de caracteres da mensagem no livechat", + "Livechat_enable_message_character_limit": "Habilitar Limite de caracteres de mensagem", "Livechat_message_character_limit": "Limite de caracteres da mensagem no livechat", "Livechat_transcript_already_requested_warning": "A transcrição deste bate-papo já foi solicitada e será enviada assim que a conversa for encerrada.", "Livechat_transcript_request_has_been_canceled": "A requisição de transcrição do bate-papo foi cancelada.", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index ef2872ced037..9d02000779f0 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -1894,7 +1894,7 @@ "Livechat_Take_Confirm": "Quer levar este cliente?", "Livechat_title": "Título Livechat", "Livechat_title_color": "Cor de fundo do título do Livechat", - "Livechat_show_message_character_limit": "Exibir Limite de caracteres da mensagem no livechat", + "Livechat_enable_message_character_limit": "Habilitar Limite de caracteres de mensagem", "Livechat_message_character_limit": "Limite de caracteres da mensagem no livechat", "Livechat_transcript_sent": "Transcrição de Livechat enviada", "Livechat_Users": "Utilizadores Livechat",