|
@@ -115,6 +115,7 @@ function onServerLogin(user, history) {
|
|
|
const usernameEl = $('<span>');
|
|
|
usernameEl.text(userString);
|
|
|
usernameEl.css('color', listUser.color);
|
|
|
+ usernameEl.click(() => mentionUser(listUser.name));
|
|
|
userListEl.append(usernameEl);
|
|
|
|
|
|
if (user.admin) {
|
|
@@ -171,13 +172,15 @@ function onServerLogin(user, history) {
|
|
|
const valBefore = val.substring(0, cursorPos);
|
|
|
const valAfter = val.substring(cursorPos);
|
|
|
|
|
|
- for (const emojiPatternItem of emojiPatterns) {
|
|
|
- if (valBefore.endsWith(emojiPatternItem.pattern)) {
|
|
|
- field.val(
|
|
|
- valBefore.substring(0, valBefore.length - emojiPatternItem.pattern.length) + emojiPatternItem.replacement + valAfter
|
|
|
- );
|
|
|
- field.prop('selectionStart', cursorPos);
|
|
|
- field.prop('selectionEnd', cursorPos);
|
|
|
+ if (!valBefore.endsWith('http:/') && !valBefore.endsWith('https:/')) {
|
|
|
+ for (const emojiPatternItem of emojiPatterns) {
|
|
|
+ if (valBefore.endsWith(emojiPatternItem.pattern)) {
|
|
|
+ field.val(
|
|
|
+ valBefore.substring(0, valBefore.length - emojiPatternItem.pattern.length) + emojiPatternItem.replacement + valAfter
|
|
|
+ );
|
|
|
+ field.prop('selectionStart', cursorPos);
|
|
|
+ field.prop('selectionEnd', cursorPos);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -236,6 +239,7 @@ function appendUserMessage(msg, msgUser, timestamp, user) {
|
|
|
const avaEl = $('<img class="avatar" />');
|
|
|
avaEl.prop('src', '/img/ava/' + msgUser.name);
|
|
|
avaEl.css('backgroundColor', msgUser.color);
|
|
|
+ avaEl.click(() => mentionUser(msgUser.name));
|
|
|
messageWrapper.append(avaEl);
|
|
|
|
|
|
const timeEl = $('<span class="time">');
|
|
@@ -250,6 +254,7 @@ function appendUserMessage(msg, msgUser, timestamp, user) {
|
|
|
}
|
|
|
userEl.text(userString);
|
|
|
userEl.css('color', msgUser.color);
|
|
|
+ userEl.click(() => mentionUser(msgUser.name));
|
|
|
messageWrapper.append(userEl);
|
|
|
|
|
|
const messageEl = $('<span class="message">');
|
|
@@ -268,3 +273,24 @@ function onKickUser(user) {
|
|
|
function onLiftBan(ip) {
|
|
|
socket.emit('requestLiftBan', ip);
|
|
|
}
|
|
|
+
|
|
|
+function mentionUser(username) {
|
|
|
+ const field = $("#chat-host .messageField");
|
|
|
+ if (field) {
|
|
|
+ const mention = '@' + username + ' ';
|
|
|
+
|
|
|
+ const val = field.val();
|
|
|
+ var cursorPos = +field.prop('selectionStart');
|
|
|
+ const valBefore = val.substring(0, cursorPos);
|
|
|
+ const valAfter = val.substring(cursorPos);
|
|
|
+
|
|
|
+ field.val(valBefore + mention + valAfter);
|
|
|
+
|
|
|
+ cursorPos += mention.length;
|
|
|
+
|
|
|
+ field.prop('selectionStart', cursorPos);
|
|
|
+ field.prop('selectionEnd', cursorPos);
|
|
|
+
|
|
|
+ field.focus();
|
|
|
+ }
|
|
|
+}
|