diff --git a/CHANGES.md b/CHANGES.md index 55af5819c4..1383d34c64 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ - Updated translations - #3123: Contacts do not show up online until chat is opened with them. - #3156: Add function to prevent drag stutter effect over iframes when resize is called in overlay mode -- #3161: Re-add ability to convert OpenStreetMap URLs into `geo:` URIs in sent messages +- #3161: Re-add ability to convert OpenStreetMap URLs into `geo:` URIs in sent messages and fix issue #1850 - #3165: Use configured nickname in profile view in the control box - New config option [stanza_timeout](https://conversejs.org/docs/html/configuration.html#stanza-timeout) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 9a9860c2e2..1f7884fc8d 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -935,7 +935,7 @@ It allows to convert OpenStreetMap URLs into `geo:` URIs in sent messages. The default ``undefined`` means that no conversion is done. -E.g. ``/https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g`` +E.g. ``/(https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*)/g`` geouri_replacement ------------------ diff --git a/src/headless/plugins/chat/model.js b/src/headless/plugins/chat/model.js index 4e59a6c655..2217de7160 100644 --- a/src/headless/plugins/chat/model.js +++ b/src/headless/plugins/chat/model.js @@ -840,7 +840,7 @@ const ChatBox = ModelWithContact.extend({ const is_spoiler = !!this.get('composing_spoiler'); const origin_id = u.getUniqueId(); const text = attrs?.body; - const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined; + const body = text ? u.httpToGeoUriWithOriginalString(u.shortnamesToUnicode(text), _converse) : undefined; attrs = Object.assign({}, attrs, { 'from': _converse.bare_jid, 'fullname': _converse.xmppstatus.get('fullname'), diff --git a/src/headless/plugins/muc/tests/muc.js b/src/headless/plugins/muc/tests/muc.js index 3de8810a11..ace30988c3 100644 --- a/src/headless/plugins/muc/tests/muc.js +++ b/src/headless/plugins/muc/tests/muc.js @@ -143,28 +143,5 @@ describe("Groupchats", function () { ``+ ``); })); - - it("Original URL is displayed alongside the Geo Coordinates when sending a OpenStreetMap url as a chat message", - mock.initConverse([], {}, async function (_converse) { - const muc_jid = 'coven@chat.shakespeare.lit'; - await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo'); - const model = _converse.chatboxes.get(muc_jid); - expect(model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED); - model.sendMessage({'body': 'https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=43.00556%2C-81.21649%3B43.00422%2C-81.22377#map=17/43.00509/-81.22035'}); - - const stanza = u.toStanza(` - - - - - `); - _converse.connection._dataRecv(mock.createRequest(stanza)); - - await u.waitUntil(() => model.messages.last()?.get('body')); - expect(model.messages.last().get('message')).toBe('geo:43.00509,-81.22035\nhttps://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=43.00556%2C-81.21649%3B43.00422%2C-81.22377#map=17/43.00509/-81.22035') - })); }); }); diff --git a/src/headless/utils/core.js b/src/headless/utils/core.js index 97a3f1a17f..deab4b2b45 100644 --- a/src/headless/utils/core.js +++ b/src/headless/utils/core.js @@ -485,14 +485,11 @@ export function getUniqueId (suffix) { } } -u.httpToGeoUriWithOriginalString = function(text){ - const replacement = 'geo:$1,$2'; - if(text.replace(settings_api.get('geouri_regex'), replacement) === text){ - return text.replace(settings_api.get('geouri_regex'), replacement) - }else{ - return text.replace(settings_api.get('geouri_regex'), replacement) + '\n' + text; - } -} +u.httpToGeoUriWithOriginalString = function(text) { + const replacement = '$1 (geo:$2,$3)'; + const geouri_regex = settings_api.get("geouri_regex"); + return geouri_regex ? text.replace(geouri_regex, replacement) : text; +}; /** * Clears the specified timeout and interval. diff --git a/src/plugins/chatview/tests/messages.js b/src/plugins/chatview/tests/messages.js index d4bd92d067..00c41edf46 100644 --- a/src/plugins/chatview/tests/messages.js +++ b/src/plugins/chatview/tests/messages.js @@ -284,7 +284,7 @@ describe("A Chat Message", function () { mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) { await mock.waitForRoster(_converse, 'current', 1); - const message = "https://www.openstreetmap.org/#map=18/68.24920/13.61230"; + const message = "https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630"; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; await mock.openChatBoxFor(_converse, contact_jid); const view = _converse.chatboxviews.get(contact_jid); @@ -295,15 +295,15 @@ describe("A Chat Message", function () { const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop(); await u.waitUntil(() => msg.innerHTML.replace(/\/g, '') === 'https://www.openstreetmap.org/#map=18/68.24920/13.61230'); + '"https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630">https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630'); })); it("will render geo-URI from Openstreetmap-URL", - mock.initConverse(['chatBoxesFetched'], {'geouri_regex': /https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g}, + mock.initConverse(['chatBoxesFetched'], {'geouri_regex': /(https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*)/g}, async function (_converse) { await mock.waitForRoster(_converse, 'current', 1); - const message = "https://www.openstreetmap.org/#map=18/68.24920/13.61230"; + const message = "https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630"; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; await mock.openChatBoxFor(_converse, contact_jid); const view = _converse.chatboxviews.get(contact_jid); @@ -313,7 +313,7 @@ describe("A Chat Message", function () { expect(view.model.sendMessage).toHaveBeenCalled(); const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop(); await u.waitUntil(() => msg.innerHTML.replace(/\/g, '') === - 'geo:68.24920,13.61230'); + 'https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630 (geo:51.724,6.630)'); })); it("can be a carbon message, as defined in XEP-0280",