-
Notifications
You must be signed in to change notification settings - Fork 232
OpenAPI: Migrate mute and unmute users to v2 endpoint and generate current user payload #4208
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ allowed_endpoints=( | |
| listDevices | ||
| listUserGroups | ||
| markDelivered | ||
| mute | ||
| muteChannel | ||
| queryMembers | ||
| queryPollVotes | ||
|
|
@@ -47,6 +48,7 @@ allowed_endpoints=( | |
| showChannel | ||
| stopWatchingChannel | ||
| unblockUsers | ||
| unmute | ||
|
laevandus marked this conversation as resolved.
|
||
| unmuteChannel | ||
| unreadCounts | ||
| updateLiveLocation | ||
|
|
@@ -78,6 +80,7 @@ allowed_models=( | |
| CreateUserGroupRequest | ||
| DeleteChannelResponse | ||
| DeliveredMessagePayload | ||
| DeliveryReceiptsResponse | ||
| DeviceResponse | ||
| Field | ||
| FileUploadConfig | ||
|
|
@@ -98,6 +101,9 @@ allowed_models=( | |
| MembersResponse | ||
| MuteChannelRequest | ||
| MuteChannelResponse | ||
| MuteRequest | ||
| MuteResponse | ||
| OwnUserResponse | ||
| PollOptionInput | ||
| PollOptionResponse | ||
| PollOptionResponseData | ||
|
|
@@ -106,21 +112,26 @@ allowed_models=( | |
| PollVoteResponse | ||
| PollVoteResponseData | ||
| PollVotesResponse | ||
| PrivacySettingsResponse | ||
| PushPreferenceInput | ||
| PushPreferencesResponse | ||
| QueryMembersPayload | ||
| QueryPollVotesRequest | ||
| QueryReactionsRequest | ||
| ReactionResponse | ||
| ReadReceiptsResponse | ||
| RemoveUserGroupMembersRequest | ||
| Role | ||
| SearchRolesResponse | ||
| SharedLocationResponseData | ||
| SharedLocationsResponse | ||
| SortParamRequest | ||
| TypingIndicatorsResponse | ||
| UnblockUsersRequest | ||
| UnblockUsersResponse | ||
| UnmuteChannelRequest | ||
| UnmuteRequest | ||
| UnmuteResponse | ||
| UnreadCountsChannel | ||
| UnreadCountsChannelType | ||
| UnreadCountsThread | ||
|
|
@@ -135,6 +146,7 @@ allowed_models=( | |
| UpsertPushPreferencesResponse | ||
| UserGroupMember | ||
| UserGroupResponse | ||
| UserMuteResponse | ||
| UserResponse | ||
| VoteData | ||
| WrappedUnreadCountsResponse | ||
|
|
@@ -400,12 +412,17 @@ rename_generated ChannelMemberResponse MemberPayload | |
| rename_generated ChannelMute MutedChannelPayload | ||
| rename_generated ChannelResponse ChannelDetailPayload | ||
| rename_generated MuteChannelResponse MutedChannelPayloadResponse | ||
| rename_generated UnmuteResponse UnmuteUsersResponse | ||
| rename_generated UserMuteResponse MutedUserPayload | ||
| rename_generated DeliveryReceiptsResponse DeliveryReceiptsPrivacySettings | ||
| rename_generated PrivacySettingsResponse UserPrivacySettings | ||
| rename_generated ReadReceiptsResponse ReadReceiptsPrivacySettings | ||
| rename_generated TypingIndicatorsResponse TypingIndicatorPrivacySettings | ||
|
|
||
| rename_generated_type HideChannelResponse EmptyResponse | ||
| rename_generated_type MarkDeliveredResponse EmptyResponse | ||
| rename_generated_type Response EmptyResponse | ||
| rename_generated_type ShowChannelResponse EmptyResponse | ||
| rename_generated_type UnmuteResponse EmptyResponse | ||
|
|
||
| # Remove a generated property (declaration, doc comment, init param, assignment, | ||
| # CodingKeys case). Runs before publicize, so there are no access modifiers to | ||
|
|
@@ -439,6 +456,17 @@ optionalize_property MemberPayload channelRole | |
| optionalize_property MemberPayload notificationsMuted | ||
| optionalize_property MemberPayload shadowBanned | ||
|
|
||
| optionalize_property OwnUserResponse banned | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. were these optional already? |
||
| optionalize_property OwnUserResponse channelMutes | ||
| optionalize_property OwnUserResponse devices | ||
| optionalize_property OwnUserResponse invisible | ||
| optionalize_property OwnUserResponse language | ||
| optionalize_property OwnUserResponse mutes | ||
| optionalize_property OwnUserResponse teams | ||
| optionalize_property OwnUserResponse totalUnreadCount | ||
| optionalize_property OwnUserResponse unreadChannels | ||
| optionalize_property OwnUserResponse unreadThreads | ||
|
|
||
| # Remove a generated property (declaration, doc comment, init param, assignment, | ||
| # CodingKeys case). Runs before publicize, so there are no access modifiers to | ||
| # handle. Assumes the single-line init the generator emits (step 7 re-wraps). | ||
|
|
@@ -479,6 +507,8 @@ remove_property DeleteChannelResponse duration | |
| remove_property MutedChannelPayloadResponse channelMutes | ||
| remove_property MutedChannelPayloadResponse duration | ||
| remove_property MutedChannelPayloadResponse ownUser | ||
| remove_property OwnUserResponse unreadCount | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we remove these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a deprecated field and our hand-crafted payload also skipped it. |
||
| remove_property UnmuteUsersResponse duration | ||
|
|
||
| retype_property ChannelDetailPayload cid String ChannelId | ||
| retype_property ChannelDetailPayload config ChannelConfigWithInfo ChannelConfig | ||
|
|
@@ -497,40 +527,75 @@ remove_nested_enum() { | |
| remove_nested_enum PushPreferenceInput PushPreferenceInputCallLevel | ||
| remove_nested_enum PushPreferenceInput PushPreferenceInputFeedsLevel | ||
|
|
||
| # 4c. Expose selected generated models as public API. The class and its stored | ||
| # Give a generated model mutable stored properties, so it can replace a hand-written | ||
| # public type whose properties were var. Mutable state rules out checked Sendable, | ||
| # hence the relaxed conformance. Runs before publicize_model, which anchors on the | ||
| # resulting var lines. | ||
| make_model_mutable() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| sed -i '' -E \ | ||
| -e 's/^(final class [A-Za-z0-9_]+): Sendable,/\1: @unchecked Sendable,/' \ | ||
| -e 's/^ let / var /' \ | ||
| "$file" | ||
| } | ||
| make_model_mutable DeliveryReceiptsPrivacySettings | ||
| make_model_mutable ReadReceiptsPrivacySettings | ||
| make_model_mutable TypingIndicatorPrivacySettings | ||
| make_model_mutable UserPrivacySettings | ||
|
|
||
| # 4c. Expose selected generated models as public API. The type and its stored | ||
| # properties become public, along with the generated Hashable conformance | ||
| # (== and hash(into:)); the memberwise init and CodingKeys stay internal. | ||
| publicize_model() { | ||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| sed -i '' -E \ | ||
| -e 's/^final class /public final class /' \ | ||
| -e 's/^ let / public let /' \ | ||
| -e 's/^ var / public var /' \ | ||
| -e 's/^ static func == / public static func == /' \ | ||
| -e 's/^ func hash\(into / public func hash(into /' \ | ||
| "$file" | ||
| } | ||
| publicize_model AppSettings | ||
| publicize_model CurrentUserUnreads | ||
| publicize_model DeliveryReceiptsPrivacySettings | ||
| publicize_model Device | ||
| publicize_model PushPreference | ||
| publicize_model ReadReceiptsPrivacySettings | ||
| publicize_model Role | ||
| publicize_model SharedLocation | ||
| publicize_model TypingIndicatorPrivacySettings | ||
| publicize_model UnmuteUsersResponse | ||
| publicize_model UnreadChannel | ||
| publicize_model UnreadChannelByType | ||
| publicize_model UnreadThread | ||
| publicize_model UploadConfig | ||
| publicize_model UserGroup | ||
| publicize_model UserGroupMember | ||
| publicize_model UserPrivacySettings | ||
|
|
||
| # Drop `final` from a generated model so hand-written payloads can subclass it. | ||
| unfinalize_model() { | ||
| # Expose a generated model's memberwise init, for models whose hand-written public | ||
| # counterpart had a public init. | ||
| publicize_init() { | ||
|
Comment on lines
+577
to
+579
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoiding breaking changes when using generated model in the public API layer |
||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| sed -i '' -E \ | ||
| -e 's/^final class /class /' \ | ||
| -e 's/^(class [A-Za-z0-9_]+): Sendable,/\1: @unchecked Sendable,/' \ | ||
| "$file" | ||
| sed -i '' -E 's/^ init\(/ public init(/' "$file" | ||
| } | ||
| publicize_init DeliveryReceiptsPrivacySettings | ||
| publicize_init ReadReceiptsPrivacySettings | ||
| publicize_init TypingIndicatorPrivacySettings | ||
|
|
||
| # Give a generated memberwise init parameter a default value, restoring one the | ||
| # hand-written public init had. | ||
| default_init_parameter() { | ||
|
Comment on lines
+587
to
+589
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoiding breaking changes when using generated model in the public API layer
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably we should mark this for removal in v6
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| local file="$OUTPUT_DIR_CHAT/models/$1.swift" | ||
| P="$2" D="$3" perl -0777 -pi -e ' | ||
| my ($p, $d) = ($ENV{P}, $ENV{D}); | ||
| s/([(,]\s*)\Q$p\E: ([^,)\n=]+)(?=[,)])/${1}$p: $2 = $d/; | ||
| ' "$file" | ||
| } | ||
| unfinalize_model UserPayload | ||
| default_init_parameter DeliveryReceiptsPrivacySettings enabled true | ||
| default_init_parameter ReadReceiptsPrivacySettings enabled true | ||
| default_init_parameter TypingIndicatorPrivacySettings enabled true | ||
|
|
||
| # 4d. Strip the generated Hashable conformance from every model not in | ||
| # allowed_hashable_models. The Hashable extension is always the last block in | ||
|
|
@@ -613,7 +678,6 @@ inject_v1_endpoint_paths() { | |
| case banMember | ||
| case flagUser | ||
| case flagMessage | ||
| case muteUser(Bool) | ||
|
|
||
| EOF | ||
|
|
||
|
|
@@ -667,7 +731,6 @@ EOF | |
| case .banMember: return "moderation/ban" | ||
| case .flagUser: return "moderation/flag" | ||
| case .flagMessage: return "moderation/flag" | ||
| case let .muteUser(mute): return "moderation/\(mute ? "mute" : "unmute")" | ||
|
|
||
| EOF | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Report the actual unmuted user count.
If
response.nonExistingUsersis not empty, Line 509 reports users as unmuted even though the response reports them as not found. Subtract the missing-user count frommemberIds.count.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents