mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Earlier, 'all_topics_in_cache' used to return `false` in the case where we were unsure if some topics were present even before the user subscribed to the channel and hence missing in the cache. Returning `false` led to visible 'show all topics', even if all the topics were already displayed. This was helpful if the API call to fetch channel history failed, as users had the option to make another request. That resulted in a bug where "show all topics" was flashing in channels with less number of topics. We used to display "show all topics" initially and then hide it after the API call confirmed that there were no new topics to display. To fix this bug, we return `true`. So, the "show all topics" is not displayed beforehand. We let the API call fetch the history and rebuild the topic list based on the updated data. Instead of show then hide. We now prefer, show if needed. To fix the issue of API call failure and users having no option to see all topics, we did prep work in the last commit to add retry mechanism to the concerned API call.
80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
|
|
const {run_test, noop} = require("./lib/test.cjs");
|
|
|
|
const stream_topic_history_util = mock_esm("../src/stream_topic_history_util");
|
|
mock_esm("../src/people.ts", {
|
|
maybe_get_user_by_id: noop,
|
|
});
|
|
|
|
const all_messages_data = zrequire("all_messages_data");
|
|
const {set_realm} = zrequire("state_data");
|
|
const stream_data = zrequire("stream_data");
|
|
const stream_topic_history = zrequire("stream_topic_history");
|
|
const topic_list = zrequire("topic_list");
|
|
|
|
set_realm({});
|
|
|
|
function test(label, f) {
|
|
run_test(label, (helpers) => {
|
|
f(helpers);
|
|
});
|
|
}
|
|
|
|
test("is_full_topic_history_available", ({override}) => {
|
|
const stream_id = 21;
|
|
const general = {
|
|
name: "general",
|
|
stream_id,
|
|
first_message_id: null,
|
|
};
|
|
const messages = [
|
|
{id: 1, stream_id},
|
|
{id: 2, stream_id},
|
|
{id: 3, stream_id},
|
|
];
|
|
const sub = stream_data.create_sub_from_server_data(general);
|
|
|
|
// Currently, all_messages_data is empty.
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), false);
|
|
|
|
all_messages_data.all_messages_data.clear();
|
|
all_messages_data.all_messages_data.add_messages(messages, true);
|
|
|
|
let has_found_newest = false;
|
|
|
|
override(
|
|
all_messages_data.all_messages_data.fetch_status,
|
|
"has_found_newest",
|
|
() => has_found_newest,
|
|
);
|
|
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), false);
|
|
has_found_newest = true;
|
|
// sub.first_message_id === null
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), true);
|
|
|
|
// Note that we'll return `true` here due to
|
|
// fetched_stream_ids having the stream_id now.
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), true);
|
|
|
|
// Clear the data, otherwise `is_full_topic_history_available`
|
|
// will always return true due to stream_id in fetched_stream_ids.
|
|
stream_topic_history.reset();
|
|
|
|
sub.first_message_id = 0;
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), false);
|
|
|
|
sub.first_message_id = 2;
|
|
let full_topic_history_fetched_and_widget_updated = false;
|
|
stream_topic_history_util.get_server_history = (stream_id) => {
|
|
assert.equal(stream_id, general.stream_id);
|
|
full_topic_history_fetched_and_widget_updated = true;
|
|
};
|
|
assert.equal(topic_list.is_full_topic_history_available(stream_id), true);
|
|
assert.equal(full_topic_history_fetched_and_widget_updated, true);
|
|
});
|