forked from cory/tildefriends
Auto-detect @mentions.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4008 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -63,6 +63,29 @@ class TfComposeElement extends LitElement {
|
||||
message.root = this.root;
|
||||
message.branch = this.branch;
|
||||
}
|
||||
for (let match of message.text.matchAll(/\[([^\[]+)]\((@[^\)]+)/g)) {
|
||||
if (!message.mentions) {
|
||||
message.mentions = [];
|
||||
}
|
||||
let name = match[1].length;
|
||||
let balance = 0;
|
||||
let bracket_end = match.index + match[1].length + '[]'.length - 1;
|
||||
for (let i = bracket_end; i >= 0; i--) {
|
||||
if (message.text.charAt(i) == ']') {
|
||||
balance++;
|
||||
} else if (message.text.charAt(i) == '[') {
|
||||
balance--;
|
||||
}
|
||||
if (balance <= 0) {
|
||||
name = message.text.substring(i + 1, bracket_end - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
message.mentions.push({
|
||||
link: match[2],
|
||||
name: name.charAt(0) == '@' ? name.substring(1) : name,
|
||||
});
|
||||
}
|
||||
console.log('Would post:', message);
|
||||
tfrpc.rpc.appendMessage(this.whoami, message).then(function() {
|
||||
edit.value = '';
|
||||
|
Reference in New Issue
Block a user