Skip to content

Commit 06c9f4c

Browse files
committed
optimize fix for issue #1850
1 parent 93bfa20 commit 06c9f4c

File tree

5 files changed

+11
-36
lines changed

5 files changed

+11
-36
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- Removed documentation about the no longer implemented `fullname` option.
1111
- Updated translations
1212
- #3156: Add function to prevent drag stutter effect over iframes when resize is called in overlay mode
13-
- #3161: Re-add ability to convert OpenStreetMap URLs into `geo:` URIs in sent messages
13+
- #3161: Re-add ability to convert OpenStreetMap URLs into `geo:` URIs in sent messages and fix issue #1850
1414
- #3165: Use configured nickname in profile view in the control box
1515

1616
- New config option [stanza_timeout](https://conversejs.org/docs/html/configuration.html#stanza-timeout)

src/headless/plugins/chat/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ const ChatBox = ModelWithContact.extend({
840840
const is_spoiler = !!this.get('composing_spoiler');
841841
const origin_id = u.getUniqueId();
842842
const text = attrs?.body;
843-
const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined;
843+
const body = text ? u.httpToGeoUriWithOriginalString(u.shortnamesToUnicode(text), _converse) : undefined;
844844
attrs = Object.assign({}, attrs, {
845845
'from': _converse.bare_jid,
846846
'fullname': _converse.xmppstatus.get('fullname'),

src/headless/plugins/muc/tests/muc.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,5 @@ describe("Groupchats", function () {
143143
`<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+
144144
`</presence>`);
145145
}));
146-
147-
it("Original URL is displayed alongside the Geo Coordinates when sending a OpenStreetMap url as a chat message",
148-
mock.initConverse([], {}, async function (_converse) {
149-
const muc_jid = '[email protected]';
150-
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
151-
const model = _converse.chatboxes.get(muc_jid);
152-
expect(model.session.get('connection_status')).toBe(converse.ROOMSTATUS.ENTERED);
153-
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'});
154-
155-
const stanza = u.toStanza(`
156-
<message xmlns='jabber:client'
157-
from='${muc_jid}'
158-
type='error'
159-
to='${_converse.bare_jid}'>
160-
<error type='cancel'>
161-
<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
162-
</error>
163-
</message>`);
164-
_converse.connection._dataRecv(mock.createRequest(stanza));
165-
166-
await u.waitUntil(() => model.messages.last()?.get('body'));
167-
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')
168-
}));
169146
});
170147
});

src/headless/utils/core.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,11 @@ export function getUniqueId (suffix) {
485485
}
486486
}
487487

488-
u.httpToGeoUriWithOriginalString = function(text){
488+
u.httpToGeoUriWithOriginalString = function(text) {
489489
const replacement = 'geo:$1,$2';
490-
if(text.replace(settings_api.get('geouri_regex'), replacement) === text){
491-
return text.replace(settings_api.get('geouri_regex'), replacement)
492-
}else{
493-
return text.replace(settings_api.get('geouri_regex'), replacement) + '\n' + text;
494-
}
495-
}
490+
const geouri_regex = settings_api.get("geouri_regex");
491+
return geouri_regex ? text + " (" + text.replace(geouri_regex, replacement) + ")" : text;
492+
};
496493

497494
/**
498495
* Clears the specified timeout and interval.

src/plugins/chatview/tests/messages.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe("A Chat Message", function () {
284284
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
285285

286286
await mock.waitForRoster(_converse, 'current', 1);
287-
const message = "https://www.openstreetmap.org/#map=18/68.24920/13.61230";
287+
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";
288288
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
289289
await mock.openChatBoxFor(_converse, contact_jid);
290290
const view = _converse.chatboxviews.get(contact_jid);
@@ -295,15 +295,15 @@ describe("A Chat Message", function () {
295295
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
296296
await u.waitUntil(() => msg.innerHTML.replace(/\<!-.*?-\>/g, '') ===
297297
'<a target="_blank" rel="noopener" href='+
298-
'"https://www.openstreetmap.org/#map=18/68.24920/13.61230">https://www.openstreetmap.org/#map=18/68.24920/13.61230</a>');
298+
'"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</a>');
299299
}));
300300

301301
it("will render geo-URI from Openstreetmap-URL",
302302
mock.initConverse(['chatBoxesFetched'], {'geouri_regex': /https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g},
303303
async function (_converse) {
304304

305305
await mock.waitForRoster(_converse, 'current', 1);
306-
const message = "https://www.openstreetmap.org/#map=18/68.24920/13.61230";
306+
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";
307307
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
308308
await mock.openChatBoxFor(_converse, contact_jid);
309309
const view = _converse.chatboxviews.get(contact_jid);
@@ -313,7 +313,8 @@ describe("A Chat Message", function () {
313313
expect(view.model.sendMessage).toHaveBeenCalled();
314314
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
315315
await u.waitUntil(() => msg.innerHTML.replace(/\<!-.*?-\>/g, '') ===
316-
'geo:68.24920,13.61230');
316+
'<a target="_blank" rel="noopener" href='+
317+
'"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</a> (geo:51.724,6.630)');
317318
}));
318319

319320
it("can be a carbon message, as defined in XEP-0280",

0 commit comments

Comments
 (0)