refactor: Extract message_helper.process_new_message.

We move the message_store.add_message_metadata function
(and all its dependencies) into a new module called
message_helper and rename the function to process_new_message.
(It does a bit more than adding message metadata, such
as updating our message store.)

We also have a "protected" interface now in message_store,
so that message_helper can access the message store:

    update_message_cache
    get_cached_message

Because update_message_cache is identical to
the former create_mock_message, we just renamed it
in the tests.

Most callers should use these functions:

    message_helper.process_new_message (setting)
    message_store.get (getting)

It's slightly annoying that the setter interface
is in a different module than the getter interface,
but that's how you break a bunch of dependencies.

We also extract the tiny message_user_ids class:

    user_ids()
    add_user_ids()

All the code moves here are pretty trivial, and
the code that was moved maintains 100% line
coverage.

The module name `message_helper` is not ideal, but it's a single
function and it'll save time to just do the topology change now and
leave thinking through the right name to later.
This commit is contained in:
Steve Howell
2021-03-28 15:57:53 +00:00
committed by Tim Abbott
parent 8798b0a134
commit 45d806d9aa
19 changed files with 160 additions and 144 deletions

View File

@@ -35,7 +35,7 @@ export function set_focused_recipient(msg_type) {
}
} else {
// Normalize the recipient list so it matches the one used when
// adding the message (see message_store.add_message_metadata()).
// adding the message (see message_helper.process_new_message()).
const reply_to = util.normalize_recipients(compose_state.private_message_recipient());
focused_recipient.reply_to = reply_to;
focused_recipient.to_user_ids = people.reply_to_to_user_ids_string(reply_to);