topic_data: Rename topic_data module to stream_topic_history.

`stream_topic_history` is a more appropriate name as this
module will contain information about last message of a
stream in upcoming commits. Function and variable names
are changed accordingly like:

* topic_history() -> per_stream_history()
* get_recent_names() -> get_recent_topic_names()
* name -> topic_name
This commit is contained in:
Hashir Sarwar
2020-03-22 22:40:05 +05:00
committed by Tim Abbott
parent c5eddcb1ca
commit ee0d4541b4
28 changed files with 138 additions and 136 deletions

View File

@@ -21,7 +21,7 @@ set_global('md5', function (s) {
stream_data.update_calculated_fields = () => {};
stream_data.set_filter_out_inactives = () => false;
set_global('topic_data', {
set_global('stream_topic_history', {
});
set_global('message_store', {
@@ -281,7 +281,7 @@ const make_emoji = function (emoji_dict) {
};
run_test('topics_seen_for', () => {
topic_data.get_recent_names = (stream_id) => {
stream_topic_history.get_recent_topic_names = (stream_id) => {
assert.equal(stream_id, denmark_stream.stream_id);
return ['With Twisted Metal', 'acceptance', 'civil fears'];
};
@@ -560,7 +560,7 @@ run_test('initialize', () => {
let subject_typeahead_called = false;
$('#stream_message_recipient_topic').typeahead = function (options) {
const topics = ['<&>', 'even more ice', 'furniture', 'ice', 'kronor', 'more ice'];
topic_data.get_recent_names = (stream_id) => {
stream_topic_history.get_recent_topic_names = (stream_id) => {
assert.equal(stream_id, sweden_stream.stream_id);
return topics;
};
@@ -1282,7 +1282,8 @@ run_test('begins_typeahead', () => {
assert_typeahead_equals("#**Sweden>some topic** >", false); // Already completed a topic.
// topic_list
const sweden_topics_to_show = topic_data.get_recent_names(1); //includes "more ice"
// includes "more ice"
const sweden_topics_to_show = stream_topic_history.get_recent_topic_names(1);
assert_typeahead_equals("#**Sweden>more ice", sweden_topics_to_show);
sweden_topics_to_show.push('totally new topic');
assert_typeahead_equals("#**Sweden>totally new topic", sweden_topics_to_show);

View File

@@ -92,7 +92,7 @@ set_global('overlays', {
// For data-oriented modules, just use them, don't stub them.
zrequire('alert_words');
zrequire('unread');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('stream_list');
zrequire('message_flags');
zrequire('message_store');
@@ -1540,7 +1540,7 @@ with_overrides(function (override) {
assert_same(args.message_ids, [1337]);
});
global.with_stub(function (stub) {
override('topic_data.remove_message', stub.f);
override('stream_topic_history.remove_message', stub.f);
dispatch(event);
const args = stub.get_args('opts');
assert_same(args.opts.stream_id, 99);

View File

@@ -98,7 +98,7 @@ alert_words.process_message = noop;
// We can also bring in real code:
zrequire('recent_senders');
zrequire('unread');
zrequire('topic_data');
zrequire('stream_topic_history');
// And finally require the module that we will test directly:
zrequire('message_store');
@@ -118,7 +118,7 @@ run_test('message_store', () => {
assert.equal(message, in_message);
// There are more side effects.
const topic_names = topic_data.get_recent_names(denmark_stream.stream_id);
const topic_names = stream_topic_history.get_recent_topic_names(denmark_stream.stream_id);
assert.deepEqual(topic_names, ['copenhagen']);
});

View File

@@ -4,7 +4,7 @@ zrequire('muting');
zrequire('people');
zrequire('recent_senders');
zrequire('stream_data');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('unread');
set_global('alert_words', {});
@@ -75,7 +75,7 @@ run_test('update_messages', () => {
assert.equal(original_message.unread, true);
assert.deepEqual(
topic_data.get_recent_names(denmark.stream_id),
stream_topic_history.get_recent_topic_names(denmark.stream_id),
['lunch']
);

View File

@@ -12,7 +12,7 @@ set_global('alert_words', {
process_message: noop,
});
set_global('topic_data', {
set_global('stream_topic_history', {
add_message: noop,
});

View File

@@ -213,7 +213,7 @@ run_test('show_invalid_narrow_message', () => {
run_test('narrow_to_compose_target', () => {
set_global('compose_state', {});
set_global('topic_data', {});
set_global('stream_topic_history', {});
const args = {called: false};
const activate_backup = narrow.activate;
narrow.activate = function (operators, opts) {
@@ -239,7 +239,7 @@ run_test('narrow_to_compose_target', () => {
global.compose_state.get_message_type = () => 'stream';
stream_data.add_sub({name: 'ROME', stream_id: 99});
global.compose_state.stream_name = () => 'ROME';
global.topic_data.get_recent_names = () => ['one', 'two', 'three'];
global.stream_topic_history.get_recent_topic_names = () => ['one', 'two', 'three'];
// Test with existing topic
global.compose_state.topic = () => 'one';

View File

@@ -15,7 +15,7 @@ set_global('Handlebars', global.make_handlebars());
zrequire('Filter', 'js/filter');
zrequire('narrow_state');
zrequire('stream_data');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('people');
zrequire('unread');
zrequire('common');
@@ -41,7 +41,7 @@ init();
page_params.is_admin = true;
set_global('narrow', {});
topic_data.reset();
stream_topic_history.reset();
function get_suggestions(base_query, query) {
return search.get_suggestions(base_query, query);
@@ -832,20 +832,20 @@ run_test('topic_suggestions', () => {
}
};
topic_data.reset();
stream_topic_history.reset();
suggestions = get_suggestions('', 'te');
expected = [
"te",
];
assert.deepEqual(suggestions.strings, expected);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: devel_id,
topic_name: 'REXX',
});
for (const topic_name of ['team', 'ignore', 'test']) {
topic_data.add_message({
stream_topic_history.add_message({
stream_id: office_id,
topic_name: topic_name,
});
@@ -924,7 +924,7 @@ run_test('whitespace_glitch', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
const suggestions = get_suggestions('', query);
@@ -944,7 +944,7 @@ run_test('stream_completion', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
let query = 'stream:of';
let suggestions = get_suggestions('s', query);
@@ -996,7 +996,7 @@ function people_suggestion_setup() {
};
people.add(alice);
topic_data.reset();
stream_topic_history.reset();
}
run_test('people_suggestions', () => {
@@ -1151,7 +1151,7 @@ run_test('queries_with_spaces', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
// test allowing spaces with quotes surrounding operand
let query = 'stream:"dev he"';

View File

@@ -14,7 +14,7 @@ set_global('Handlebars', global.make_handlebars());
zrequire('Filter', 'js/filter');
zrequire('narrow_state');
zrequire('stream_data');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('people');
zrequire('unread');
zrequire('common');
@@ -39,7 +39,7 @@ set_global('narrow', {});
page_params.is_admin = true;
topic_data.reset();
stream_topic_history.reset();
run_test('basic_get_suggestions', () => {
const query = 'fred';
@@ -801,20 +801,20 @@ run_test('topic_suggestions', () => {
}
};
topic_data.reset();
stream_topic_history.reset();
suggestions = search.get_suggestions_legacy('te');
expected = [
"te",
];
assert.deepEqual(suggestions.strings, expected);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: devel_id,
topic_name: 'REXX',
});
for (const topic_name of ['team', 'ignore', 'test']) {
topic_data.add_message({
stream_topic_history.add_message({
stream_id: office_id,
topic_name: topic_name,
});
@@ -903,7 +903,7 @@ run_test('whitespace_glitch', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
const suggestions = search.get_suggestions_legacy(query);
@@ -923,7 +923,7 @@ run_test('stream_completion', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
let query = 'stream:of';
let suggestions = search.get_suggestions_legacy(query);
@@ -982,7 +982,8 @@ run_test('people_suggestions', () => {
people.add(bob);
people.add(alice);
topic_data.reset();
stream_topic_history.reset();
let suggestions = search.get_suggestions_legacy(query);
@@ -1099,7 +1100,7 @@ run_test('queries_with_spaces', () => {
return;
};
topic_data.reset();
stream_topic_history.reset();
// test allowing spaces with quotes surrounding operand
let query = 'stream:"dev he"';

View File

@@ -12,7 +12,7 @@ global.stub_out_jquery();
zrequire('color_data');
zrequire('hash_util');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('people');
zrequire('stream_color');
zrequire('stream_data');
@@ -347,7 +347,7 @@ run_test('is_active', () => {
message_id: 108,
topic_name: 'topic2',
};
topic_data.add_message(opts);
stream_topic_history.add_message(opts);
assert(stream_data.is_active(sub));
@@ -375,7 +375,7 @@ run_test('is_active', () => {
assert(stream_data.is_active(sub));
topic_data.add_message(opts);
stream_topic_history.add_message(opts);
assert(stream_data.is_active(sub));
@@ -397,7 +397,7 @@ run_test('is_active', () => {
sub.pin_to_top = true;
assert(stream_data.is_active(sub));
topic_data.add_message(opts);
stream_topic_history.add_message(opts);
assert(stream_data.is_active(sub));
});

View File

@@ -3,7 +3,6 @@ set_global('$', global.make_zjquery());
zrequire('unread_ui');
zrequire('Filter', 'js/filter');
zrequire('topic_data');
zrequire('stream_sort');
zrequire('colorspace');
zrequire('stream_color');

View File

@@ -1,7 +1,7 @@
zrequire('unread');
zrequire('stream_data');
zrequire('topic_data');
zrequire('stream_topic_history');
set_global('channel', {});
set_global('message_list', {});
@@ -9,57 +9,57 @@ set_global('message_list', {});
run_test('basics', () => {
const stream_id = 55;
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 101,
topic_name: 'toPic1',
});
let history = topic_data.get_recent_names(stream_id);
let history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['toPic1']);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 102,
topic_name: 'Topic1',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['Topic1']);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 103,
topic_name: 'topic2',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2', 'Topic1']);
// Removing first topic1 message has no effect.
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: stream_id,
topic_name: 'toPic1',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2', 'Topic1']);
// Removing second topic1 message removes the topic.
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: stream_id,
topic_name: 'Topic1',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2']);
// Test that duplicate remove does not crash us.
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: stream_id,
topic_name: 'Topic1',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2']);
// get to 100% coverage for defensive code
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: 9999999,
});
});
@@ -83,7 +83,7 @@ run_test('is_complete_for_stream_id', () => {
};
assert.equal(
topic_data.is_complete_for_stream_id(sub.stream_id),
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
true);
// Now simulate a more recent message id.
@@ -94,15 +94,15 @@ run_test('is_complete_for_stream_id', () => {
// Note that we'll return `true` here due to
// fetched_stream_ids having the stream_id now.
assert.equal(
topic_data.is_complete_for_stream_id(sub.stream_id),
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
true);
// But now clear the data to see what we'd have without
// the previous call.
topic_data.reset();
stream_topic_history.reset();
assert.equal(
topic_data.is_complete_for_stream_id(sub.stream_id),
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
false);
});
@@ -117,20 +117,20 @@ run_test('server_history', () => {
message_list.all.fetch_status.has_found_newest = () => false;
assert.equal(
topic_data.is_complete_for_stream_id(stream_id),
stream_topic_history.is_complete_for_stream_id(stream_id),
false);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 501,
topic_name: 'local',
});
function add_server_history() {
topic_data.add_history(stream_id, [
{ name: 'local', max_id: 501 },
{ name: 'hist2', max_id: 31 },
{ name: 'hist1', max_id: 30 },
stream_topic_history.add_history(stream_id, [
{ topic_name: 'local', max_id: 501 },
{ topic_name: 'hist2', max_id: 31 },
{ topic_name: 'hist1', max_id: 30 },
]);
}
@@ -139,73 +139,73 @@ run_test('server_history', () => {
// Since we added history, now subsequent calls
// to is_complete_for_stream_id will return true.
assert.equal(
topic_data.is_complete_for_stream_id(stream_id),
stream_topic_history.is_complete_for_stream_id(stream_id),
true);
let history = topic_data.get_recent_names(stream_id);
let history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['local', 'hist2', 'hist1']);
// If new activity comes in for historical messages,
// they can bump to the front of the list.
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 502,
topic_name: 'hist1',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['hist1', 'local', 'hist2']);
// server history is allowed to backdate hist1
add_server_history();
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['local', 'hist2', 'hist1']);
// Removing a local message removes the topic if we have
// our counts right.
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: stream_id,
topic_name: 'local',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['hist2', 'hist1']);
// We can try to remove a historical message, but it should
// have no effect.
topic_data.remove_message({
stream_topic_history.remove_message({
stream_id: stream_id,
topic_name: 'hist2',
});
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['hist2', 'hist1']);
// If we call back to the server for history, the
// effect is always additive. We may decide to prune old
// topics in the future, if they dropped off due to renames,
// but that is probably an edge case we can ignore for now.
topic_data.add_history(stream_id, [
{ name: 'hist2', max_id: 931 },
{ name: 'hist3', max_id: 5 },
stream_topic_history.add_history(stream_id, [
{ topic_name: 'hist2', max_id: 931 },
{ topic_name: 'hist3', max_id: 5 },
]);
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['hist2', 'hist1', 'hist3']);
});
run_test('test_unread_logic', () => {
const stream_id = 77;
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 201,
topic_name: 'toPic1',
});
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 45,
topic_name: 'topic2',
});
let history = topic_data.get_recent_names(stream_id);
let history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['toPic1', 'topic2']);
const msgs = [
@@ -223,39 +223,39 @@ run_test('test_unread_logic', () => {
unread.process_loaded_messages(msgs);
history = topic_data.get_recent_names(stream_id);
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['toPic1', 'unread1', 'topic2', 'UNREAD2']);
});
run_test('test_stream_has_topics', () => {
const stream_id = 88;
assert.equal(topic_data.stream_has_topics(stream_id), false);
assert.equal(stream_topic_history.stream_has_topics(stream_id), false);
topic_data.find_or_create(stream_id);
stream_topic_history.find_or_create(stream_id);
// This was a bug before--just creating a bucket does not
// mean we have actual topics.
assert.equal(topic_data.stream_has_topics(stream_id), false);
assert.equal(stream_topic_history.stream_has_topics(stream_id), false);
topic_data.add_message({
stream_topic_history.add_message({
stream_id: stream_id,
message_id: 888,
topic_name: 'whatever',
});
assert.equal(topic_data.stream_has_topics(stream_id), true);
assert.equal(stream_topic_history.stream_has_topics(stream_id), true);
});
run_test('server_history_end_to_end', () => {
topic_data.reset();
stream_topic_history.reset();
const stream_id = 99;
const topics = [
{ name: 'topic3', max_id: 501 },
{ name: 'topic2', max_id: 31 },
{ name: 'topic1', max_id: 30 },
{ topic_name: 'topic3', max_id: 501 },
{ topic_name: 'topic2', max_id: 31 },
{ topic_name: 'topic1', max_id: 30 },
];
let get_success_callback;
@@ -267,7 +267,7 @@ run_test('server_history_end_to_end', () => {
get_success_callback = opts.success;
};
topic_data.get_server_history(stream_id, () => {
stream_topic_history.get_server_history(stream_id, () => {
on_success_called = true;
});
@@ -275,7 +275,7 @@ run_test('server_history_end_to_end', () => {
assert(on_success_called);
const history = topic_data.get_recent_names(stream_id);
const history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic3', 'topic2', 'topic1']);
// Try getting server history for a second time.
@@ -285,7 +285,7 @@ run_test('server_history_end_to_end', () => {
};
on_success_called = false;
topic_data.get_server_history(stream_id, () => {
stream_topic_history.get_server_history(stream_id, () => {
on_success_called = true;
});
assert(on_success_called);

View File

@@ -5,7 +5,7 @@ set_global('pm_conversations', {
zrequire('muting');
zrequire('unread');
zrequire('stream_data');
zrequire('topic_data');
zrequire('stream_topic_history');
zrequire('stream_sort');
const tg = zrequire('topic_generator');
@@ -264,7 +264,7 @@ run_test('topics', () => {
devel: devel_stream_id,
};
topic_data.get_recent_names = function (stream_id) {
stream_topic_history.get_recent_topic_names = function (stream_id) {
switch (stream_id) {
case muted_stream_id:
return ['ms-topic1', 'ms-topic2'];

View File

@@ -6,7 +6,7 @@ set_global('message_list', {});
zrequire('hash_util');
zrequire('stream_data');
zrequire('unread');
zrequire('topic_data');
zrequire('stream_topic_history');
const topic_list_data = zrequire('topic_list_data');
const general = {
@@ -18,7 +18,7 @@ stream_data.add_sub(general);
function clear() {
narrow_state.topic = () => undefined;
topic_data.reset();
stream_topic_history.reset();
muting.is_topic_muted = () => false;
}
@@ -28,7 +28,7 @@ function get_list_info(zoomed) {
stream_id, zoomed);
}
run_test('get_list_info w/real topic_data', () => {
run_test('get_list_info w/real stream_topic_history', () => {
clear();
let list_info;
@@ -42,7 +42,7 @@ run_test('get_list_info w/real topic_data', () => {
for (const i of _.range(7)) {
const topic_name = 'topic ' + i;
topic_data.add_message({
stream_topic_history.add_message({
stream_id: general.stream_id,
topic_name: topic_name,
message_id: 1000 + i,
@@ -78,9 +78,9 @@ run_test('get_list_info unreads', () => {
let list_info;
// Going forward, we just stub get_recent_names
// Going forward, we just stub get_recent_topic_names
// for simpler test setup.
topic_data.get_recent_names = () => {
stream_topic_history.get_recent_topic_names = () => {
return _.range(15).map(i => 'topic ' + i);
};