mirror of https://github.com/zulip/zulip.git
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:
parent
c5eddcb1ca
commit
ee0d4541b4
|
@ -367,6 +367,7 @@
|
||||||
"stream_data": false,
|
"stream_data": false,
|
||||||
"stream_edit": false,
|
"stream_edit": false,
|
||||||
"stream_events": false,
|
"stream_events": false,
|
||||||
|
"stream_topic_history": false,
|
||||||
"stream_list": false,
|
"stream_list": false,
|
||||||
"stream_muting": false,
|
"stream_muting": false,
|
||||||
"stream_popover": false,
|
"stream_popover": false,
|
||||||
|
@ -381,7 +382,6 @@
|
||||||
"timerender": false,
|
"timerender": false,
|
||||||
"todo_widget": false,
|
"todo_widget": false,
|
||||||
"top_left_corner": false,
|
"top_left_corner": false,
|
||||||
"topic_data": false,
|
|
||||||
"topic_generator": false,
|
"topic_generator": false,
|
||||||
"topic_list": false,
|
"topic_list": false,
|
||||||
"topic_zoom": false,
|
"topic_zoom": false,
|
||||||
|
|
|
@ -21,7 +21,7 @@ set_global('md5', function (s) {
|
||||||
stream_data.update_calculated_fields = () => {};
|
stream_data.update_calculated_fields = () => {};
|
||||||
stream_data.set_filter_out_inactives = () => false;
|
stream_data.set_filter_out_inactives = () => false;
|
||||||
|
|
||||||
set_global('topic_data', {
|
set_global('stream_topic_history', {
|
||||||
});
|
});
|
||||||
|
|
||||||
set_global('message_store', {
|
set_global('message_store', {
|
||||||
|
@ -281,7 +281,7 @@ const make_emoji = function (emoji_dict) {
|
||||||
};
|
};
|
||||||
|
|
||||||
run_test('topics_seen_for', () => {
|
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);
|
assert.equal(stream_id, denmark_stream.stream_id);
|
||||||
return ['With Twisted Metal', 'acceptance', 'civil fears'];
|
return ['With Twisted Metal', 'acceptance', 'civil fears'];
|
||||||
};
|
};
|
||||||
|
@ -560,7 +560,7 @@ run_test('initialize', () => {
|
||||||
let subject_typeahead_called = false;
|
let subject_typeahead_called = false;
|
||||||
$('#stream_message_recipient_topic').typeahead = function (options) {
|
$('#stream_message_recipient_topic').typeahead = function (options) {
|
||||||
const topics = ['<&>', 'even more ice', 'furniture', 'ice', 'kronor', 'more ice'];
|
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);
|
assert.equal(stream_id, sweden_stream.stream_id);
|
||||||
return topics;
|
return topics;
|
||||||
};
|
};
|
||||||
|
@ -1282,7 +1282,8 @@ run_test('begins_typeahead', () => {
|
||||||
assert_typeahead_equals("#**Sweden>some topic** >", false); // Already completed a topic.
|
assert_typeahead_equals("#**Sweden>some topic** >", false); // Already completed a topic.
|
||||||
|
|
||||||
// topic_list
|
// 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);
|
assert_typeahead_equals("#**Sweden>more ice", sweden_topics_to_show);
|
||||||
sweden_topics_to_show.push('totally new topic');
|
sweden_topics_to_show.push('totally new topic');
|
||||||
assert_typeahead_equals("#**Sweden>totally new topic", sweden_topics_to_show);
|
assert_typeahead_equals("#**Sweden>totally new topic", sweden_topics_to_show);
|
||||||
|
|
|
@ -92,7 +92,7 @@ set_global('overlays', {
|
||||||
// For data-oriented modules, just use them, don't stub them.
|
// For data-oriented modules, just use them, don't stub them.
|
||||||
zrequire('alert_words');
|
zrequire('alert_words');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('stream_list');
|
zrequire('stream_list');
|
||||||
zrequire('message_flags');
|
zrequire('message_flags');
|
||||||
zrequire('message_store');
|
zrequire('message_store');
|
||||||
|
@ -1540,7 +1540,7 @@ with_overrides(function (override) {
|
||||||
assert_same(args.message_ids, [1337]);
|
assert_same(args.message_ids, [1337]);
|
||||||
});
|
});
|
||||||
global.with_stub(function (stub) {
|
global.with_stub(function (stub) {
|
||||||
override('topic_data.remove_message', stub.f);
|
override('stream_topic_history.remove_message', stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
const args = stub.get_args('opts');
|
const args = stub.get_args('opts');
|
||||||
assert_same(args.opts.stream_id, 99);
|
assert_same(args.opts.stream_id, 99);
|
||||||
|
|
|
@ -98,7 +98,7 @@ alert_words.process_message = noop;
|
||||||
// We can also bring in real code:
|
// We can also bring in real code:
|
||||||
zrequire('recent_senders');
|
zrequire('recent_senders');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
|
|
||||||
// And finally require the module that we will test directly:
|
// And finally require the module that we will test directly:
|
||||||
zrequire('message_store');
|
zrequire('message_store');
|
||||||
|
@ -118,7 +118,7 @@ run_test('message_store', () => {
|
||||||
assert.equal(message, in_message);
|
assert.equal(message, in_message);
|
||||||
|
|
||||||
// There are more side effects.
|
// 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']);
|
assert.deepEqual(topic_names, ['copenhagen']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ zrequire('muting');
|
||||||
zrequire('people');
|
zrequire('people');
|
||||||
zrequire('recent_senders');
|
zrequire('recent_senders');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
|
|
||||||
set_global('alert_words', {});
|
set_global('alert_words', {});
|
||||||
|
@ -75,7 +75,7 @@ run_test('update_messages', () => {
|
||||||
assert.equal(original_message.unread, true);
|
assert.equal(original_message.unread, true);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
topic_data.get_recent_names(denmark.stream_id),
|
stream_topic_history.get_recent_topic_names(denmark.stream_id),
|
||||||
['lunch']
|
['lunch']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ set_global('alert_words', {
|
||||||
process_message: noop,
|
process_message: noop,
|
||||||
});
|
});
|
||||||
|
|
||||||
set_global('topic_data', {
|
set_global('stream_topic_history', {
|
||||||
add_message: noop,
|
add_message: noop,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ run_test('show_invalid_narrow_message', () => {
|
||||||
|
|
||||||
run_test('narrow_to_compose_target', () => {
|
run_test('narrow_to_compose_target', () => {
|
||||||
set_global('compose_state', {});
|
set_global('compose_state', {});
|
||||||
set_global('topic_data', {});
|
set_global('stream_topic_history', {});
|
||||||
const args = {called: false};
|
const args = {called: false};
|
||||||
const activate_backup = narrow.activate;
|
const activate_backup = narrow.activate;
|
||||||
narrow.activate = function (operators, opts) {
|
narrow.activate = function (operators, opts) {
|
||||||
|
@ -239,7 +239,7 @@ run_test('narrow_to_compose_target', () => {
|
||||||
global.compose_state.get_message_type = () => 'stream';
|
global.compose_state.get_message_type = () => 'stream';
|
||||||
stream_data.add_sub({name: 'ROME', stream_id: 99});
|
stream_data.add_sub({name: 'ROME', stream_id: 99});
|
||||||
global.compose_state.stream_name = () => 'ROME';
|
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
|
// Test with existing topic
|
||||||
global.compose_state.topic = () => 'one';
|
global.compose_state.topic = () => 'one';
|
||||||
|
|
|
@ -15,7 +15,7 @@ set_global('Handlebars', global.make_handlebars());
|
||||||
zrequire('Filter', 'js/filter');
|
zrequire('Filter', 'js/filter');
|
||||||
zrequire('narrow_state');
|
zrequire('narrow_state');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('people');
|
zrequire('people');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('common');
|
zrequire('common');
|
||||||
|
@ -41,7 +41,7 @@ init();
|
||||||
page_params.is_admin = true;
|
page_params.is_admin = true;
|
||||||
set_global('narrow', {});
|
set_global('narrow', {});
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
function get_suggestions(base_query, query) {
|
function get_suggestions(base_query, query) {
|
||||||
return search.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');
|
suggestions = get_suggestions('', 'te');
|
||||||
expected = [
|
expected = [
|
||||||
"te",
|
"te",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: devel_id,
|
stream_id: devel_id,
|
||||||
topic_name: 'REXX',
|
topic_name: 'REXX',
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const topic_name of ['team', 'ignore', 'test']) {
|
for (const topic_name of ['team', 'ignore', 'test']) {
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: office_id,
|
stream_id: office_id,
|
||||||
topic_name: topic_name,
|
topic_name: topic_name,
|
||||||
});
|
});
|
||||||
|
@ -924,7 +924,7 @@ run_test('whitespace_glitch', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
const suggestions = get_suggestions('', query);
|
const suggestions = get_suggestions('', query);
|
||||||
|
|
||||||
|
@ -944,7 +944,7 @@ run_test('stream_completion', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
let query = 'stream:of';
|
let query = 'stream:of';
|
||||||
let suggestions = get_suggestions('s', query);
|
let suggestions = get_suggestions('s', query);
|
||||||
|
@ -996,7 +996,7 @@ function people_suggestion_setup() {
|
||||||
};
|
};
|
||||||
people.add(alice);
|
people.add(alice);
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('people_suggestions', () => {
|
run_test('people_suggestions', () => {
|
||||||
|
@ -1151,7 +1151,7 @@ run_test('queries_with_spaces', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
// test allowing spaces with quotes surrounding operand
|
// test allowing spaces with quotes surrounding operand
|
||||||
let query = 'stream:"dev he"';
|
let query = 'stream:"dev he"';
|
||||||
|
|
|
@ -14,7 +14,7 @@ set_global('Handlebars', global.make_handlebars());
|
||||||
zrequire('Filter', 'js/filter');
|
zrequire('Filter', 'js/filter');
|
||||||
zrequire('narrow_state');
|
zrequire('narrow_state');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('people');
|
zrequire('people');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('common');
|
zrequire('common');
|
||||||
|
@ -39,7 +39,7 @@ set_global('narrow', {});
|
||||||
|
|
||||||
page_params.is_admin = true;
|
page_params.is_admin = true;
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
run_test('basic_get_suggestions', () => {
|
run_test('basic_get_suggestions', () => {
|
||||||
const query = 'fred';
|
const query = 'fred';
|
||||||
|
@ -801,20 +801,20 @@ run_test('topic_suggestions', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
suggestions = search.get_suggestions_legacy('te');
|
suggestions = search.get_suggestions_legacy('te');
|
||||||
expected = [
|
expected = [
|
||||||
"te",
|
"te",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: devel_id,
|
stream_id: devel_id,
|
||||||
topic_name: 'REXX',
|
topic_name: 'REXX',
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const topic_name of ['team', 'ignore', 'test']) {
|
for (const topic_name of ['team', 'ignore', 'test']) {
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: office_id,
|
stream_id: office_id,
|
||||||
topic_name: topic_name,
|
topic_name: topic_name,
|
||||||
});
|
});
|
||||||
|
@ -903,7 +903,7 @@ run_test('whitespace_glitch', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
const suggestions = search.get_suggestions_legacy(query);
|
const suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
|
@ -923,7 +923,7 @@ run_test('stream_completion', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
let query = 'stream:of';
|
let query = 'stream:of';
|
||||||
let suggestions = search.get_suggestions_legacy(query);
|
let suggestions = search.get_suggestions_legacy(query);
|
||||||
|
@ -982,7 +982,8 @@ run_test('people_suggestions', () => {
|
||||||
people.add(bob);
|
people.add(bob);
|
||||||
people.add(alice);
|
people.add(alice);
|
||||||
|
|
||||||
topic_data.reset();
|
|
||||||
|
stream_topic_history.reset();
|
||||||
|
|
||||||
let suggestions = search.get_suggestions_legacy(query);
|
let suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
|
@ -1099,7 +1100,7 @@ run_test('queries_with_spaces', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
// test allowing spaces with quotes surrounding operand
|
// test allowing spaces with quotes surrounding operand
|
||||||
let query = 'stream:"dev he"';
|
let query = 'stream:"dev he"';
|
||||||
|
|
|
@ -12,7 +12,7 @@ global.stub_out_jquery();
|
||||||
|
|
||||||
zrequire('color_data');
|
zrequire('color_data');
|
||||||
zrequire('hash_util');
|
zrequire('hash_util');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('people');
|
zrequire('people');
|
||||||
zrequire('stream_color');
|
zrequire('stream_color');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
|
@ -347,7 +347,7 @@ run_test('is_active', () => {
|
||||||
message_id: 108,
|
message_id: 108,
|
||||||
topic_name: 'topic2',
|
topic_name: 'topic2',
|
||||||
};
|
};
|
||||||
topic_data.add_message(opts);
|
stream_topic_history.add_message(opts);
|
||||||
|
|
||||||
assert(stream_data.is_active(sub));
|
assert(stream_data.is_active(sub));
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ run_test('is_active', () => {
|
||||||
|
|
||||||
assert(stream_data.is_active(sub));
|
assert(stream_data.is_active(sub));
|
||||||
|
|
||||||
topic_data.add_message(opts);
|
stream_topic_history.add_message(opts);
|
||||||
|
|
||||||
assert(stream_data.is_active(sub));
|
assert(stream_data.is_active(sub));
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ run_test('is_active', () => {
|
||||||
sub.pin_to_top = true;
|
sub.pin_to_top = true;
|
||||||
assert(stream_data.is_active(sub));
|
assert(stream_data.is_active(sub));
|
||||||
|
|
||||||
topic_data.add_message(opts);
|
stream_topic_history.add_message(opts);
|
||||||
|
|
||||||
assert(stream_data.is_active(sub));
|
assert(stream_data.is_active(sub));
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,6 @@ set_global('$', global.make_zjquery());
|
||||||
|
|
||||||
zrequire('unread_ui');
|
zrequire('unread_ui');
|
||||||
zrequire('Filter', 'js/filter');
|
zrequire('Filter', 'js/filter');
|
||||||
zrequire('topic_data');
|
|
||||||
zrequire('stream_sort');
|
zrequire('stream_sort');
|
||||||
zrequire('colorspace');
|
zrequire('colorspace');
|
||||||
zrequire('stream_color');
|
zrequire('stream_color');
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
|
|
||||||
set_global('channel', {});
|
set_global('channel', {});
|
||||||
set_global('message_list', {});
|
set_global('message_list', {});
|
||||||
|
@ -9,57 +9,57 @@ set_global('message_list', {});
|
||||||
run_test('basics', () => {
|
run_test('basics', () => {
|
||||||
const stream_id = 55;
|
const stream_id = 55;
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 101,
|
message_id: 101,
|
||||||
topic_name: 'toPic1',
|
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']);
|
assert.deepEqual(history, ['toPic1']);
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 102,
|
message_id: 102,
|
||||||
topic_name: 'Topic1',
|
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']);
|
assert.deepEqual(history, ['Topic1']);
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 103,
|
message_id: 103,
|
||||||
topic_name: 'topic2',
|
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']);
|
assert.deepEqual(history, ['topic2', 'Topic1']);
|
||||||
|
|
||||||
// Removing first topic1 message has no effect.
|
// Removing first topic1 message has no effect.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
topic_name: 'toPic1',
|
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']);
|
assert.deepEqual(history, ['topic2', 'Topic1']);
|
||||||
|
|
||||||
// Removing second topic1 message removes the topic.
|
// Removing second topic1 message removes the topic.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
topic_name: 'Topic1',
|
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']);
|
assert.deepEqual(history, ['topic2']);
|
||||||
|
|
||||||
// Test that duplicate remove does not crash us.
|
// Test that duplicate remove does not crash us.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
topic_name: 'Topic1',
|
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']);
|
assert.deepEqual(history, ['topic2']);
|
||||||
|
|
||||||
// get to 100% coverage for defensive code
|
// get to 100% coverage for defensive code
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: 9999999,
|
stream_id: 9999999,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -83,7 +83,7 @@ run_test('is_complete_for_stream_id', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
topic_data.is_complete_for_stream_id(sub.stream_id),
|
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
// Now simulate a more recent message id.
|
// 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
|
// Note that we'll return `true` here due to
|
||||||
// fetched_stream_ids having the stream_id now.
|
// fetched_stream_ids having the stream_id now.
|
||||||
assert.equal(
|
assert.equal(
|
||||||
topic_data.is_complete_for_stream_id(sub.stream_id),
|
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
// But now clear the data to see what we'd have without
|
// But now clear the data to see what we'd have without
|
||||||
// the previous call.
|
// the previous call.
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
topic_data.is_complete_for_stream_id(sub.stream_id),
|
stream_topic_history.is_complete_for_stream_id(sub.stream_id),
|
||||||
false);
|
false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -117,20 +117,20 @@ run_test('server_history', () => {
|
||||||
message_list.all.fetch_status.has_found_newest = () => false;
|
message_list.all.fetch_status.has_found_newest = () => false;
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
topic_data.is_complete_for_stream_id(stream_id),
|
stream_topic_history.is_complete_for_stream_id(stream_id),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 501,
|
message_id: 501,
|
||||||
topic_name: 'local',
|
topic_name: 'local',
|
||||||
});
|
});
|
||||||
|
|
||||||
function add_server_history() {
|
function add_server_history() {
|
||||||
topic_data.add_history(stream_id, [
|
stream_topic_history.add_history(stream_id, [
|
||||||
{ name: 'local', max_id: 501 },
|
{ topic_name: 'local', max_id: 501 },
|
||||||
{ name: 'hist2', max_id: 31 },
|
{ topic_name: 'hist2', max_id: 31 },
|
||||||
{ name: 'hist1', max_id: 30 },
|
{ topic_name: 'hist1', max_id: 30 },
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,73 +139,73 @@ run_test('server_history', () => {
|
||||||
// Since we added history, now subsequent calls
|
// Since we added history, now subsequent calls
|
||||||
// to is_complete_for_stream_id will return true.
|
// to is_complete_for_stream_id will return true.
|
||||||
assert.equal(
|
assert.equal(
|
||||||
topic_data.is_complete_for_stream_id(stream_id),
|
stream_topic_history.is_complete_for_stream_id(stream_id),
|
||||||
true);
|
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']);
|
assert.deepEqual(history, ['local', 'hist2', 'hist1']);
|
||||||
|
|
||||||
// If new activity comes in for historical messages,
|
// If new activity comes in for historical messages,
|
||||||
// they can bump to the front of the list.
|
// they can bump to the front of the list.
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 502,
|
message_id: 502,
|
||||||
topic_name: 'hist1',
|
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']);
|
assert.deepEqual(history, ['hist1', 'local', 'hist2']);
|
||||||
|
|
||||||
// server history is allowed to backdate hist1
|
// server history is allowed to backdate hist1
|
||||||
add_server_history();
|
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']);
|
assert.deepEqual(history, ['local', 'hist2', 'hist1']);
|
||||||
|
|
||||||
// Removing a local message removes the topic if we have
|
// Removing a local message removes the topic if we have
|
||||||
// our counts right.
|
// our counts right.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
topic_name: 'local',
|
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']);
|
assert.deepEqual(history, ['hist2', 'hist1']);
|
||||||
|
|
||||||
// We can try to remove a historical message, but it should
|
// We can try to remove a historical message, but it should
|
||||||
// have no effect.
|
// have no effect.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
topic_name: 'hist2',
|
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']);
|
assert.deepEqual(history, ['hist2', 'hist1']);
|
||||||
|
|
||||||
// If we call back to the server for history, the
|
// If we call back to the server for history, the
|
||||||
// effect is always additive. We may decide to prune old
|
// effect is always additive. We may decide to prune old
|
||||||
// topics in the future, if they dropped off due to renames,
|
// topics in the future, if they dropped off due to renames,
|
||||||
// but that is probably an edge case we can ignore for now.
|
// but that is probably an edge case we can ignore for now.
|
||||||
topic_data.add_history(stream_id, [
|
stream_topic_history.add_history(stream_id, [
|
||||||
{ name: 'hist2', max_id: 931 },
|
{ topic_name: 'hist2', max_id: 931 },
|
||||||
{ name: 'hist3', max_id: 5 },
|
{ 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']);
|
assert.deepEqual(history, ['hist2', 'hist1', 'hist3']);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('test_unread_logic', () => {
|
run_test('test_unread_logic', () => {
|
||||||
const stream_id = 77;
|
const stream_id = 77;
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 201,
|
message_id: 201,
|
||||||
topic_name: 'toPic1',
|
topic_name: 'toPic1',
|
||||||
});
|
});
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: stream_id,
|
stream_id: stream_id,
|
||||||
message_id: 45,
|
message_id: 45,
|
||||||
topic_name: 'topic2',
|
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']);
|
assert.deepEqual(history, ['toPic1', 'topic2']);
|
||||||
|
|
||||||
const msgs = [
|
const msgs = [
|
||||||
|
@ -223,39 +223,39 @@ run_test('test_unread_logic', () => {
|
||||||
|
|
||||||
unread.process_loaded_messages(msgs);
|
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']);
|
assert.deepEqual(history, ['toPic1', 'unread1', 'topic2', 'UNREAD2']);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('test_stream_has_topics', () => {
|
run_test('test_stream_has_topics', () => {
|
||||||
const stream_id = 88;
|
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
|
// This was a bug before--just creating a bucket does not
|
||||||
// mean we have actual topics.
|
// 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,
|
stream_id: stream_id,
|
||||||
message_id: 888,
|
message_id: 888,
|
||||||
topic_name: 'whatever',
|
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', () => {
|
run_test('server_history_end_to_end', () => {
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
const stream_id = 99;
|
const stream_id = 99;
|
||||||
|
|
||||||
const topics = [
|
const topics = [
|
||||||
{ name: 'topic3', max_id: 501 },
|
{ topic_name: 'topic3', max_id: 501 },
|
||||||
{ name: 'topic2', max_id: 31 },
|
{ topic_name: 'topic2', max_id: 31 },
|
||||||
{ name: 'topic1', max_id: 30 },
|
{ topic_name: 'topic1', max_id: 30 },
|
||||||
];
|
];
|
||||||
|
|
||||||
let get_success_callback;
|
let get_success_callback;
|
||||||
|
@ -267,7 +267,7 @@ run_test('server_history_end_to_end', () => {
|
||||||
get_success_callback = opts.success;
|
get_success_callback = opts.success;
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.get_server_history(stream_id, () => {
|
stream_topic_history.get_server_history(stream_id, () => {
|
||||||
on_success_called = true;
|
on_success_called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ run_test('server_history_end_to_end', () => {
|
||||||
|
|
||||||
assert(on_success_called);
|
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']);
|
assert.deepEqual(history, ['topic3', 'topic2', 'topic1']);
|
||||||
|
|
||||||
// Try getting server history for a second time.
|
// Try getting server history for a second time.
|
||||||
|
@ -285,7 +285,7 @@ run_test('server_history_end_to_end', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
on_success_called = false;
|
on_success_called = false;
|
||||||
topic_data.get_server_history(stream_id, () => {
|
stream_topic_history.get_server_history(stream_id, () => {
|
||||||
on_success_called = true;
|
on_success_called = true;
|
||||||
});
|
});
|
||||||
assert(on_success_called);
|
assert(on_success_called);
|
|
@ -5,7 +5,7 @@ set_global('pm_conversations', {
|
||||||
zrequire('muting');
|
zrequire('muting');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
zrequire('stream_sort');
|
zrequire('stream_sort');
|
||||||
const tg = zrequire('topic_generator');
|
const tg = zrequire('topic_generator');
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ run_test('topics', () => {
|
||||||
devel: devel_stream_id,
|
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) {
|
switch (stream_id) {
|
||||||
case muted_stream_id:
|
case muted_stream_id:
|
||||||
return ['ms-topic1', 'ms-topic2'];
|
return ['ms-topic1', 'ms-topic2'];
|
||||||
|
|
|
@ -6,7 +6,7 @@ set_global('message_list', {});
|
||||||
zrequire('hash_util');
|
zrequire('hash_util');
|
||||||
zrequire('stream_data');
|
zrequire('stream_data');
|
||||||
zrequire('unread');
|
zrequire('unread');
|
||||||
zrequire('topic_data');
|
zrequire('stream_topic_history');
|
||||||
const topic_list_data = zrequire('topic_list_data');
|
const topic_list_data = zrequire('topic_list_data');
|
||||||
|
|
||||||
const general = {
|
const general = {
|
||||||
|
@ -18,7 +18,7 @@ stream_data.add_sub(general);
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
narrow_state.topic = () => undefined;
|
narrow_state.topic = () => undefined;
|
||||||
topic_data.reset();
|
stream_topic_history.reset();
|
||||||
muting.is_topic_muted = () => false;
|
muting.is_topic_muted = () => false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ function get_list_info(zoomed) {
|
||||||
stream_id, zoomed);
|
stream_id, zoomed);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('get_list_info w/real topic_data', () => {
|
run_test('get_list_info w/real stream_topic_history', () => {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
let list_info;
|
let list_info;
|
||||||
|
@ -42,7 +42,7 @@ run_test('get_list_info w/real topic_data', () => {
|
||||||
|
|
||||||
for (const i of _.range(7)) {
|
for (const i of _.range(7)) {
|
||||||
const topic_name = 'topic ' + i;
|
const topic_name = 'topic ' + i;
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: general.stream_id,
|
stream_id: general.stream_id,
|
||||||
topic_name: topic_name,
|
topic_name: topic_name,
|
||||||
message_id: 1000 + i,
|
message_id: 1000 + i,
|
||||||
|
@ -78,9 +78,9 @@ run_test('get_list_info unreads', () => {
|
||||||
|
|
||||||
let list_info;
|
let list_info;
|
||||||
|
|
||||||
// Going forward, we just stub get_recent_names
|
// Going forward, we just stub get_recent_topic_names
|
||||||
// for simpler test setup.
|
// for simpler test setup.
|
||||||
topic_data.get_recent_names = () => {
|
stream_topic_history.get_recent_topic_names = () => {
|
||||||
return _.range(15).map(i => 'topic ' + i);
|
return _.range(15).map(i => 'topic ' + i);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ import "../upload.js";
|
||||||
import "../color_data.js";
|
import "../color_data.js";
|
||||||
import "../stream_color.js";
|
import "../stream_color.js";
|
||||||
import "../stream_data.js";
|
import "../stream_data.js";
|
||||||
import "../topic_data.js";
|
import "../stream_topic_history.js";
|
||||||
import "../stream_muting.js";
|
import "../stream_muting.js";
|
||||||
import "../stream_events.js";
|
import "../stream_events.js";
|
||||||
import "../stream_create.js";
|
import "../stream_create.js";
|
||||||
|
|
|
@ -44,7 +44,7 @@ exports.topics_seen_for = function (stream_name) {
|
||||||
if (!stream_id) {
|
if (!stream_id) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const topic_names = topic_data.get_recent_names(stream_id);
|
const topic_names = stream_topic_history.get_recent_topic_names(stream_id);
|
||||||
return topic_names;
|
return topic_names;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -192,14 +192,14 @@ exports.edit_locally = function (message, request) {
|
||||||
|
|
||||||
if (request.new_topic !== undefined) {
|
if (request.new_topic !== undefined) {
|
||||||
const new_topic = request.new_topic;
|
const new_topic = request.new_topic;
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: message.stream_id,
|
stream_id: message.stream_id,
|
||||||
topic_name: message.topic,
|
topic_name: message.topic,
|
||||||
});
|
});
|
||||||
|
|
||||||
message.topic = new_topic;
|
message.topic = new_topic;
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: message.stream_id,
|
stream_id: message.stream_id,
|
||||||
topic_name: message.topic,
|
topic_name: message.topic,
|
||||||
message_id: message.id,
|
message_id: message.id,
|
||||||
|
|
|
@ -153,7 +153,7 @@ declare let templates: any;
|
||||||
declare let tictactoe_widget: any;
|
declare let tictactoe_widget: any;
|
||||||
declare let timerender: any;
|
declare let timerender: any;
|
||||||
declare let todo_widget: any;
|
declare let todo_widget: any;
|
||||||
declare let topic_data: any;
|
declare let stream_topic_history: any;
|
||||||
declare let topic_generator: any;
|
declare let topic_generator: any;
|
||||||
declare let topic_list: any;
|
declare let topic_list: any;
|
||||||
declare let topic_zoom: any;
|
declare let topic_zoom: any;
|
||||||
|
|
|
@ -229,7 +229,7 @@ exports.update_messages = function update_messages(events) {
|
||||||
|
|
||||||
// Remove the recent topics entry for the old topics;
|
// Remove the recent topics entry for the old topics;
|
||||||
// must be called before we call set_message_topic.
|
// must be called before we call set_message_topic.
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: msg.stream_id,
|
stream_id: msg.stream_id,
|
||||||
topic_name: msg.topic,
|
topic_name: msg.topic,
|
||||||
});
|
});
|
||||||
|
@ -251,7 +251,7 @@ exports.update_messages = function update_messages(events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the recent topics entry for the new stream/topics.
|
// Add the recent topics entry for the new stream/topics.
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: msg.stream_id,
|
stream_id: msg.stream_id,
|
||||||
topic_name: msg.topic,
|
topic_name: msg.topic,
|
||||||
message_id: msg.id,
|
message_id: msg.id,
|
||||||
|
|
|
@ -169,7 +169,7 @@ exports.add_message_metadata = function (message) {
|
||||||
message.stream = message.display_recipient;
|
message.stream = message.display_recipient;
|
||||||
message.reply_to = message.sender_email;
|
message.reply_to = message.sender_email;
|
||||||
|
|
||||||
topic_data.add_message({
|
stream_topic_history.add_message({
|
||||||
stream_id: message.stream_id,
|
stream_id: message.stream_id,
|
||||||
topic_name: message.topic,
|
topic_name: message.topic,
|
||||||
message_id: message.id,
|
message_id: message.id,
|
||||||
|
|
|
@ -701,7 +701,7 @@ exports.to_compose_target = function () {
|
||||||
}
|
}
|
||||||
// If we are composing to a new topic, we narrow to the stream but
|
// If we are composing to a new topic, we narrow to the stream but
|
||||||
// grey-out the message view instead of narrowing to an empty view.
|
// grey-out the message view instead of narrowing to an empty view.
|
||||||
const topics = topic_data.get_recent_names(stream_id);
|
const topics = stream_topic_history.get_recent_topic_names(stream_id);
|
||||||
const operators = [{operator: 'stream', operand: stream_name}];
|
const operators = [{operator: 'stream', operand: stream_name}];
|
||||||
const topic = compose_state.topic();
|
const topic = compose_state.topic();
|
||||||
if (topics.includes(topic)) {
|
if (topics.includes(topic)) {
|
||||||
|
|
|
@ -337,7 +337,7 @@ function get_topic_suggestions(last, operators) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let topics = topic_data.get_recent_names(stream_id);
|
let topics = stream_topic_history.get_recent_topic_names(stream_id);
|
||||||
|
|
||||||
if (!topics || !topics.length) {
|
if (!topics || !topics.length) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -28,7 +28,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
||||||
// So double marking something as read would not occur
|
// So double marking something as read would not occur
|
||||||
unread_ops.process_read_messages_event([msg_id]);
|
unread_ops.process_read_messages_event([msg_id]);
|
||||||
if (event.message_type === 'stream') {
|
if (event.message_type === 'stream') {
|
||||||
topic_data.remove_message({
|
stream_topic_history.remove_message({
|
||||||
stream_id: event.stream_id,
|
stream_id: event.stream_id,
|
||||||
topic_name: event.topic,
|
topic_name: event.topic,
|
||||||
});
|
});
|
||||||
|
|
|
@ -142,7 +142,7 @@ exports.is_active = function (sub) {
|
||||||
// to set_filter_out_inactives.
|
// to set_filter_out_inactives.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return topic_data.stream_has_topics(sub.stream_id) || sub.newly_subscribed;
|
return stream_topic_history.stream_has_topics(sub.stream_id) || sub.newly_subscribed;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.rename_sub = function (sub, new_name) {
|
exports.rename_sub = function (sub, new_name) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const FoldDict = require('./fold_dict').FoldDict;
|
const FoldDict = require('./fold_dict').FoldDict;
|
||||||
|
|
||||||
const stream_dict = new Map(); // stream_id -> topic_history object
|
const stream_dict = new Map(); // stream_id -> per_stream_history object
|
||||||
const fetched_stream_ids = new Set();
|
const fetched_stream_ids = new Set();
|
||||||
|
|
||||||
exports.is_complete_for_stream_id = (stream_id) => {
|
exports.is_complete_for_stream_id = (stream_id) => {
|
||||||
|
@ -42,12 +42,13 @@ exports.stream_has_topics = function (stream_id) {
|
||||||
return history.has_topics();
|
return history.has_topics();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.topic_history = function (stream_id) {
|
exports.per_stream_history = function (stream_id) {
|
||||||
/*
|
/*
|
||||||
Each stream has a dictionary of topics.
|
Each stream has a dictionary of topics.
|
||||||
The main getter of this object is
|
The main getter of this object is
|
||||||
get_recent_names, and we just sort on
|
get_recent_topic_names, and we just
|
||||||
the fly every time we are called.
|
sort on the fly every time we are
|
||||||
|
called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const topics = new FoldDict();
|
const topics = new FoldDict();
|
||||||
|
@ -59,17 +60,17 @@ exports.topic_history = function (stream_id) {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.add_or_update = function (opts) {
|
self.add_or_update = function (opts) {
|
||||||
const name = opts.name;
|
const topic_name = opts.topic_name;
|
||||||
let message_id = opts.message_id || 0;
|
let message_id = opts.message_id || 0;
|
||||||
|
|
||||||
message_id = parseInt(message_id, 10);
|
message_id = parseInt(message_id, 10);
|
||||||
|
|
||||||
const existing = topics.get(name);
|
const existing = topics.get(topic_name);
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
topics.set(opts.name, {
|
topics.set(opts.topic_name, {
|
||||||
message_id: message_id,
|
message_id: message_id,
|
||||||
pretty_name: name,
|
pretty_name: topic_name,
|
||||||
historical: false,
|
historical: false,
|
||||||
count: 1,
|
count: 1,
|
||||||
});
|
});
|
||||||
|
@ -82,7 +83,7 @@ exports.topic_history = function (stream_id) {
|
||||||
|
|
||||||
if (message_id > existing.message_id) {
|
if (message_id > existing.message_id) {
|
||||||
existing.message_id = message_id;
|
existing.message_id = message_id;
|
||||||
existing.pretty_name = name;
|
existing.pretty_name = topic_name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,10 +115,10 @@ exports.topic_history = function (stream_id) {
|
||||||
// client can maintain for newer topics.
|
// client can maintain for newer topics.
|
||||||
|
|
||||||
for (const obj of server_history) {
|
for (const obj of server_history) {
|
||||||
const name = obj.name;
|
const topic_name = obj.topic_name;
|
||||||
const message_id = obj.max_id;
|
const message_id = obj.max_id;
|
||||||
|
|
||||||
const existing = topics.get(name);
|
const existing = topics.get(topic_name);
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
if (!existing.historical) {
|
if (!existing.historical) {
|
||||||
|
@ -131,15 +132,15 @@ exports.topic_history = function (stream_id) {
|
||||||
// the topic for the first time, or we are getting
|
// the topic for the first time, or we are getting
|
||||||
// more current data for it.
|
// more current data for it.
|
||||||
|
|
||||||
topics.set(name, {
|
topics.set(topic_name, {
|
||||||
message_id: message_id,
|
message_id: message_id,
|
||||||
pretty_name: name,
|
pretty_name: topic_name,
|
||||||
historical: true,
|
historical: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.get_recent_names = function () {
|
self.get_recent_topic_names = function () {
|
||||||
const my_recents = Array.from(topics.values());
|
const my_recents = Array.from(topics.values());
|
||||||
|
|
||||||
const missing_topics = unread.get_missing_topics({
|
const missing_topics = unread.get_missing_topics({
|
||||||
|
@ -163,7 +164,7 @@ exports.topic_history = function (stream_id) {
|
||||||
|
|
||||||
exports.remove_message = function (opts) {
|
exports.remove_message = function (opts) {
|
||||||
const stream_id = opts.stream_id;
|
const stream_id = opts.stream_id;
|
||||||
const name = opts.topic_name;
|
const topic_name = opts.topic_name;
|
||||||
const history = stream_dict.get(stream_id);
|
const history = stream_dict.get(stream_id);
|
||||||
|
|
||||||
// This is the special case of "removing" a message from
|
// This is the special case of "removing" a message from
|
||||||
|
@ -174,14 +175,14 @@ exports.remove_message = function (opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the normal case of an incoming message.
|
// This is the normal case of an incoming message.
|
||||||
history.maybe_remove(name);
|
history.maybe_remove(topic_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.find_or_create = function (stream_id) {
|
exports.find_or_create = function (stream_id) {
|
||||||
let history = stream_dict.get(stream_id);
|
let history = stream_dict.get(stream_id);
|
||||||
|
|
||||||
if (!history) {
|
if (!history) {
|
||||||
history = exports.topic_history(stream_id);
|
history = exports.per_stream_history(stream_id);
|
||||||
stream_dict.set(stream_id, history);
|
stream_dict.set(stream_id, history);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +192,12 @@ exports.find_or_create = function (stream_id) {
|
||||||
exports.add_message = function (opts) {
|
exports.add_message = function (opts) {
|
||||||
const stream_id = opts.stream_id;
|
const stream_id = opts.stream_id;
|
||||||
const message_id = opts.message_id;
|
const message_id = opts.message_id;
|
||||||
const name = opts.topic_name;
|
const topic_name = opts.topic_name;
|
||||||
|
|
||||||
const history = exports.find_or_create(stream_id);
|
const history = exports.find_or_create(stream_id);
|
||||||
|
|
||||||
history.add_or_update({
|
history.add_or_update({
|
||||||
name: name,
|
topic_name: topic_name,
|
||||||
message_id: message_id,
|
message_id: message_id,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -226,10 +227,10 @@ exports.get_server_history = function (stream_id, on_success) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.get_recent_names = function (stream_id) {
|
exports.get_recent_topic_names = function (stream_id) {
|
||||||
const history = exports.find_or_create(stream_id);
|
const history = exports.find_or_create(stream_id);
|
||||||
|
|
||||||
return history.get_recent_names();
|
return history.get_recent_topic_names();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.reset = function () {
|
exports.reset = function () {
|
||||||
|
@ -238,4 +239,4 @@ exports.reset = function () {
|
||||||
fetched_stream_ids.clear();
|
fetched_stream_ids.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.topic_data = exports;
|
window.stream_topic_history = exports;
|
|
@ -207,7 +207,7 @@ exports.get_next_topic = function (curr_stream, curr_topic) {
|
||||||
|
|
||||||
function get_unmuted_topics(stream_name) {
|
function get_unmuted_topics(stream_name) {
|
||||||
const stream_id = stream_data.get_stream_id(stream_name);
|
const stream_id = stream_data.get_stream_id(stream_name);
|
||||||
let topics = topic_data.get_recent_names(stream_id);
|
let topics = stream_topic_history.get_recent_topic_names(stream_id);
|
||||||
topics = topics.filter(topic => !muting.is_topic_muted(stream_id, topic));
|
topics = topics.filter(topic => !muting.is_topic_muted(stream_id, topic));
|
||||||
return topics;
|
return topics;
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ exports.widget = function (parent_elem, my_stream_id) {
|
||||||
|
|
||||||
const is_showing_all_possible_topics =
|
const is_showing_all_possible_topics =
|
||||||
list_info.items.length === num_possible_topics &&
|
list_info.items.length === num_possible_topics &&
|
||||||
topic_data.is_complete_for_stream_id(my_stream_id);
|
stream_topic_history.is_complete_for_stream_id(my_stream_id);
|
||||||
|
|
||||||
const attrs = [
|
const attrs = [
|
||||||
['class', 'topic-list'],
|
['class', 'topic-list'],
|
||||||
|
@ -256,7 +256,7 @@ exports.zoom_in = function () {
|
||||||
const spinner = true;
|
const spinner = true;
|
||||||
active_widget.build(spinner);
|
active_widget.build(spinner);
|
||||||
|
|
||||||
topic_data.get_server_history(stream_id, on_success);
|
stream_topic_history.get_server_history(stream_id, on_success);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
|
|
|
@ -11,7 +11,7 @@ exports.get_list_info = function (stream_id, zoomed) {
|
||||||
active_topic = active_topic.toLowerCase();
|
active_topic = active_topic.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
const topic_names = topic_data.get_recent_names(stream_id);
|
const topic_names = stream_topic_history.get_recent_topic_names(stream_id);
|
||||||
|
|
||||||
const items = [];
|
const items = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue