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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/__tests__/lib/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,25 @@ export const crossRealmBot: CrossRealmBot = makeCrossRealmBot({

const randStreamId: () => number = makeUniqueRandInt('stream IDs', 1000);
export const makeStream = (
args: {| stream_id?: number, name?: string, description?: string |} = Object.freeze({}),
args: {|
stream_id?: number,
name?: string,
description?: string,
invite_only?: boolean,
is_web_public?: boolean,
history_public_to_subscribers?: boolean,
|} = Object.freeze({}),
): Stream => {
const name = args.name ?? randString();
return deepFreeze({
stream_id: args.stream_id ?? randStreamId(),
name,
description: args.description ?? `On the ${randString()} of ${name}`,
rendered_description: args.description ?? `<p>On the ${randString()} of ${name}</p>`,
invite_only: false,
invite_only: args.invite_only ?? false,
is_announcement_only: false,
is_web_public: false,
history_public_to_subscribers: true,
is_web_public: args.is_web_public ?? false,
history_public_to_subscribers: args.history_public_to_subscribers ?? true,
first_message_id: null,
});
};
Expand Down
88 changes: 79 additions & 9 deletions src/api/eventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,91 @@ type StreamListEvent = $ReadOnly<{|
streams: $ReadOnlyArray<Stream>,
|}>;

type StreamUpdateEventBase = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.stream,
op: 'update',
stream_id: number,
name: string,
|}>;

// https://zulip.com/api/get-events#stream-update
export type StreamUpdateEvent =
| {| ...StreamUpdateEventBase, +property: 'name', +value: $PropertyType<Stream, 'name'> |}
| {|
...StreamUpdateEventBase,
+property: 'description',
+value: $PropertyType<Stream, 'description'>,
+rendered_description: $PropertyType<Stream, 'rendered_description'>,
|}
// TODO(server-4.0): New in FL 30.
| {|
...StreamUpdateEventBase,
+property: 'date_created',
+value: $PropertyType<Stream, 'date_created'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'invite_only',
+value: $PropertyType<Stream, 'invite_only'>,
+history_public_to_subscribers: $PropertyType<Stream, 'history_public_to_subscribers'>,

// TODO(server-5.0): New in FL 71.
+is_web_public?: $PropertyType<Stream, 'is_web_public'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'rendered_description',
+value: $PropertyType<Stream, 'rendered_description'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'is_web_public',
+value: $PropertyType<Stream, 'is_web_public'>,
|}
Comment on lines +184 to +193
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.

// TODO(server-3.0): New in FL 1; expect is_announcement_only from older
// servers.
| {|
...StreamUpdateEventBase,
+property: 'stream_post_policy',
+value: $PropertyType<Stream, 'stream_post_policy'>,
|}
// Special values are:
// * null: default; inherits from org-level setting
// * -1: unlimited retention
// These special values differ from updateStream's and createStream's params; see
// https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/message_retention_days/near/1367895
// TODO(server-3.0): New in FL 17.
| {|
...StreamUpdateEventBase,
+property: 'message_retention_days',
+value: $PropertyType<Stream, 'message_retention_days'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'history_public_to_subscribers',
+value: $PropertyType<Stream, 'history_public_to_subscribers'>,
|}
| {|
...StreamUpdateEventBase,
+property: 'first_message_id',
+value: $PropertyType<Stream, 'first_message_id'>,
|}
// TODO(server-3.0): Deprecated at FL 1; expect stream_post_policy from
// newer servers.
| {|
...StreamUpdateEventBase,
+property: 'is_announcement_only',
+value: $PropertyType<Stream, 'is_announcement_only'>,
|};

// prettier-ignore
export type StreamEvent =
| {| ...StreamListEvent, +op: 'create', |}
| {| ...StreamListEvent, +op: 'delete', |}
| {| ...StreamListEvent, +op: 'occupy', |}
| {| ...StreamListEvent, +op: 'vacate', |}
| $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.stream,
op: 'update',
stream_id: number,
name: string,
property: string,
value: string,
|}>;
| StreamUpdateEvent;

export type UpdateMessageFlagsEvent = $ReadOnly<{|
...EventCommon,
Expand Down
Loading