<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>views/mentions.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,7 @@
 Retwis-RB
 =========
 
-An example application using the Redis key-value database.
+An example Twitter application using the Redis key-value database.
 
 Daniel Lucraft (dan@fluentradical.com)
 </diff>
      <filename>README.md</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,6 @@ end
 
 before do
   keys = redis.keys(&quot;*&quot;)
-  p keys
 end
 
 get '/' do
@@ -66,11 +65,16 @@ get '/:username' do |username|
   erb :profile
 end
 
+get '/:username/mentions' do |username|
+  @user = User.find_by_username(username)
+  @posts = @user.mentions
+  erb :mentions
+end
 
 helpers do
   def link_to_user(user)
     f = &lt;&lt;-HTML
-      &lt;a href=&quot;/#{user.username}&quot;&gt;#{user.username}&lt;/a&gt;
+&lt;a href=&quot;/#{user.username}&quot;&gt;#{user.username}&lt;/a&gt;
     HTML
   end
   
@@ -81,6 +85,16 @@ helpers do
       count.to_s + &quot; &quot; + plural
     end
   end
+  
+  def display_post(post)
+    post.content.gsub(/@\w+/) do |mention|
+      if user = User.find_by_username(mention[1..-1])
+        &quot;@&quot; + link_to_user(user)
+      else
+        mention
+      end
+    end
+  end
 
   def time_ago_in_words(time)
     distance_in_seconds = (Time.now - time).round</diff>
      <filename>app.rb</filename>
    </modified>
    <modified>
      <diff>@@ -96,6 +96,13 @@ class User &lt; Model
     end
   end
   
+  def mentions(page=1)
+    from, to = (page-1)*10, page*10
+    redis.list_range(&quot;user:id:#{id}:mentions&quot;, from, to).map do |post_id|
+      Post.new(post_id)
+    end
+  end
+  
   def add_post(post)
     redis.push_head(&quot;user:id:#{id}:posts&quot;, post.id)
     redis.push_head(&quot;user:id:#{id}:timeline&quot;, post.id)
@@ -105,6 +112,10 @@ class User &lt; Model
     redis.push_head(&quot;user:id:#{id}:timeline&quot;, post.id)
   end
   
+  def add_mention(post)
+    redis.push_head(&quot;user:id:#{id}:mentions&quot;, post.id)
+  end
+  
   def follow(user)
     return if user == self
     redis.set_add(&quot;user:id:#{id}:followees&quot;, user.id)
@@ -155,6 +166,11 @@ class Post &lt; Model
     post.user.followers.each do |follower|
       follower.add_timeline_post(post)
     end
+    content.scan(/@\w+/).each do |mention|
+      if user = User.find_by_username(mention[1..-1])
+        user.add_mention(post)
+      end
+    end
   end
   
   property :content</diff>
      <filename>domain.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,10 +3,13 @@
   &lt;% @posts.each do |post| %&gt;
     &lt;div class=&quot;post&quot;&gt;
       &lt;strong&gt;&lt;%= link_to_user(post.user) %&gt;&lt;/strong&gt;
-      &lt;%= post.content %&gt;&lt;br /&gt;
+      &lt;%= display_post(post) %&gt;
       &lt;div class=&quot;date&quot;&gt;
         &lt;%= time_ago_in_words(post.created_at) %&gt;
       &lt;/div&gt;
     &lt;/div&gt;
   &lt;% end %&gt;
+  &lt;% if @posts.empty? %&gt;
+    No posts.
+  &lt;% end %&gt;
 &lt;/div&gt;</diff>
      <filename>views/_posts.erb</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,8 @@
             &lt;% if @logged_in_user %&gt;
               &lt;br /&gt;&lt;br /&gt;
               &lt;a href=&quot;/&quot;&gt;home&lt;/a&gt; | 
-              &lt;%= link_to_user(@logged_in_user) %&gt; | 
+              &lt;a href=&quot;/&lt;%= @logged_in_user.username %&gt;/mentions&quot;&gt;mentions&lt;/a&gt; | 
+                &lt;%= link_to_user(@logged_in_user) %&gt; | 
               &lt;a href=&quot;/timeline&quot;&gt;timeline&lt;/a&gt; | 
               &lt;a href=&quot;/logout&quot;&gt;logout&lt;/a&gt;
             &lt;% end %&gt;</diff>
      <filename>views/header.erb</filename>
    </modified>
    <modified>
      <diff>@@ -9,6 +9,7 @@
       &lt;% else %&gt;
         &lt;a href=&quot;/&lt;%= @logged_in_user.username %&gt;/follow/&lt;%= @user.username %&gt;&quot;&gt;Follow&lt;/a&gt;
       &lt;% end %&gt;
+      | &lt;a href=&quot;/&lt;%= @user.username %&gt;/mentions&quot;&gt;See mentions&lt;/a&gt;
     &lt;/div&gt;
   &lt;% end %&gt;
   </diff>
      <filename>views/profile.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>68e4b5919964768f7fae0841df915bc155f3b6e1</id>
    </parent>
  </parents>
  <author>
    <name>Daniel Lucraft</name>
    <email>dan@fluentradical.com</email>
  </author>
  <url>http://github.com/danlucraft/retwis-rb/commit/544defafe2922cfda66ccf100768cdc1ea9a3579</url>
  <id>544defafe2922cfda66ccf100768cdc1ea9a3579</id>
  <committed-date>2009-05-24T04:49:43-07:00</committed-date>
  <authored-date>2009-05-24T04:49:43-07:00</authored-date>
  <message>Implemented mentions (replies)</message>
  <tree>28bc124686a035ed82b56b2f1fd9a158d9c6e141</tree>
  <committer>
    <name>Daniel Lucraft</name>
    <email>dan@fluentradical.com</email>
  </committer>
</commit>
