Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Sync update-stream event types with doc and align implementation #5346

Merged
merged 4 commits into from
Apr 20, 2022

Conversation

chrisbobbe
Copy link
Contributor

After #5341, on the path to fixing #5250.

There are some good changes in behavior:

- When the event's `property` is "invite_only", we'll also update
  `event.history_public_to_subscribers` and `is_web_public`. This
  fixes a live bug! We read `is_web_public` when choosing whether to
  mark a stream as web-public in the UI.

- When the event's `property` is "description", we'll also update
  `rendered_description`. (This was a latent bug; we don't read
  `rendered_description` anywhere.)

So, also add tests for those.
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe! Looks good; merging.

Comment on lines +24 to +27
expect(
streamsReducer(
[],
deepFreeze({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

streamsReducer tests [nfc]: Make more compact

Well, sort of.

Yeah, Prettier's style of layout makes for a lot of very short lines here.

One thing I sometimes do when that happens is to pull some pieces out as locals, in order to get Prettier to collapse a list of arguments back to one line. Here that could look like:

-      expect(
-        streamsReducer(
-          [],
-          deepFreeze({
-            type: EVENT,
-            event: {
-              id: 0,
-              type: EventTypes.stream,
-              op: 'create',
-              streams: [stream1, stream2],
-            },
-          }),
-        ),
-      ).toEqual([stream1, stream2]);
+      const event = deepFreeze({
+        type: EVENT,
+        event: {
+          id: 0,
+          type: EventTypes.stream,
+          op: 'create',
+          streams: [stream1, stream2],
+        },
+      });
+      expect(streamsReducer([], event)).toEqual([stream1, stream2]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A further step could be, at the top of this file:

const mkAction = e => deepFreeze({ type: EVENT, event: { id: 0, type: EventTypes.stream, ...e } });

and then these 14 lines would become just:

      const action = mkAction({ op: 'create', streams: [stream1, stream2] });
      expect(streamsReducer([], action)).toEqual([stream1, stream2]);

and similarly for the other events in the file.

Copy link
Contributor Author

@chrisbobbe chrisbobbe Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A further step

I've just tried this out, and I haven't yet found a way to do this without Flow errors; I think a factor is how many branches there are in StreamEvent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll come back to it in the future when doing other substantive work in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just sent #5352 for the first thing though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tried this out, and I haven't yet found a way to do this without Flow errors; I think a factor is how many branches there are in StreamEvent.

Ah indeed. I think I have a solution for that; I'll send as a PR after merging #5352.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sent: #5353. The extra bit it needs is a type annotation on the helper, making it generic with a bound:

const mkAction = <E: $Diff<StreamEvent, {| id: mixed, type: mixed |}>>(event: E) =>
  deepFreeze({ type: EVENT, event: { id: 0, type: EventTypes.stream, ...event } });

Wrote a bit of a long commit message for it, too -- I tried to think through why it is that this was getting errors without an annotation, and why this particular spot is one where Flow needs an annotation even though in many other situations it infers things just fine, and then to see if I could explain that in a meaningful way.

Comment on lines +184 to +193
| {|
...StreamUpdateEventBase,
+property: 'rendered_description',
+value: $PropertyType<Stream, 'rendered_description'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'is_web_public',
+value: $PropertyType<Stream, 'is_web_public'>,
|}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these can usefully be further deduplicated. I'll send that as a quick PR on top of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants