Skip to content

Commit

Permalink
Merge pull request thelounge#425 from thelounge/yamanickill/custom-hi…
Browse files Browse the repository at this point in the history
…ghlights

Add custom highlights
  • Loading branch information
astorije authored Jun 30, 2016
2 parents 0ccdb0e + a4fb73d commit f96027f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ <h2>Notifications</h2>
Enable notification for all messages
</label>
</div>

<div class="col-sm-12">
<label class="opt">
<label for="highlights" class="sr-only">Custom highlights (comma-separated keywords)</label>
<input type="text" id="highlights" name="highlights" class="input" placeholder="Custom highlights (comma-separated keywords)">
</label>
</div>

<% if (!public) { %>
<div id="change-password">
<form action="" method="post">
Expand Down
23 changes: 21 additions & 2 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ $(function() {
var chan = chat.find(target);
var msg;

if (highlights.some(function(h) {
return data.msg.text.indexOf(h) > -1;
})) {
data.msg.highlight = true;
}

if ([
"invite",
"join",
Expand Down Expand Up @@ -466,12 +472,15 @@ $(function() {
}
settings.find("#user-specified-css-input").val(options[i]);
continue;
}
if (options[i]) {
} else if (i === "highlights") {
settings.find("input[name=" + i + "]").val(options[i]);
} else if (options[i]) {
settings.find("input[name=" + i + "]").prop("checked", true);
}
}

var highlights = [];

settings.on("change", "input, textarea", function() {
var self = $(this);
var name = self.attr("name");
Expand Down Expand Up @@ -501,6 +510,16 @@ $(function() {
if (name === "userStyles") {
$(document.head).find("#user-specified-css").html(options[name]);
}
if (name === "highlights") {
var highlightString = options[name];
highlights = highlightString.split(",").map(function(h) {
return h.trim();
}).filter(function(h) {
// Ensure we don't have empty string in the list of highlights
// otherwise, users get notifications for everything
return h !== "";
});
}
}).find("input")
.trigger("change");

Expand Down

0 comments on commit f96027f

Please sign in to comment.