stream_topic_history: Pluralize remove_message.

Since this function now does a bulk operation with several messages,
we should make sure it's named appropriately.
This commit is contained in:
Tim Abbott
2020-06-15 10:52:00 -07:00
parent ba2de34414
commit 3087fbe854
6 changed files with 21 additions and 12 deletions

View File

@@ -811,11 +811,12 @@ with_overrides(function (override) {
assert_same(args.message_ids, [1337]);
});
global.with_stub(function (stub) {
override('stream_topic_history.remove_message', stub.f);
override('stream_topic_history.remove_messages', stub.f);
dispatch(event);
const args = stub.get_args('opts');
assert_same(args.opts.stream_id, 99);
assert_same(args.opts.topic_name, 'topic1');
assert_same(args.opts.num_messages, 1);
});
});

View File

@@ -41,9 +41,10 @@ run_test('basics', () => {
assert.deepEqual(max_message_id, 103);
// Removing first topic1 message has no effect.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: stream_id,
topic_name: 'toPic1',
num_messages: 1,
});
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2', 'Topic1']);
@@ -52,24 +53,27 @@ run_test('basics', () => {
assert.deepEqual(max_message_id, 103);
// Removing second topic1 message removes the topic.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: stream_id,
topic_name: 'Topic1',
num_messages: 1,
});
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2']);
// Test that duplicate remove does not crash us.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: stream_id,
topic_name: 'Topic1',
num_messages: 1,
});
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['topic2']);
// get to 100% coverage for defensive code
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: 9999999,
num_messages: 1,
});
});
@@ -173,18 +177,20 @@ run_test('server_history', () => {
// Removing a local message removes the topic if we have
// our counts right.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: stream_id,
topic_name: 'local',
num_messages: 1,
});
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.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: stream_id,
topic_name: 'hist2',
num_messages: 1,
});
history = stream_topic_history.get_recent_topic_names(stream_id);
assert.deepEqual(history, ['hist2', 'hist1']);

View File

@@ -193,9 +193,10 @@ exports.edit_locally = function (message, request) {
if (request.new_topic !== undefined || request.new_stream_id !== undefined) {
const new_stream_id = request.new_stream_id;
const new_topic = request.new_topic;
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: message.stream_id,
topic_name: message.topic,
num_messages: 1,
});
if (new_stream_id !== undefined) {

View File

@@ -187,9 +187,10 @@ exports.update_messages = function update_messages(events) {
// complexity; the present loop assumes stream_topic_history has
// only messages in message_store, but that's been false
// since we added the server_history feature.
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: msg.stream_id,
topic_name: msg.topic,
num_messages: 1,
});
// Update the unread counts; again, this must be called

View File

@@ -29,7 +29,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
unread_ops.process_read_messages_event(msg_ids);
if (event.message_type === 'stream') {
stream_topic_history.remove_message({
stream_topic_history.remove_messages({
stream_id: event.stream_id,
topic_name: event.topic,
num_messages: msg_ids.length,

View File

@@ -196,10 +196,10 @@ exports.per_stream_history = function (stream_id) {
return self;
};
exports.remove_message = function (opts) {
exports.remove_messages = function (opts) {
const stream_id = opts.stream_id;
const topic_name = opts.topic_name;
const num_messages = opts.num_messages || 1;
const num_messages = opts.num_messages;
const history = stream_dict.get(stream_id);
// This is the special case of "removing" a message from