yakryder / muscle-wizards

Contest prep app
0 stars 1 forks source link

New message count could be refactored #64

Closed dummied closed 8 years ago

dummied commented 8 years ago

https://github.com/SherSpock/muscle-wizards/blob/master/app/controllers/application_controller.rb#L16-L20

I'm thinking something like conversation.unread_count(user)

def unread_count(user)
  this_user = user == recipient ? sender : recipient
  messages.where(user: this_user, read: false).count
end

Then, ideally, you can go a level higher in Prep:

def unread_count(user)
  Conversation.between(athlete_id, coach_id).first.unread_count(user)
end

Your mileage may vary, but I think this would get new_message_count down to:

def new_message_count
  @prep.unread_count(current_user)
end