typeahead: Clear rendered stream html on stream rename.

Previously, after a stream name, you could search for it using its
new name but the typeahead would still display the old name.
This commit is contained in:
Rohitt Vashishtha 2019-07-19 17:42:10 +00:00 committed by Tim Abbott
parent 31bd3d617d
commit 5d20c4b8fb
3 changed files with 36 additions and 0 deletions

View File

@ -520,6 +520,33 @@ run_test('render_stream', () => {
assert(rendered); assert(rendered);
}); });
run_test('clear_rendered_stream', () => {
var rendered = false;
var stream = {
description: 'This is a description.',
stream_id: 44,
name: 'Stream To Be Cleared',
};
global.stub_templates(function (template_name, args) {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
assert.equal(args.secondary, stream.description);
rendered = true;
return 'typeahead-item-stub';
});
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert(rendered);
rendered = false;
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert.equal(rendered, false);
// Here rendered will be true as it is being rendered again.
th.clear_rendered_stream(stream.stream_id);
assert.equal(th.render_stream(stream), 'typeahead-item-stub');
assert(rendered);
});
run_test('render_emoji', () => { run_test('render_emoji', () => {
// Test render_emoji with normal emoji. // Test render_emoji with normal emoji.
var rendered = false; var rendered = false;

View File

@ -149,6 +149,9 @@ exports.update_stream_name = function (sub, new_name) {
// Update the message feed. // Update the message feed.
message_live_update.update_stream_name(stream_id, new_name); message_live_update.update_stream_name(stream_id, new_name);
// Clear rendered typeahead cache
typeahead_helper.clear_rendered_stream(stream_id);
}; };
exports.update_stream_description = function (sub, description, rendered_description) { exports.update_stream_description = function (sub, description, rendered_description) {

View File

@ -132,6 +132,12 @@ exports.render_person_or_user_group = function (item) {
return typeahead_helper.render_person(item); return typeahead_helper.render_person(item);
}; };
exports.clear_rendered_stream = function (stream_id) {
if (rendered.streams.has(stream_id)) {
rendered.streams.del(stream_id);
}
};
exports.render_stream = function (stream) { exports.render_stream = function (stream) {
var desc = stream.description; var desc = stream.description;
var short_desc = desc.substring(0, 35); var short_desc = desc.substring(0, 35);