Unread Messages Count in LovdByLess

   By chris on March 19th 2008 in /dev/rails | 635 views

Recently Less Everything released their “social network in a box” platform Lovd by Less, built upon the Rails framework, and it’s pretty nice. Very easy to set up and get running. I’m enjoying hacking around in it.

One of the first things I noticed was that users weren’t told how many unread messages they have when in their dashboard. Easy enough to add, just make these two small changes:

1. In _private.html.erb change the Messages link to:

<%= link_to( "Messages (#{@p.unread_messages.length.to_s})", messages_path ) unless @p.received_messages.empty? && !@p.has_network? %>

2. In profile.rb change the has_many association to:

has_many :unread_messages,   :class_name => 'Message', :conditions => ["messages.read=?",false], :foreign_key => ‘receiver_id’

(I suspect the change above is actually a fix to an existing bug since calling @p.unread_messages as-is throws a SQL error).

Trackback URI | Comments RSS

Leave a Reply