Skip to content

Share code for encoding/decoding narrows as links #3757

@gnprice

Description

@gnprice

As discussed in the comments at the end of #3739, there's some code in the webapp's static/js/hash_util.js that would be good to move into a shared module, perhaps named narrow_encoding.

There's one layer of this that should be pretty simple to do, and another that will involve some refactoring:

  • The functions decodeHashComponent and encodeHashComponent are pure, so making them shared should just be a matter of moving some code, with no refactoring needed to their interfaces.

    They're very small which makes them not so bad to duplicate; but @ray-kraesig recently wrote a thorough set of test cases for the mobile implementation of decodeHashComponent, much more than the webapp has, and it'd be good to share those tests.

  • The function parse_narrow, and the code it calls, encode a fair bit of complexity that would be good to share.

    This one will require some refactoring: a lot of that function's work gets done by decode_operand, and that relies on people.slug_to_emails and stream_data.slug_to_name, which in turn consult the app's data structures. So to share this code, it'll need to be explicitly passed a way to get that data. Specifically, we'll probably want to have it take a set of getter functions for the data it needs from those data structures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @zulip/sharedGood spots to share code with the webapp

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions