2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", "document-stub");
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2020-07-02 01:55:18 +02:00
|
|
|
function MessageListView() {
|
2022-07-14 20:46:41 +02:00
|
|
|
return {
|
|
|
|
maybe_rerender: noop,
|
|
|
|
append: noop,
|
|
|
|
prepend: noop,
|
|
|
|
};
|
2020-07-02 01:55:18 +02:00
|
|
|
}
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_list_view", {
|
2021-02-28 00:46:47 +01:00
|
|
|
MessageListView,
|
|
|
|
});
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2023-09-06 23:14:37 +02:00
|
|
|
mock_esm("../src/recent_view_ui", {
|
2020-05-22 08:16:08 +02:00
|
|
|
process_messages: noop,
|
2022-02-25 06:08:08 +01:00
|
|
|
show_loading_indicator: noop,
|
|
|
|
hide_loading_indicator: noop,
|
2023-10-04 19:07:01 +02:00
|
|
|
set_oldest_message_date: noop,
|
2020-05-22 08:16:08 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/ui_report", {
|
2018-02-25 13:01:38 +01:00
|
|
|
hide_error: noop,
|
|
|
|
});
|
2020-06-07 21:20:49 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const channel = mock_esm("../src/channel");
|
|
|
|
const message_helper = mock_esm("../src/message_helper");
|
|
|
|
const message_lists = mock_esm("../src/message_lists");
|
|
|
|
const message_util = mock_esm("../src/message_util");
|
|
|
|
const stream_list = mock_esm("../src/stream_list", {
|
2022-11-17 23:33:43 +01:00
|
|
|
maybe_scroll_narrow_into_view() {},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-06-01 01:57:47 +02:00
|
|
|
mock_esm("../src/message_feed_top_notices", {
|
2023-05-10 18:06:57 +02:00
|
|
|
update_top_of_narrow_notices() {},
|
|
|
|
});
|
|
|
|
mock_esm("../src/message_feed_loading", {
|
2020-06-15 12:47:11 +02:00
|
|
|
show_loading_older: noop,
|
|
|
|
hide_loading_older: noop,
|
2020-05-26 16:27:06 +02:00
|
|
|
show_loading_newer: noop,
|
|
|
|
hide_loading_newer: noop,
|
|
|
|
});
|
2021-03-06 17:37:51 +01:00
|
|
|
set_global("document", "document-stub");
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const message_fetch = zrequire("message_fetch");
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2021-03-30 06:23:09 +02:00
|
|
|
const {all_messages_data} = zrequire("all_messages_data");
|
2023-02-22 23:03:47 +01:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2020-12-01 23:21:38 +01:00
|
|
|
const message_list = zrequire("message_list");
|
|
|
|
const people = zrequire("people");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2019-07-11 18:54:28 +02:00
|
|
|
user_id: 7,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
2019-07-11 18:54:28 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
2019-07-11 18:54:28 +02:00
|
|
|
|
2018-03-22 23:34:40 +01:00
|
|
|
function make_home_msg_list() {
|
2020-07-15 01:29:15 +02:00
|
|
|
const table_name = "whatever";
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter = new Filter();
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const list = new message_list.MessageList({
|
2020-07-20 22:18:43 +02:00
|
|
|
table_name,
|
|
|
|
filter,
|
2018-05-14 15:46:25 +02:00
|
|
|
});
|
2018-03-22 23:34:40 +01:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_lists() {
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.home = make_home_msg_list();
|
|
|
|
message_lists.current = message_lists.home;
|
2021-03-30 06:23:09 +02:00
|
|
|
all_messages_data.clear();
|
2018-03-22 23:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function config_fake_channel(conf) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
|
|
|
let called;
|
2020-11-05 20:03:11 +01:00
|
|
|
let called_with_newest_flag = false;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
channel.get = (opts) => {
|
2020-11-05 20:03:11 +01:00
|
|
|
assert.equal(opts.url, "/json/messages");
|
|
|
|
// There's a separate call with anchor="newest" that happens
|
2021-04-25 22:54:23 +02:00
|
|
|
// unconditionally; do basic verification of that call.
|
2020-11-05 20:03:11 +01:00
|
|
|
if (opts.data.anchor === "newest") {
|
2022-04-09 23:44:38 +02:00
|
|
|
assert.ok(!called_with_newest_flag, "Only one 'newest' call allowed");
|
|
|
|
called_with_newest_flag = true;
|
|
|
|
assert.equal(opts.data.num_after, 0);
|
|
|
|
return;
|
2020-11-05 20:03:11 +01:00
|
|
|
}
|
|
|
|
|
2022-04-09 23:44:38 +02:00
|
|
|
assert.ok(!called || conf.can_call_again, "only use this for one call");
|
2020-06-16 17:58:37 +02:00
|
|
|
if (!conf.can_call_again) {
|
2021-06-08 05:08:12 +02:00
|
|
|
assert.equal(self.success, undefined);
|
2020-06-16 17:58:37 +02:00
|
|
|
}
|
2018-03-22 23:34:40 +01:00
|
|
|
assert.deepEqual(opts.data, conf.expected_opts_data);
|
|
|
|
self.success = opts.success;
|
|
|
|
called = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
function config_process_results(messages) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
2018-03-22 23:34:40 +01:00
|
|
|
|
narrow: Fix messages being cached without flags set.
f0c680e9c0d1a62fd414bccc82e4ac255173aaa9 introduced a call to
message_helper.process_new_message without first calling
message_store.set_message_flags on the message.
This resulted in it being possible as a race, when loading the Zulip
app to a stream/topic/near narrow, for a message to have the
`historical` flag be undefined due to not being initialized.
That invalid state, in turn, resulted in the message_list_view code
path for rendering the message feed incorrectly displaying additional
recipient bars around the message.
We could fix this by just calling message_store.set_message_booleans
in this code path. However, this bug exposes the fact that it's very
fragile to expect every code path to call that function before
message_helper.process_new_message.
So we instead fix this by moving message_store.set_message_booleans
inside message_helper.process_new_message.
One call point of concern in this change is maybe_add_narrow_messages,
which could theoretically reintroduce the double set_message_flags
bugs detailed in 9729b1a4ad51b69c98ce4f8374c9d9f8cf69430c. However, I
believe that to not be possible, because that call should never
experience a cache miss.
The other existing code paths were already calling
set_message_booleans immediately before
message_helper.process_new_message. They are still changing here, in
that we now do a cache lookup before attempting to call
set_message_booleans. Because the message booleans do not affect the
cache lookup and the local message object is discarded in case of a
cache hit, this should have no functional impact.
Because I found the existing comment at that call site confusing and
almost proposed removing it as pointless, extend the block comment to
explicitly mention that the purpose is refreshing our object.
Fixes #21503.
2022-03-24 01:07:56 +01:00
|
|
|
const messages_processed_for_new = [];
|
2018-03-22 23:34:40 +01:00
|
|
|
|
narrow: Fix messages being cached without flags set.
f0c680e9c0d1a62fd414bccc82e4ac255173aaa9 introduced a call to
message_helper.process_new_message without first calling
message_store.set_message_flags on the message.
This resulted in it being possible as a race, when loading the Zulip
app to a stream/topic/near narrow, for a message to have the
`historical` flag be undefined due to not being initialized.
That invalid state, in turn, resulted in the message_list_view code
path for rendering the message feed incorrectly displaying additional
recipient bars around the message.
We could fix this by just calling message_store.set_message_booleans
in this code path. However, this bug exposes the fact that it's very
fragile to expect every code path to call that function before
message_helper.process_new_message.
So we instead fix this by moving message_store.set_message_booleans
inside message_helper.process_new_message.
One call point of concern in this change is maybe_add_narrow_messages,
which could theoretically reintroduce the double set_message_flags
bugs detailed in 9729b1a4ad51b69c98ce4f8374c9d9f8cf69430c. However, I
believe that to not be possible, because that call should never
experience a cache miss.
The other existing code paths were already calling
set_message_booleans immediately before
message_helper.process_new_message. They are still changing here, in
that we now do a cache lookup before attempting to call
set_message_booleans. Because the message booleans do not affect the
cache lookup and the local message object is discarded in case of a
cache hit, this should have no functional impact.
Because I found the existing comment at that call site confusing and
almost proposed removing it as pointless, extend the block comment to
explicitly mention that the purpose is refreshing our object.
Fixes #21503.
2022-03-24 01:07:56 +01:00
|
|
|
message_helper.process_new_message = (message) => {
|
|
|
|
messages_processed_for_new.push(message);
|
|
|
|
return message;
|
2018-03-22 23:34:40 +01:00
|
|
|
};
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
message_util.do_unread_count_updates = (arg) => {
|
2018-03-22 23:34:40 +01:00
|
|
|
assert.deepEqual(arg, messages);
|
|
|
|
};
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
message_util.add_old_messages = (new_messages, msg_list) => {
|
2018-03-22 23:34:40 +01:00
|
|
|
assert.deepEqual(new_messages, messages);
|
2019-01-08 01:26:02 +01:00
|
|
|
msg_list.add_messages(new_messages);
|
2018-03-22 23:34:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
stream_list.update_streams_sidebar = noop;
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
self.verify = () => {
|
narrow: Fix messages being cached without flags set.
f0c680e9c0d1a62fd414bccc82e4ac255173aaa9 introduced a call to
message_helper.process_new_message without first calling
message_store.set_message_flags on the message.
This resulted in it being possible as a race, when loading the Zulip
app to a stream/topic/near narrow, for a message to have the
`historical` flag be undefined due to not being initialized.
That invalid state, in turn, resulted in the message_list_view code
path for rendering the message feed incorrectly displaying additional
recipient bars around the message.
We could fix this by just calling message_store.set_message_booleans
in this code path. However, this bug exposes the fact that it's very
fragile to expect every code path to call that function before
message_helper.process_new_message.
So we instead fix this by moving message_store.set_message_booleans
inside message_helper.process_new_message.
One call point of concern in this change is maybe_add_narrow_messages,
which could theoretically reintroduce the double set_message_flags
bugs detailed in 9729b1a4ad51b69c98ce4f8374c9d9f8cf69430c. However, I
believe that to not be possible, because that call should never
experience a cache miss.
The other existing code paths were already calling
set_message_booleans immediately before
message_helper.process_new_message. They are still changing here, in
that we now do a cache lookup before attempting to call
set_message_booleans. Because the message booleans do not affect the
cache lookup and the local message object is discarded in case of a
cache hit, this should have no functional impact.
Because I found the existing comment at that call site confusing and
almost proposed removing it as pointless, extend the block comment to
explicitly mention that the purpose is refreshing our object.
Fixes #21503.
2022-03-24 01:07:56 +01:00
|
|
|
assert.deepEqual(messages_processed_for_new, messages);
|
2018-03-22 23:34:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
function message_range(start, end) {
|
2020-07-02 01:39:34 +02:00
|
|
|
return _.range(start, end).map((idx) => ({
|
js: Convert _.map(a, …) to a.map(…).
And convert the corresponding function expressions to arrow style
while we’re here.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitCallExpression(path) {
const { callee, arguments: args } = path.node;
if (
n.MemberExpression.check(callee) &&
!callee.computed &&
n.Identifier.check(callee.object) &&
callee.object.name === "_" &&
n.Identifier.check(callee.property) &&
callee.property.name === "map" &&
args.length === 2 &&
checkExpression(args[0]) &&
checkExpression(args[1])
) {
const [arr, fn] = args;
path.replace(
b.callExpression(b.memberExpression(arr, b.identifier("map")), [
n.FunctionExpression.check(fn) ||
n.ArrowFunctionExpression.check(fn)
? b.arrowFunctionExpression(
fn.params,
n.BlockStatement.check(fn.body) &&
fn.body.body.length === 1 &&
n.ReturnStatement.check(fn.body.body[0])
? fn.body.body[0].argument || b.identifier("undefined")
: fn.body
)
: fn,
])
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 02:43:49 +01:00
|
|
|
id: idx,
|
|
|
|
}));
|
2018-03-22 23:34:40 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const initialize_data = {
|
2018-03-22 23:34:40 +01:00
|
|
|
initial_fetch: {
|
|
|
|
req: {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "first_unread",
|
2018-03-22 23:34:40 +01:00
|
|
|
num_before: 200,
|
|
|
|
num_after: 200,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(201, 801),
|
|
|
|
found_newest: false,
|
2020-02-19 22:45:57 +01:00
|
|
|
anchor: 444,
|
2018-03-22 23:34:40 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
forward_fill: {
|
|
|
|
req: {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "800",
|
2018-03-22 23:34:40 +01:00
|
|
|
num_before: 0,
|
|
|
|
num_after: 1000,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(800, 1000),
|
|
|
|
found_newest: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
back_fill: {
|
|
|
|
req: {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "201",
|
2018-03-22 23:34:40 +01:00
|
|
|
num_before: 1000,
|
|
|
|
num_after: 0,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(100, 200),
|
|
|
|
found_oldest: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
function test_fetch_success(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const response = opts.response;
|
|
|
|
const messages = response.messages;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const process_results = config_process_results(messages);
|
2018-03-22 23:34:40 +01:00
|
|
|
opts.fetch.success(response);
|
|
|
|
process_results.verify();
|
|
|
|
}
|
|
|
|
|
2021-03-28 16:43:58 +02:00
|
|
|
function initial_fetch_step(home_view_loaded) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let fetch;
|
|
|
|
const response = initialize_data.initial_fetch.resp;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
self.prep = () => {
|
2018-03-22 23:34:40 +01:00
|
|
|
fetch = config_fake_channel({
|
|
|
|
expected_opts_data: initialize_data.initial_fetch.req,
|
|
|
|
});
|
|
|
|
|
2021-03-28 16:43:58 +02:00
|
|
|
message_fetch.initialize(home_view_loaded);
|
2018-03-22 23:34:40 +01:00
|
|
|
};
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
self.finish = () => {
|
2018-03-22 23:34:40 +01:00
|
|
|
test_fetch_success({
|
2020-07-20 22:18:43 +02:00
|
|
|
fetch,
|
|
|
|
response,
|
2018-03-22 23:34:40 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
function forward_fill_step() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const self = {};
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let fetch;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
self.prep = () => {
|
2018-03-22 23:34:40 +01:00
|
|
|
fetch = config_fake_channel({
|
|
|
|
expected_opts_data: initialize_data.forward_fill.req,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
self.finish = () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const response = initialize_data.forward_fill.resp;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let idle_config;
|
2021-02-23 14:37:26 +01:00
|
|
|
$("document-stub").idle = (config) => {
|
2018-03-22 23:34:40 +01:00
|
|
|
idle_config = config;
|
|
|
|
};
|
|
|
|
|
|
|
|
test_fetch_success({
|
2020-07-20 22:18:43 +02:00
|
|
|
fetch,
|
|
|
|
response,
|
2018-03-22 23:34:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(idle_config.idle, 10000);
|
|
|
|
|
|
|
|
return idle_config;
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_backfill_idle(idle_config) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const fetch = config_fake_channel({
|
2018-03-22 23:34:40 +01:00
|
|
|
expected_opts_data: initialize_data.back_fill.req,
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const response = initialize_data.back_fill.resp;
|
2018-03-22 23:34:40 +01:00
|
|
|
|
|
|
|
idle_config.onIdle();
|
|
|
|
|
|
|
|
test_fetch_success({
|
2020-07-20 22:18:43 +02:00
|
|
|
fetch,
|
|
|
|
response,
|
2018-03-22 23:34:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("initialize", () => {
|
2018-03-22 23:34:40 +01:00
|
|
|
reset_lists();
|
|
|
|
|
2021-03-28 16:43:58 +02:00
|
|
|
let home_loaded = false;
|
2022-10-25 00:34:47 +02:00
|
|
|
page_params.unread_msgs = {
|
|
|
|
old_unreads_missing: false,
|
|
|
|
};
|
2021-03-28 16:43:58 +02:00
|
|
|
|
|
|
|
function home_view_loaded() {
|
|
|
|
home_loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const step1 = initial_fetch_step(home_view_loaded);
|
2018-03-22 23:34:40 +01:00
|
|
|
|
|
|
|
step1.prep();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const step2 = forward_fill_step();
|
2018-03-22 23:34:40 +01:00
|
|
|
|
|
|
|
step2.prep();
|
|
|
|
step1.finish();
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!home_loaded);
|
2019-11-02 00:06:25 +01:00
|
|
|
const idle_config = step2.finish();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(home_loaded);
|
2018-03-22 23:34:40 +01:00
|
|
|
|
|
|
|
test_backfill_idle(idle_config);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-03-23 17:32:24 +01:00
|
|
|
|
|
|
|
function simulate_narrow() {
|
2023-04-11 21:04:33 +02:00
|
|
|
const filter = new Filter([{operator: "dm", operand: alice.email}]);
|
2018-03-23 17:32:24 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_list = new message_list.MessageList({
|
2020-07-15 01:29:15 +02:00
|
|
|
table_name: "zfilt",
|
2020-07-20 22:18:43 +02:00
|
|
|
filter,
|
2018-05-14 15:46:25 +02:00
|
|
|
});
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current = msg_list;
|
2018-03-23 17:32:24 +01:00
|
|
|
|
|
|
|
return msg_list;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("loading_newer", () => {
|
2018-03-23 17:32:24 +01:00
|
|
|
function test_dup_new_fetch(msg_list) {
|
2020-05-30 09:45:12 +02:00
|
|
|
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), false);
|
2018-03-23 17:32:24 +01:00
|
|
|
message_fetch.maybe_load_newer_messages({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
2018-03-23 17:32:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_happy_path(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_list = opts.msg_list;
|
|
|
|
const data = opts.data;
|
2018-03-23 17:32:24 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const fetch = config_fake_channel({
|
2018-03-23 17:32:24 +01:00
|
|
|
expected_opts_data: data.req,
|
2020-06-16 17:58:37 +02:00
|
|
|
can_call_again: true,
|
2018-03-23 17:32:24 +01:00
|
|
|
});
|
|
|
|
|
2023-11-08 20:46:12 +01:00
|
|
|
message_fetch.maybe_load_newer_messages({
|
|
|
|
msg_list,
|
|
|
|
show_loading: noop,
|
|
|
|
hide_loading: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
test_dup_new_fetch(msg_list);
|
|
|
|
|
|
|
|
test_fetch_success({
|
|
|
|
fetch,
|
|
|
|
response: data.resp,
|
|
|
|
});
|
2018-03-23 17:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
(function test_narrow() {
|
2023-11-08 20:46:12 +01:00
|
|
|
let msg_list = simulate_narrow();
|
2022-10-25 00:34:47 +02:00
|
|
|
page_params.unread_msgs = {
|
|
|
|
old_unreads_missing: true,
|
|
|
|
};
|
2018-03-23 17:32:24 +01:00
|
|
|
|
2023-11-08 20:46:12 +01:00
|
|
|
// Test what happens when an empty list is returned with found_newest false.
|
|
|
|
const empty_list_data = {
|
2018-03-23 17:32:24 +01:00
|
|
|
req: {
|
2023-11-08 20:46:12 +01:00
|
|
|
anchor: "oldest",
|
2018-03-23 17:32:24 +01:00
|
|
|
num_before: 0,
|
|
|
|
num_after: 100,
|
2023-04-11 21:04:33 +02:00
|
|
|
narrow: `[{"negated":false,"operator":"dm","operand":[${alice.user_id}]}]`,
|
2018-03-23 17:32:24 +01:00
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(500, 600),
|
|
|
|
found_newest: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test_happy_path({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
2023-11-08 20:46:12 +01:00
|
|
|
data: empty_list_data,
|
2020-06-06 16:35:50 +02:00
|
|
|
});
|
|
|
|
|
2023-11-08 20:46:12 +01:00
|
|
|
msg_list = simulate_narrow();
|
2023-12-14 23:51:33 +01:00
|
|
|
msg_list.append_to_view = noop;
|
2020-06-06 16:35:50 +02:00
|
|
|
// Instead of using 444 as page_param.pointer, we
|
|
|
|
// should have a message with that id in the message_list.
|
|
|
|
msg_list.append(message_range(444, 445), false);
|
|
|
|
|
2023-11-08 20:46:12 +01:00
|
|
|
const data = {
|
|
|
|
req: {
|
|
|
|
anchor: "444",
|
|
|
|
num_before: 0,
|
|
|
|
num_after: 100,
|
|
|
|
narrow: `[{"negated":false,"operator":"dm","operand":[${alice.user_id}]}]`,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(500, 600),
|
|
|
|
found_newest: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-06-06 16:35:50 +02:00
|
|
|
test_happy_path({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
|
|
|
data,
|
2018-03-23 17:32:24 +01:00
|
|
|
});
|
|
|
|
|
2020-05-30 09:45:12 +02:00
|
|
|
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), true);
|
2020-05-30 17:34:07 +02:00
|
|
|
|
|
|
|
// The server successfully responded with messages having id's from 500-599.
|
|
|
|
// We test for the case that this was the last batch of messages for the narrow
|
|
|
|
// so no more fetching should occur.
|
|
|
|
// And also while fetching for the above condition the server received a new message
|
|
|
|
// event, updating the last message's id for that narrow to 600 from 599.
|
|
|
|
data.resp.found_newest = true;
|
|
|
|
msg_list.data.fetch_status.update_expected_max_message_id([{id: 600}]);
|
|
|
|
|
|
|
|
test_happy_path({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
|
|
|
data,
|
2020-05-30 17:34:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// To handle this special case we should allow another fetch to occur,
|
|
|
|
// since the last message event's data had been discarded.
|
2020-06-16 17:58:37 +02:00
|
|
|
// This fetch goes on until the newest message has been found.
|
|
|
|
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), false);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-03-23 17:32:24 +01:00
|
|
|
|
|
|
|
(function test_home() {
|
|
|
|
reset_lists();
|
2023-11-08 20:46:12 +01:00
|
|
|
let msg_list = message_lists.home;
|
|
|
|
|
|
|
|
// Test what happens when an empty list is returned with found_newest false.
|
|
|
|
const empty_list_data = {
|
|
|
|
req: {
|
|
|
|
anchor: "oldest",
|
|
|
|
num_before: 0,
|
|
|
|
num_after: 100,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(500, 600),
|
|
|
|
found_newest: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test_happy_path({
|
|
|
|
msg_list,
|
|
|
|
data: empty_list_data,
|
|
|
|
});
|
|
|
|
|
|
|
|
reset_lists();
|
2018-03-23 17:32:24 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = [
|
2018-03-23 17:32:24 +01:00
|
|
|
{
|
|
|
|
req: {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "444",
|
2018-03-23 17:32:24 +01:00
|
|
|
num_before: 0,
|
|
|
|
num_after: 100,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(500, 600),
|
|
|
|
found_newest: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
req: {
|
2020-07-15 01:29:15 +02:00
|
|
|
anchor: "599",
|
2018-03-23 17:32:24 +01:00
|
|
|
num_before: 0,
|
|
|
|
num_after: 100,
|
|
|
|
client_gravatar: true,
|
|
|
|
},
|
|
|
|
resp: {
|
|
|
|
messages: message_range(700, 800),
|
|
|
|
found_newest: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-11-08 20:46:12 +01:00
|
|
|
msg_list = message_lists.home;
|
2021-03-30 06:23:09 +02:00
|
|
|
all_messages_data.append(message_range(444, 445), false);
|
2020-06-06 16:35:50 +02:00
|
|
|
|
|
|
|
test_happy_path({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
2020-06-06 16:35:50 +02:00
|
|
|
data: data[0],
|
2018-03-23 17:32:24 +01:00
|
|
|
});
|
|
|
|
|
2020-05-30 09:45:12 +02:00
|
|
|
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), true);
|
2018-03-23 17:32:24 +01:00
|
|
|
|
|
|
|
test_happy_path({
|
2020-07-20 22:18:43 +02:00
|
|
|
msg_list,
|
2018-03-23 17:32:24 +01:00
|
|
|
data: data[1],
|
|
|
|
});
|
|
|
|
|
2020-05-30 09:45:12 +02:00
|
|
|
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), false);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|