Skip to content
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

List messages #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

List messages #11

wants to merge 4 commits into from

Conversation

Copy link
Collaborator

@enzofab91 enzofab91 left a comment

Choose a reason for hiding this comment

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

Same comment as previous PR. Try fixing previous one first.

As a suggestion, if you are not creating branches from develop from each feature, you can change your base branch of this PR and when the previous one is merged do a rebase with this one.

@rodrieiz rodrieiz changed the base branch from master to send_message August 31, 2021 17:12
def index
@conversation = Conversation.find(params[:conversation_id])
if @conversation && (current_user == @conversation.user1 || current_user == @conversation.user2)
@messages = @conversation.messages.limit(params[:limit]).offset(params[:offset])
Copy link

Choose a reason for hiding this comment

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

It would be good to choose an upper limit for limit, so a user can't just ask for a million messages, extreme and probably there won't be a conversation with that, but you can set a limit of 10 or 20 and they can make multiple requests if they want to.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good point, thanks

@rodrieiz rodrieiz requested a review from enzofab91 September 3, 2021 19:39

def max_items_page
limit = Integer(params[:limit])
limit <= 20 ? limit : 20
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can define a constant or an env variable.

@rodrieiz rodrieiz changed the base branch from send_message to master September 6, 2021 11:42
def max_items_page
limit = Integer(params[:limit])
limit <= 20 ? limit : 20
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: Maybe it's a good idea to use a gem like pagy to implement pagination.

Copy link
Collaborator

@enzofab91 enzofab91 left a comment

Choose a reason for hiding this comment

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

Good work! 👏

Comment on lines +17 to +18
validates :user, presence: false
validates :conversation, presence: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary?

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.

4 participants