-
Notifications
You must be signed in to change notification settings - Fork 20
Feat: Added Delete for me support on behalf of a user #204
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,10 @@ def _make_request( | |
| data: Any = None, | ||
| ) -> StreamResponse: | ||
| params = params or {} | ||
| # Convert boolean values to lowercase strings for consistency with async implementation | ||
| params = { | ||
| k: str(v).lower() if isinstance(v, bool) else v for k, v in params.items() | ||
| } | ||
| data = data or {} | ||
| serialized = None | ||
| default_params = self.get_default_params() | ||
|
|
@@ -94,7 +98,9 @@ def _make_request( | |
|
|
||
| url = f"{self.base_url}/{relative_url}" | ||
|
|
||
| if method.__name__ in ["post", "put", "patch"]: | ||
| if method.__name__ in ["post", "put", "patch"] or ( | ||
| method.__name__ == "delete" and data | ||
| ): | ||
|
Comment on lines
+101
to
+103
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. Added to serialize DELETE body only when data is provided; keeps existing DELETEs unchanged. |
||
| serialized = json.dumps(data) | ||
|
|
||
| response = method( | ||
|
|
@@ -119,8 +125,10 @@ def post( | |
| def get(self, relative_url: str, params: Dict = None) -> StreamResponse: | ||
| return self._make_request(self.session.get, relative_url, params, None) | ||
|
|
||
| def delete(self, relative_url: str, params: Dict = None) -> StreamResponse: | ||
| return self._make_request(self.session.delete, relative_url, params, None) | ||
| def delete( | ||
| self, relative_url: str, params: Dict = None, data: Any = None | ||
| ) -> StreamResponse: | ||
| return self._make_request(self.session.delete, relative_url, params, data) | ||
|
|
||
| def patch( | ||
| self, relative_url: str, params: Dict = None, data: Any = None | ||
|
|
@@ -342,8 +350,24 @@ def update_message_partial( | |
| data.update(options) | ||
| return self.put(f"messages/{message_id}", data=data) | ||
|
|
||
| def delete_message(self, message_id: str, **options: Any) -> StreamResponse: | ||
| return self.delete(f"messages/{message_id}", options) | ||
| def delete_message( | ||
| self, | ||
| message_id: str, | ||
| delete_for_me: bool = False, | ||
| deleted_by: str = None, | ||
| **options: Any, | ||
| ) -> StreamResponse: | ||
| if delete_for_me and not deleted_by: | ||
| raise ValueError("deleted_by is required when delete_for_me is True") | ||
|
|
||
| params = options.copy() | ||
| if delete_for_me: | ||
| # Send in body with acting user for server-side auth compatibility | ||
| body = {"delete_for_me": True, "user": {"id": deleted_by}} | ||
| return self.delete(f"messages/{message_id}", None, body) | ||
| if deleted_by: | ||
| params["deleted_by"] = deleted_by | ||
| return self.delete(f"messages/{message_id}", params) | ||
|
|
||
| def undelete_message(self, message_id: str, user_id: str) -> StreamResponse: | ||
| return self.post( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Added to allow delete(relative_url, params=None, data=None) in async client to match sync behavior.