-
Notifications
You must be signed in to change notification settings - Fork 8.6k
DEV: Refactor Chat::ListChannelThreadMessages
a bit
#33380
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
Conversation
f7803ba
to
bf0465d
Compare
bf0465d
to
4867189
Compare
@dbattersby can you review this please? I think it's interesting to see how Loic refactors code. |
4867189
to
3d7459a
Compare
@@ -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) |
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.
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 }), |
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.
This was a bug as we were always forcing the page_size
.
3d7459a
to
32524dd
Compare
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 |
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.
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?
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.
32524dd
to
a241a6d
Compare
- 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.
max_page_size
option, allowing different behavior between controllers and SDK.model
where possible.