Skip to content

Commit

Permalink
added fixes for Issue conversejs#2857
Browse files Browse the repository at this point in the history
  • Loading branch information
ShehanAT committed May 15, 2022
1 parent 858a605 commit 27345bd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/plugins/chatview/tests/chatbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,45 @@ describe("Chatboxes", function () {
}));
});
});

describe("Chatbox Message Styling", function() {

it("is not applied when sending a chat message containing a HTTP URL with styling template characters( _, \`, \`\`\`, ~, *) in the middle of it",
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {

await mock.waitForRoster(_converse, 'current');
await mock.openControlBox(_converse);
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';

spyOn(_converse.api, "trigger").and.callThrough();
await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
let message = 'https://nitter.kavin.rocks/_MG_/~/*/1506109152665382920';
await mock.sendMessage(view, message);

expect(view.model.messages.length === 1).toBeTruthy();
const stored_messages = await view.model.messages.browserStorage.findAll();
expect(view.model.messages.models[0].attributes.message).toEqual(message);
expect(view.model.messages.length).toBe(1);

// try second URL
let message2 = 'https://nitter.george.rocks/_G*_/\`/\`\`\`/665382920';
await mock.sendMessage(view, message2);

expect(view.model.messages.length === 2).toBeTruthy();
expect(view.model.messages.models[1].attributes.message).toEqual(message2);
expect(view.model.messages.length).toBe(2);

// try third URL
let message3 = 'https://nitter.frank.rocks/_OP_/_NP_/\`\`\`/*/~/_qweq_665382920';
await mock.sendMessage(view, message3);

expect(view.model.messages.length === 3).toBeTruthy();
expect(view.model.messages.models[2].attributes.message).toEqual(message3);
expect(view.model.messages.length).toBe(3);
}));

});;
});

describe("Special Messages", function () {
Expand Down Expand Up @@ -1052,5 +1091,7 @@ describe("Chatboxes", function () {
await mock.openChatBoxFor(_converse, sender_jid);
expect(select_msgs_indicator().textContent).toBe('1');
}));


});
});
19 changes: 18 additions & 1 deletion src/shared/rich-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ export class RichText extends String {
references.forEach(ref => this.addTemplateResult(ref.begin, ref.end, ref.template));
}

checkIfHttpsUrl (text) {
if(text.slice(0, 8) === "https://"){
return true;
}
return false;
}

trimMeMessage () {
if (this.offset === 0) {
// Subtract `/me ` from 3rd person messages
Expand Down Expand Up @@ -300,7 +307,15 @@ export class RichText extends String {
*/
await api.trigger('beforeMessageBodyTransformed', this, { 'Synchronous': true });

this.render_styling && this.addStyling();
var text = this.toString();

if(!this.checkIfHttpsUrl(text)){
this.render_styling && this.addStyling();
}else{
this.render_styling;
}

// this.render_styling && this.addStyling();
this.addAnnotations(this.addMentions);
this.addAnnotations(this.addHyperlinks);
this.addAnnotations(this.addMapURLs);
Expand Down Expand Up @@ -342,6 +357,8 @@ export class RichText extends String {
this.references.push({ begin, end, template });
}



isMeCommand () {
const text = this.toString();
if (!text) {
Expand Down

0 comments on commit 27345bd

Please sign in to comment.