From 68e479f91827a6e3003e6093a5be2954a69e6265 Mon Sep 17 00:00:00 2001 From: Munaf Khan Date: Thu, 17 Jun 2021 12:21:13 +0000 Subject: [PATCH] [FIX] website: improve whatsapp sharing URL for social share snippet Curretnly, the link responsible for sharing the page on whatsapp (from social share snippet) is not working correctly. There are two main problems: - it works only for the devices where WhatsApp is already installed - only the page title is being shared, not the page URL This commit fixes both the issues by changing the sharing URL for WhatsApp. The URL is now changed to 'https://wa.me/....' instead of using 'whatsapp://' protocol (see the official link[1] for more information). With this URL, if the WhatsApp is not installed on the device, it will provide user with the options to either download it or use WhatsApp Web, and if WhatsApp is installed, it will open the app. Also with the URL, we pass both page title and page URL within 'text' URL parameter, and the secure link will be automatically parsed and converted to hyperlink by the platform. [1] - https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat/ TaskID-2557077 closes odoo/odoo#73360 X-original-commit: 348e10cdd09cd77972b57fe47626609b200996af Signed-off-by: Thibault Delavallee (tde) --- addons/website/static/src/snippets/s_share/000.js | 8 ++++++++ addons/website/views/snippets/s_share.xml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/snippets/s_share/000.js b/addons/website/static/src/snippets/s_share/000.js index c9be8c9b5ff..b6d630b12f8 100644 --- a/addons/website/static/src/snippets/s_share/000.js +++ b/addons/website/static/src/snippets/s_share/000.js @@ -20,6 +20,14 @@ const ShareWidget = publicWidget.Widget.extend({ return href.replace(urlRegex, function (match, a, b, c) { return a + url + c; }).replace(titleRegex, function (match, a, b, c) { + if ($a.hasClass('s_share_whatsapp')) { + // WhatsApp does not support the "url" GET parameter. + // Instead we need to include the url within the passed "text" parameter, merging everything together. + // e.g of output: + // https://wa.me/?text=%20OpenWood%20Collection%20Online%20Reveal%20%7C%20My%20Website%20http%3A%2F%2Flocalhost%3A8888%2Fevent%2Fopenwood-collection-online-reveal-2021-06-21-2021-06-23-8%2Fregister + // see https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat/ for more details + return a + title + url + c; + } return a + title + c; }); }); diff --git a/addons/website/views/snippets/s_share.xml b/addons/website/views/snippets/s_share.xml index 8c853f88491..54c2aa47455 100644 --- a/addons/website/views/snippets/s_share.xml +++ b/addons/website/views/snippets/s_share.xml @@ -13,7 +13,7 @@ - +