From 302cf54fab7f4f77dd43bb068b2a24b0dcb363b9 Mon Sep 17 00:00:00 2001
From: maxwell <maxwell@joindiaspora.com>
Date: Fri, 23 Jul 2010 21:31:28 -0700
Subject: [PATCH] MS subscribers should now unsubscribe

---
 app/controllers/authors_controller.rb | 7 +++++++
 app/models/author.rb                  | 7 ++++++-
 app/views/authors/show.html.haml      | 2 +-
 app/views/dashboards/index.html.haml  | 1 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb
index ebf6b50969..2f53c442b9 100644
--- a/app/controllers/authors_controller.rb
+++ b/app/controllers/authors_controller.rb
@@ -5,5 +5,12 @@ class AuthorsController < ApplicationController
     @author= Author.where(:id => params[:id]).first
     @author_ostatus_posts = @author.ostatus_posts.sort(:created_at.desc)
   end
+
+
+  def destroy
+    current_user.unsubscribe_from_pubsub(params[:id])
+    flash[:notice] = "unsubscribed person."
+    redirect_to ostatus_path 
+  end 
   
 end
diff --git a/app/models/author.rb b/app/models/author.rb
index 2f50c28cb9..1547e67fa7 100644
--- a/app/models/author.rb
+++ b/app/models/author.rb
@@ -9,7 +9,8 @@ class Author
   key :hub, String
 
   many :ostatus_posts, :class_name => 'OstatusPost', :foreign_key => :author_id
-  before_save :set_defaults  
+  before_save :set_defaults 
+  before_destroy :delete_posts
 
   def self.instantiate(opts)
     author = Author.first(:feed_url => opts[:feed_url])
@@ -22,4 +23,8 @@ class Author
     self.avatar_thumbnail = nil if self.avatar_thumbnail == 0
     self.service = self.url if self.service == 0
   end
+
+  def delete_posts
+    self.ostatus_posts.delete_all
+  end
  end
diff --git a/app/views/authors/show.html.haml b/app/views/authors/show.html.haml
index 7191f40a66..364bf6eace 100644
--- a/app/views/authors/show.html.haml
+++ b/app/views/authors/show.html.haml
@@ -1,6 +1,6 @@
 .span-20.last
   %h1= "#{@author.username}"
-
+  = link_to 'unsubscribe', @author, :confirm => 'Are you sure?', :method => :delete
 .span-20
   - if @author_ostatus_posts
 
diff --git a/app/views/dashboards/index.html.haml b/app/views/dashboards/index.html.haml
index 088ec334fb..86dbeeec90 100644
--- a/app/views/dashboards/index.html.haml
+++ b/app/views/dashboards/index.html.haml
@@ -7,6 +7,7 @@
 %h1= title_for_page
 = render "shared/publisher"
 %ul#stream
+  = puts @posts.inspect
   - for post in @posts
     = render type_partial(post), :post => post
 #pagination
-- 
GitLab