[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) <tde@openerp.com>
This commit is contained in:
Munaf Khan
2021-07-07 09:42:16 +00:00
committed by Thibault Delavallée
parent 2072de7504
commit 68e479f918
2 changed files with 9 additions and 1 deletions
@@ -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;
});
});
+1 -1
View File
@@ -13,7 +13,7 @@
<a t-if="not _exclude_share_links or not 'linkedin' in _exclude_share_links" href="http://www.linkedin.com/sharing/share-offsite/?url={url}" t-attf-class="s_share_linkedin #{_link_classes}" target="_blank">
<i t-attf-class="fa fa-linkedin #{not _link_classes and 'rounded shadow-sm'}"/>
</a>
<a t-if="not _exclude_share_links or not 'whatsapp' in _exclude_share_links" href="whatsapp://send?text={title}&amp;url={url}" t-attf-class="s_share_whatsapp #{_link_classes}" target="_blank">
<a t-if="not _exclude_share_links or not 'whatsapp' in _exclude_share_links" href="https://wa.me/?text={title}" t-attf-class="s_share_whatsapp #{_link_classes}" target="_blank">
<i t-attf-class="fa fa-whatsapp #{not _link_classes and 'rounded shadow-sm'}"/>
</a>
<a t-if="not _exclude_share_links or not 'pinterest' in _exclude_share_links" href="http://pinterest.com/pin/create/button/?url={url}&amp;description={title}" t-attf-class="s_share_pinterest #{_link_classes}" target="_blank">