Skip to content

Add IM\Recent service for im.recent.* API support#466

Merged
mesilov merged 3 commits intov3-devfrom
feature/427-add-im-recent-service
Apr 29, 2026
Merged

Add IM\Recent service for im.recent.* API support#466
mesilov merged 3 commits intov3-devfrom
feature/427-add-im-recent-service

Conversation

@mesilov
Copy link
Copy Markdown
Collaborator

@mesilov mesilov commented Apr 29, 2026

Q A
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #427
License MIT

Description

This PR implements the IM\Recent service to wrap Bitrix24 REST API methods for managing recent chats and dialogs.

Changes

New Service & Result Classes:

  • Recent service with 5 methods:

    • get(?int $lastId, ?int $limit): RecentsResult – Returns a shortened list of recent chats
    • list(?int $lastId, ?int $limit): RecentsResult – Returns the full recent dialogs list with pagination
    • pin(string $dialogId, bool $pin): UpdatedItemResult – Pins or unpins a dialog
    • unread(string $dialogId, string $action): UpdatedItemResult – Sets or removes the "unread" mark
    • hide(string $dialogId): UpdatedItemResult – Removes a chat from the recent list
  • RecentItemResult – Annotated result item with properties: id, type, avatar, color, title, counter, unread, pinned, user_id, chat_id, message, date_message

  • RecentsResult – Container result for list responses

Integration:

  • Added IMServiceBuilder::recent() accessor method
  • Updated phpunit.xml.dist with integration_tests_im_recent testsuite
  • Updated Makefile with test-integration-im-recent target
  • Updated CHANGELOG.md

Tests:

  • Unit test: RecentTest verifies service instantiation
  • Integration tests: Full coverage of all 5 methods with real portal calls
  • Result annotation tests: Validates all fields are properly annotated and type-cast

Compliance

  • All classes extend appropriate base classes from Core (no cross-scope dependencies)
  • Follows existing IM service patterns (similar to Dialog, Counters)
  • No deptrac violations introduced
  • All linting and test suites pass

Test Plan

Run the integration test suite:

make test-integration-im-recent

All existing unit and integration tests continue to pass.

https://claude.ai/code/session_01JU6axyfnTk62HoezmhWfWL

Implements im.recent.get, im.recent.list, im.recent.pin,
im.recent.unread, and im.recent.hide via
Bitrix24\SDK\Services\IM\Recent\Service\Recent.

Adds RecentItemResult, RecentsResult, IMServiceBuilder::recent(),
unit/integration/annotation tests, phpunit suite, and Makefile target.

https://claude.ai/code/session_01JU6axyfnTk62HoezmhWfWL
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf668f5741

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +27 to +29
return array_values(array_map(
static fn(array $item): RecentItemResult => new RecentItemResult($item),
array_filter($this->getCoreResponse()->getResponseData()->getResult(), 'is_array')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Parse im.recent.list items from nested result.items

RecentsResult::items() currently maps every top-level array inside result, but im.recent.list returns an object where dialogs are nested under result["items"] (alongside other array/object fields like copilot). In that shape, this code builds RecentItemResult objects from non-dialog payloads, so consumers of recent()->list()->items() get malformed entries (e.g., missing id, chat_id) instead of actual recent dialogs.

Useful? React with 👍 / 👎.

Comment on lines +61 to +63
$payload = [
'LAST_ID' => $lastId,
'LIMIT' => $limit,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use supported pagination parameter for im.recent.list

The list() wrapper sends LAST_ID, but im.recent.list pagination is driven by OFFSET (with LIMIT). As implemented, callers cannot advance through pages via this method signature, because the provided cursor argument is not mapped to the API’s pagination contract, which can lead to repeatedly fetching the first page.

Useful? React with 👍 / 👎.

@mesilov mesilov added this to the 3.2.0 milestone Apr 29, 2026
mesilov added 2 commits April 29, 2026 17:45
…onsTest` and update type annotations

- Renamed and reorganized integration tests for `RecentItemResult` into `RecentItemResultAnnotationsTest`.
- Updated `RecentItemResult` with new fields (`last_id`, `has_reminder`, `date_update`, etc.) and improved type annotations.
- Enhanced type safety with consistent property definitions and runtime casting.

Signed-off-by: mesilov <mesilov.maxim@gmail.com>
…ecent.get` payload fields

- Adjusted PHPDoc comments in `RecentItemResult` to match live REST API data structure and magic getter behavior.
- Updated `CHANGELOG.md` with details of the fix.

Signed-off-by: mesilov <mesilov.maxim@gmail.com>
@mesilov mesilov self-assigned this Apr 29, 2026
@mesilov mesilov merged commit 5ada09d into v3-dev Apr 29, 2026
10 checks 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.

2 participants