Skip to content

Commit

Permalink
optimize fix for issue #1850
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaosKid42 committed Jun 10, 2023
1 parent adadd18 commit 0f571df
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down
2 changes: 1 addition & 1 deletion src/headless/plugins/chat/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
23 changes: 0 additions & 23 deletions src/headless/plugins/muc/tests/muc.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,5 @@ describe("Groupchats", function () {
`<c hash="sha-1" node="https://conversejs.org" ver="TfHz9vOOfqIG0Z9lW5CuPaWGnrQ=" xmlns="http://jabber.org/protocol/caps"/>`+
`</presence>`);
}));

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 = '[email protected]';
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(`
<message xmlns='jabber:client'
from='${muc_jid}'
type='error'
to='${_converse.bare_jid}'>
<error type='cancel'>
<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
</error>
</message>`);
_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')
}));
});
});
13 changes: 5 additions & 8 deletions src/headless/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/chatview/tests/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, '') ===
'<a target="_blank" rel="noopener" href='+
'"https://www.openstreetmap.org/#map=18/68.24920/13.61230">https://www.openstreetmap.org/#map=18/68.24920/13.61230</a>');
'"https://www.openstreetmap.org/directions?engine=fossgis_osrm_car&amp;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&amp;route=51.507%2C-0.128%3B52.517%2C13.389#map=7/51.724/6.630</a>');
}));

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);
Expand All @@ -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&amp;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",
Expand Down

0 comments on commit 0f571df

Please sign in to comment.