Skip to content

Conversation

Flink
Copy link
Contributor

@Flink Flink commented Jun 27, 2025

  • Introduce a max_page_size option, allowing different behavior between controllers and SDK.
  • Improve the contract (validations & helper method).
  • Use model where possible.
  • Extract message existence logic to a dedicated policy, allowing easier testing.
  • Refactor specs to follow current guidelines/best practices.

@Flink Flink self-assigned this Jun 27, 2025
@github-actions github-actions bot added the chat PRs which include a change to Chat plugin label Jun 27, 2025
@Flink Flink force-pushed the loic-refactor-list-channel-thread-messages branch 2 times, most recently from f7803ba to bf0465d Compare July 4, 2025 12:49
@Flink Flink marked this pull request as ready for review July 4, 2025 12:50
@Flink Flink requested a review from jjaffeux July 7, 2025 11:58
@Flink Flink force-pushed the loic-refactor-list-channel-thread-messages branch from bf0465d to 4867189 Compare July 18, 2025 09:51
@jjaffeux
Copy link
Contributor

@dbattersby can you review this please? I think it's interesting to see how Loic refactors code.

@Flink Flink force-pushed the loic-refactor-list-channel-thread-messages branch from 4867189 to 3d7459a Compare August 7, 2025 16:16
@@ -5,15 +5,19 @@

module DiscourseDev
class Thread < Record
def initialize(channel_id:, message_count: nil, ignore_current_count: false)
def initialize(channel_id:, count: nil, ignore_current_count: false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems this whole class has been broken for quite some time 😅

def index
::Chat::ListChannelThreadMessages.call(
service_params.deep_merge(params: { page_size: MAX_PAGE_SIZE }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a bug as we were always forcing the page_size.

@Flink Flink force-pushed the loic-refactor-list-channel-thread-messages branch from 3d7459a to 32524dd Compare August 7, 2025 16:32
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/chat-api-page-size-parameter-is-ignored-when-direction-past/376984/5

Copy link
Contributor

@jjaffeux jjaffeux left a comment

Choose a reason for hiding this comment

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

Looks very good thanks! My only question is: is it better to raise an error when over the limit or automatically clamp it to the max?

@Flink
Copy link
Contributor Author

Flink commented Aug 8, 2025

I’m not sure what’s best, tbh. It’s a slightly different approach, and we’re already returning an error for this case in https://github.com/discourse/discourse/blob/main/plugins/chat/app/services/chat/list_channel_messages.rb. We should stay consistent (one way or another).

- Introduce a `max_page_size` option, allowing different behavior
  between controllers and SDK.
- Improve the contract (validations & helper method).
- Use `model` where possible.
- Extract message existence logic to a dedicated policy, allowing easier
  testing.
- Refactor specs to follow current guidelines/best practices.
@Flink Flink force-pushed the loic-refactor-list-channel-thread-messages branch from 32524dd to a241a6d Compare August 8, 2025 10:35
@Flink Flink merged commit 8dd3038 into main Aug 8, 2025
16 checks passed
@Flink Flink deleted the loic-refactor-list-channel-thread-messages branch August 8, 2025 12:05
pento pushed a commit that referenced this pull request Aug 11, 2025
- Introduce a `max_page_size` option, allowing different behavior
between controllers and SDK.
- Improve the contract (validations & helper method).
- Use `model` where possible.
- Extract message existence logic to a dedicated policy, allowing easier
testing.
- Refactor specs to follow current guidelines/best practices.
yuriyaran pushed a commit that referenced this pull request Aug 21, 2025
- Introduce a `max_page_size` option, allowing different behavior
between controllers and SDK.
- Improve the contract (validations & helper method).
- Use `model` where possible.
- Extract message existence logic to a dedicated policy, allowing easier
testing.
- Refactor specs to follow current guidelines/best practices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chat PRs which include a change to Chat plugin
Development

Successfully merging this pull request may close these issues.

3 participants