-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
List messages #11
Conversation
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.
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.
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]) |
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 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.
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.
Good point, thanks
|
||
def max_items_page | ||
limit = Integer(params[:limit]) | ||
limit <= 20 ? limit : 20 |
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.
You can define a constant or an env variable.
def max_items_page | ||
limit = Integer(params[:limit]) | ||
limit <= 20 ? limit : 20 | ||
end |
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.
Optional: Maybe it's a good idea to use a gem like pagy to implement pagination.
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.
Good work! 👏
validates :user, presence: false | ||
validates :conversation, presence: 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.
Is this necessary?
https://trello.com/c/BfWJrarf/11-5-as-a-user-i-should-be-able-to-see-the-message-history-paginated-in-a-conversation