fix: sending locations (#2339)
* added function to to modify module functions * fix for locations to be sent * changes for class Location - description property was splited into name and address - added url property - added ability to pass name, address and url as options while creating an instance * docs updated * usage example updated * added url checking * fixed url * updated location property in Message class * fixed url when http prefix is provided * injectToFunction updated to be more flexible * docs clarification * ESLint fix * fix: injectToFunction fixed to work properly * minor fix in injectToFunction * refactor: added usage of url validator * small change to improve performance for findImpl fix * window.compareWwebVersions fixed
This commit is contained in:
parent
1c059d3b3d
commit
ecf19eb9a5
2 changed files with 117 additions and 20 deletions
|
|
@ -1,5 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Location send options
|
||||
* @typedef {Object} LocationSendOptions
|
||||
* @property {string} [name] Location name
|
||||
* @property {string} [address] Location address
|
||||
* @property {string} [url] URL address to be shown within a location message
|
||||
*/
|
||||
|
||||
/**
|
||||
* Location information
|
||||
*/
|
||||
|
|
@ -7,9 +15,9 @@ class Location {
|
|||
/**
|
||||
* @param {number} latitude
|
||||
* @param {number} longitude
|
||||
* @param {?string} description
|
||||
* @param {LocationSendOptions} [options] Location send options
|
||||
*/
|
||||
constructor(latitude, longitude, description) {
|
||||
constructor(latitude, longitude, options = {}) {
|
||||
/**
|
||||
* Location latitude
|
||||
* @type {number}
|
||||
|
|
@ -24,9 +32,29 @@ class Location {
|
|||
|
||||
/**
|
||||
* Name for the location
|
||||
* @type {?string}
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.description = description;
|
||||
this.name = options.name;
|
||||
|
||||
/**
|
||||
* Location address
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.address = options.address;
|
||||
|
||||
/**
|
||||
* URL address to be shown within a location message
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.url = options.url;
|
||||
|
||||
/**
|
||||
* Location full description
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.description = this.name && this.address
|
||||
? `${this.name}\n${this.address}`
|
||||
: this.name || this.address || '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,21 @@ class Message extends Base {
|
|||
* Location information contained in the message, if the message is type "location"
|
||||
* @type {Location}
|
||||
*/
|
||||
this.location = data.type === MessageTypes.LOCATION ? new Location(data.lat, data.lng, data.loc) : undefined;
|
||||
this.location = (() => {
|
||||
if (data.type !== MessageTypes.LOCATION) {
|
||||
return undefined;
|
||||
}
|
||||
let description;
|
||||
if (data.loc && typeof data.loc === 'string') {
|
||||
let splitted = data.loc.split('\n');
|
||||
description = {
|
||||
name: splitted[0],
|
||||
address: splitted[1],
|
||||
url: data.clientUrl
|
||||
};
|
||||
}
|
||||
return new Location(data.lat, data.lng, description);
|
||||
})();
|
||||
|
||||
/**
|
||||
* List of vCards contained in the message.
|
||||
|
|
|
|||
Loading…
Reference in a new issue