Skip to content

Conversation

@sgrimee
Copy link
Contributor

@sgrimee sgrimee commented Dec 18, 2025

Summary

This PR introduces the leave_room() method for leaving group rooms, comprehensive HTTP error handling improvements, and various quality-of-life enhancements. The library is now version 0.10.1.

Key Features

  • New: leave_room() method with user ID caching to leave group rooms (direct rooms return user-friendly error)
  • New: get_user_id() cached method to avoid repeated /people/me API calls
  • New: Comprehensive test suite for leave_room functionality with mockito mocking
  • Improved: Detailed HTTP error parsing with JSON and HTML response handling
  • Improved: Clear 403 error messages indicating required spark:devices_write and spark:devices_read OAuth scopes
  • Fixed: api_delete now properly handles 204 No Content responses from DELETE endpoints
  • Fixed: Serde attributes for Membership and Person struct deserialization
  • Fixed: Serde aliases for adaptive card enum variants (Size, ImageSize)
  • Refactored: Replaced lazy_static! with std::sync::LazyLock
  • Refactored: Reduced cognitive complexity in error handling paths
  • Refactored: Removed elidable lifetime annotations from API functions
  • Refactored: Applied clippy formatting suggestions throughout

API Changes

New Public Methods

pub async fn leave_room(&self, room_id: &types::GlobalId) -> Result<(), Error>

Allows users to leave group rooms by deleting their membership. Returns Error::UserError for direct message rooms since the Webex API doesn't support leaving those.

async fn get_user_id(&self) -> Result<String, Error>

Internal method that fetches and caches the current user's ID to optimize repeated API calls.

New Error Variant

Error::UserError(String)

User-facing error messages for API limitations (e.g., cannot leave direct rooms).

Internal Changes

  • Webex struct: Added user_id: Arc<Mutex<Option<String>>> field for caching
  • Error struct: Changed Tungstenite variant to use Box<tungstenite::Error> to reduce Result size
  • Error struct: Added UserError variant for user-facing messages
  • RestClient: Improved rest_api method with comprehensive error response parsing
  • Device handling: Better error messages and fallback logic for 403 Forbidden responses

Testing

All tests pass (8 total):

  • 4 new leave_room tests covering success, errors, and edge cases
  • 4 existing type parsing tests continue to pass

Commits

  1. fix: correct serde attributes for Membership and Person structs
  2. fix: add serde aliases for adaptive card enum variants
  3. feat: add leave_room foundation with UserError and improved Tungstenite error handling
  4. feat: implement leave_room, improve error handling, and refactor for reduced complexity
  5. refactor: apply clippy formatting suggestions to examples
  6. chore: update .gitignore for Claude AI settings
  7. chore: bump version to 0.10.1
  8. chore: add nix flake for reproducible dev environment (dev)
  9. chore: add VSCode debug launch configurations (dev)
  10. chore: add editor ignore patterns and AI assistant documentation (dev)

The last 3 commits (8-10) are development environment configurations and can be dropped if preferred, keeping only the library improvements (commits 1-7).

sgrimee added 14 commits August 6, 2025 17:25
- Implement leave_room method to allow users to exit Webex rooms by deleting their membership
- Add Membership struct and MembershipListParams for room membership management
- Include UserError variant for better user-facing error messages
- Add comprehensive test suite with mockito for HTTP mocking
- Fix minor WebSocket event handling issue
- Update GlobalIdType enum to support Membership operations
- Add field-level rename attributes to Membership struct fields to match API JSON format
- Change Membership is_moderator and is_monitor from Option<bool> to bool with defaults
- Change Membership created from Option<String> to String
- Make Person struct fields optional where API may not return them (phone_numbers, nick_name, first_name, last_name, avatar)
- Add rename attributes for Person fields (displayName, orgId)

These changes ensure proper deserialization of API responses and fix errors
when parsing membership and person data from Webex API.
…tion

Implementation changes:
- Fix api_delete to properly handle 204 No Content responses from DELETE endpoints
- Implement leave_room() to delete user's membership from group rooms
- Add get_user_id() method with caching to avoid repeated /people/me API calls
- Add user_id field to Webex struct (Arc<Mutex<Option<String>>>) for thread-safe caching
- Check room type before leaving - return error for 1:1 direct rooms (API limitation)
- Remove broken personId=me filter, instead list all memberships and find user's

API behavior:
- Direct rooms cannot be left via Webex API (returns clear error message)
- Group rooms can be left by deleting the user's membership
- User ID is fetched once and cached for the lifetime of the Webex client

Testing:
- Add comprehensive test suite with 4 test cases:
  * test_leave_room_success - successful group room departure
  * test_leave_room_user_not_member - error when user not in room
  * test_leave_room_api_error - API error handling (403 response)
  * test_leave_room_direct_room_error - proper error for direct rooms
- Update test mocks to include room details and people/me endpoints
- All tests pass

This fixes the issue where deleted rooms would reappear after app restart.
Allow both camelCase and PascalCase deserialization for Size and ImageSize
enums to handle variations in API responses
- Add comprehensive HTTP status code checking with proper Error::StatusText wrapping
- Parse JSON and HTML error responses with appropriate logging levels
- Add ListResult struct flexibility to handle various API response formats
- Improve device registration error handling with fallback mechanisms for 403 errors
- Add organization listing error handling for insufficient permissions
- Add detailed error messages when device endpoints return 403 errors
- Clearly indicate required spark:devices_write and spark:devices_read scopes
- Improve error logging for mercury/WDM endpoint 403 responses
- Help users understand OAuth scope requirements for event streams
- Box large Tungstenite error variant to reduce Result size
- Refactor get_devices into smaller functions (complexity 43→acceptable)
- Replace lazy_static with std::sync::LazyLock
- Remove elidable lifetime annotations in API functions
- Merge identical match arms
- Apply clippy formatting suggestions throughout
@mistastn
Copy link

I do intend to do some work on this as well so I will bump the version as part of that.

@aknarts aknarts merged commit f132301 into wr-org:master Dec 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants