Merge pull request #1779 from thelounge/xpaw/nick-links-fixes

Fix nicks not being detected in actions and duplicate nicks
This commit is contained in:
Jérémie Astori 2017-11-30 20:43:36 -05:00 committed by GitHub
commit b2835855c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View File

@ -2,15 +2,17 @@
function findNames(text, users) {
const result = [];
let index = 0;
let index = -1;
users.forEach((nick) => {
index = text.indexOf(nick, index);
index = text.indexOf(nick, ++index);
result.push({
start: index,
end: index + nick.length,
nick: nick,
});
});
return result;
}

View File

@ -1,5 +1,5 @@
{{> ../user_name from}}
<span class="text">{{{parse text}}}</span>
<span class="text">{{{parse text users}}}</span>
{{#each previews}}
<div class="preview" data-url="{{link}}"></div>

View File

@ -23,4 +23,29 @@ describe("findNames", () => {
expect(actual).to.deep.equal(expected);
});
it("should find same nick multiple times", () => {
const input = "xPaw xPaw xPaw";
const expected = [
{
start: 0,
end: 4,
nick: "xPaw",
},
{
start: 5,
end: 9,
nick: "xPaw",
},
{
start: 10,
end: 14,
nick: "xPaw",
},
];
const nicks = ["xPaw", "xPaw", "xPaw"];
const actual = findNames(input, nicks);
expect(actual).to.deep.equal(expected);
});
});