mirror of https://github.com/zulip/zulip.git
typeahead: Migrate from _@ to @_ for silent mentions.
We also clean up the code a little to make it easier to read and combine the matching code for both mentions and silent_mentions.
This commit is contained in:
parent
5c2e64d6a2
commit
8119258c4d
|
@ -347,22 +347,22 @@ run_test('content_typeahead_selected', () => {
|
||||||
document_stub_trigger3_called = true;
|
document_stub_trigger3_called = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
fake_this.query = '_@kin';
|
fake_this.query = '@_kin';
|
||||||
fake_this.token = 'kin';
|
fake_this.token = 'kin';
|
||||||
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
||||||
expected_value = '_@**King Hamlet** ';
|
expected_value = '@_**King Hamlet** ';
|
||||||
assert.equal(actual_value, expected_value);
|
assert.equal(actual_value, expected_value);
|
||||||
|
|
||||||
fake_this.query = '_@*kin';
|
fake_this.query = '@_*kin';
|
||||||
fake_this.token = 'kin';
|
fake_this.token = 'kin';
|
||||||
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
||||||
expected_value = '_@**King Hamlet** ';
|
expected_value = '@_**King Hamlet** ';
|
||||||
assert.equal(actual_value, expected_value);
|
assert.equal(actual_value, expected_value);
|
||||||
|
|
||||||
fake_this.query = '_@**kin';
|
fake_this.query = '@_**kin';
|
||||||
fake_this.token = 'kin';
|
fake_this.token = 'kin';
|
||||||
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
actual_value = ct.content_typeahead_selected.call(fake_this, hamlet);
|
||||||
expected_value = '_@**King Hamlet** ';
|
expected_value = '@_**King Hamlet** ';
|
||||||
assert.equal(actual_value, expected_value);
|
assert.equal(actual_value, expected_value);
|
||||||
|
|
||||||
// user group mention
|
// user group mention
|
||||||
|
@ -1128,39 +1128,39 @@ run_test('begins_typeahead', () => {
|
||||||
assert_typeahead_equals("#foo\n~~~py", lang_list);
|
assert_typeahead_equals("#foo\n~~~py", lang_list);
|
||||||
|
|
||||||
assert_typeahead_equals("@", false);
|
assert_typeahead_equals("@", false);
|
||||||
assert_typeahead_equals("_@", false);
|
assert_typeahead_equals("@_", false);
|
||||||
assert_typeahead_equals(" @", false);
|
assert_typeahead_equals(" @", false);
|
||||||
assert_typeahead_equals(" _@", false);
|
assert_typeahead_equals(" @_", false);
|
||||||
assert_typeahead_equals("test @**o", all_mentions);
|
assert_typeahead_equals("test @**o", all_mentions);
|
||||||
assert_typeahead_equals("test _@**o", all_mentions);
|
assert_typeahead_equals("test @_**o", all_mentions);
|
||||||
assert_typeahead_equals("test @*o", all_mentions);
|
assert_typeahead_equals("test @*o", all_mentions);
|
||||||
assert_typeahead_equals("test _@*k", all_mentions);
|
assert_typeahead_equals("test @_*k", all_mentions);
|
||||||
assert_typeahead_equals("test @*h", all_mentions);
|
assert_typeahead_equals("test @*h", all_mentions);
|
||||||
assert_typeahead_equals("test _@*h", all_mentions);
|
assert_typeahead_equals("test @_*h", all_mentions);
|
||||||
assert_typeahead_equals("test @", false);
|
assert_typeahead_equals("test @", false);
|
||||||
assert_typeahead_equals("test _@", false);
|
assert_typeahead_equals("test @_", false);
|
||||||
assert_typeahead_equals("test no@o", false);
|
assert_typeahead_equals("test no@o", false);
|
||||||
assert_typeahead_equals("test no_@k", false);
|
assert_typeahead_equals("test no@_k", false);
|
||||||
assert_typeahead_equals("@ ", false);
|
assert_typeahead_equals("@ ", false);
|
||||||
assert_typeahead_equals("_@ ", false);
|
assert_typeahead_equals("@_ ", false);
|
||||||
assert_typeahead_equals("@* ", false);
|
assert_typeahead_equals("@* ", false);
|
||||||
assert_typeahead_equals("_@* ", false);
|
assert_typeahead_equals("@_* ", false);
|
||||||
assert_typeahead_equals("@** ", false);
|
assert_typeahead_equals("@** ", false);
|
||||||
assert_typeahead_equals("_@** ", false);
|
assert_typeahead_equals("@_** ", false);
|
||||||
assert_typeahead_equals("test\n@i", all_mentions);
|
assert_typeahead_equals("test\n@i", all_mentions);
|
||||||
assert_typeahead_equals("test\n_@i", all_mentions);
|
assert_typeahead_equals("test\n@_i", all_mentions);
|
||||||
assert_typeahead_equals("test\n @l", all_mentions);
|
assert_typeahead_equals("test\n @l", all_mentions);
|
||||||
assert_typeahead_equals("test\n _@l", all_mentions);
|
assert_typeahead_equals("test\n @_l", all_mentions);
|
||||||
assert_typeahead_equals("@zuli", all_mentions);
|
assert_typeahead_equals("@zuli", all_mentions);
|
||||||
assert_typeahead_equals("_@zuli", all_mentions);
|
assert_typeahead_equals("@_zuli", all_mentions);
|
||||||
assert_typeahead_equals("@ zuli", false);
|
assert_typeahead_equals("@ zuli", false);
|
||||||
assert_typeahead_equals("_@ zuli", false);
|
assert_typeahead_equals("@_ zuli", false);
|
||||||
assert_typeahead_equals(" @zuli", all_mentions);
|
assert_typeahead_equals(" @zuli", all_mentions);
|
||||||
assert_typeahead_equals(" _@zuli", all_mentions);
|
assert_typeahead_equals(" @_zuli", all_mentions);
|
||||||
assert_typeahead_equals("test @o", all_mentions);
|
assert_typeahead_equals("test @o", all_mentions);
|
||||||
assert_typeahead_equals("test _@k", all_mentions);
|
assert_typeahead_equals("test @_o", all_mentions);
|
||||||
assert_typeahead_equals("test @z", all_mentions);
|
assert_typeahead_equals("test @z", all_mentions);
|
||||||
assert_typeahead_equals("test _@z", all_mentions);
|
assert_typeahead_equals("test @_z", all_mentions);
|
||||||
|
|
||||||
assert_typeahead_equals(":", false);
|
assert_typeahead_equals(":", false);
|
||||||
assert_typeahead_equals(": ", false);
|
assert_typeahead_equals(": ", false);
|
||||||
|
|
|
@ -440,23 +440,17 @@ exports.compose_content_begins_typeahead = function (query) {
|
||||||
|
|
||||||
if (this.options.completions.mention && current_token[0] === '@') {
|
if (this.options.completions.mention && current_token[0] === '@') {
|
||||||
current_token = current_token.substring(1);
|
current_token = current_token.substring(1);
|
||||||
current_token = filter_mention_name(current_token);
|
|
||||||
if (!current_token) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.completing = 'mention';
|
this.completing = 'mention';
|
||||||
this.token = current_token;
|
// Silent mentions
|
||||||
return get_mention_candidates_data();
|
if (current_token.startsWith('_')) {
|
||||||
|
this.completing = 'silent_mention';
|
||||||
|
current_token = current_token.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.completions.silent_mention && current_token.startsWith('_@')) {
|
|
||||||
// Ideally, we'd figure out a way to deduplicate this with the main mentions block.
|
|
||||||
current_token = current_token.substring(2);
|
|
||||||
current_token = filter_mention_name(current_token);
|
current_token = filter_mention_name(current_token);
|
||||||
if (!current_token) {
|
if (!current_token) {
|
||||||
|
this.completing = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.completing = 'silent_mention';
|
|
||||||
this.token = current_token;
|
this.token = current_token;
|
||||||
return get_mention_candidates_data();
|
return get_mention_candidates_data();
|
||||||
}
|
}
|
||||||
|
@ -512,18 +506,13 @@ exports.content_typeahead_selected = function (item) {
|
||||||
beginning = beginning.substring(0, beginning.length - this.token.length - 1) + " :" + item.emoji_name + ": ";
|
beginning = beginning.substring(0, beginning.length - this.token.length - 1) + " :" + item.emoji_name + ": ";
|
||||||
}
|
}
|
||||||
} else if (this.completing === 'mention' || this.completing === 'silent_mention') {
|
} else if (this.completing === 'mention' || this.completing === 'silent_mention') {
|
||||||
beginning = beginning.substring(0, beginning.length - this.token.length - 1);
|
var is_silent = this.completing === 'silent_mention';
|
||||||
if (beginning.endsWith('@*')) {
|
|
||||||
beginning = beginning.substring(0, beginning.length - 2);
|
|
||||||
} else if (beginning.endsWith('@')) {
|
|
||||||
beginning = beginning.substring(0, beginning.length - 1);
|
|
||||||
}
|
|
||||||
if (user_groups.is_user_group(item)) {
|
if (user_groups.is_user_group(item)) {
|
||||||
beginning += '@*' + item.name + '* ';
|
beginning = '@*' + item.name + '* ';
|
||||||
$(document).trigger('usermention_completed.zulip', {user_group: item});
|
$(document).trigger('usermention_completed.zulip', {user_group: item});
|
||||||
} else {
|
} else {
|
||||||
var mention_text = people.get_mention_syntax(item.full_name, item.user_id);
|
var mention_text = people.get_mention_syntax(item.full_name, item.user_id, is_silent);
|
||||||
beginning += mention_text + ' ';
|
beginning = mention_text + ' ';
|
||||||
$(document).trigger('usermention_completed.zulip', {mentioned: item});
|
$(document).trigger('usermention_completed.zulip', {mentioned: item});
|
||||||
}
|
}
|
||||||
} else if (this.completing === 'stream') {
|
} else if (this.completing === 'stream') {
|
||||||
|
|
|
@ -850,8 +850,14 @@ exports.is_duplicate_full_name = function (full_name) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.get_mention_syntax = function (full_name, user_id) {
|
exports.get_mention_syntax = function (full_name, user_id, silent) {
|
||||||
var mention = '@**' + full_name;
|
var mention = '';
|
||||||
|
if (silent) {
|
||||||
|
mention += '@_**';
|
||||||
|
} else {
|
||||||
|
mention += '@**';
|
||||||
|
}
|
||||||
|
mention += full_name;
|
||||||
if (!user_id) {
|
if (!user_id) {
|
||||||
blueslip.warn('get_mention_syntax called without user_id.');
|
blueslip.warn('get_mention_syntax called without user_id.');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue