federation_sketches.diff

yossarian, 04/24/2009 01:27 am

Download (3.8 KB)

 
app/models/content.rb (working copy)
38 38
    result = nil if result.is_a?(Array) && result.first == nil
39 39
  end
40 40
  
41
  
42 41
  attr_protected :moderation_status
43 42
    
44 43
  # A convenience method to tell us whether this content is attached to 
......
122 121
    unless status.nil?
123 122
      self.moderation_status = status if user.can_set_moderation_status_to?(status, self)
124 123
    end
124

  
125
    send_this_to_subscribers
125 126
  end
127

  
128
  # this is what subscriptions look like
129
  #create table subscriptions ( destination_address varchar, feed text )
130
#
131
#  SELECT * FROM subscriptions WHERE feed IN (feeds_i_belong_to)
132

  
133
  def send_this_to_subscribers
134
    Subscriptions.find(:all, {:feed => feeds_i_belong_to}).each do |subscription|
135
      deliverer.send(:to => subscription.to, :content => self.to_atom)
136
    end
137
  end
138

  
139
  def feeds_i_belong_to
140
    ["/all_content.atom"]
141
  end
142

  
143
  def feeds_i_belong_to
144
    base = ["/all_posts.atom", super]
145
    tags = self.tags.map { |tag|
146
      "http://london.indymedia.org.uk/tags/#{tag.tag}.atom" }
147
    base + tags
148
  end
149

  
150
  ===== notes
151

  
152
  GET / HTTP/1.1
153
  Host: facebook.com
154
  <html>...
155
  <link rel="address-mapper" href="http://facebook.com/$1" />
156
  ...</html>
157

  
158
  GET / HTTP/1.1
159
  Host: flickr.com
160
  <html>...
161
  <link rel="address-mapper" href="xmpp:$1@flickr.com" />
162
  ...</html>
163

  
164
  grandmother@facebook.com -> me@flickr.com
165

  
166
  <me sits at computer, sees request from grandmother@facebook.com> <click "YES">
167

  
168

  
169

  
170

  
171

  
172

  
173
  <iq type="set" to="london.indymedia.org.uk" from="me@ihatecops.com" id="nnasdf">
174
    <pubsub>
175
      <subscribe node="http://london.indymedia.org.uk/tags/pigs.atom" jid="me@ihatecops.com"/>
176
      <subscribe node="http://london.indymedia.org.uk/tags/cops.atom" jid="me@ihatecops.com"/>
177
      <subscribe node="http://london.indymedia.org.uk/tags/police.atom" jid="me@ihatecops.com"/>
178
      <subscribe node="http://london.indymedia.org.uk/sensitive_data_on_london_cops.atom" jid="me@ihatecops.com"/>
179
    </pubsub>
180
  </iq>
181

  
182
  ==== notes ===
126 183
  
127 184
  protected
128 185
  
......
135 192
    end
136 193
  end
137 194
    
138
end
195
end
lib/global_replication.rb (revision 0)
1
TRUSTED_REPLICATORS=['london1@london1.indymedia.org.uk', 'london2@london2.indymedia.org.uk']
2

  
3
class ActiveRecord::Base
4
  after_save :send_to_trusted_replicators
5

  
6
  def send_to_trusted_replicators
7
    MiddleMan.new_worker(:class => :replicator_worker,
8
                         :job_key => "replication_#{self.class}_#{self.object_id.to_s}",
9
                         :args => { :object => self }) unless RAILS_ENV == 'test'
10
  end
11
end
lib/workers/replicator_worker.rb (revision 0)
1
class ReplicatorWorker < BackgrounDRb::Rails
2

  
3
  # This method is called in it's own new thread when you
4
  # call new worker. args is set to :args  
5
  def do_work(args)
6
    TRUSTED_REPLICATORS.each do |replicant|
7
      jabber_client.send(replicant, Marshal.dump(args[:object]))
8
    end
9
  end
10

  
11
  def jabber_client
12
    return @jabber_client if @jabber_client
13

  
14
    @jabber_client ||= Jabber::Simple.new('london1@london1.indymedia.org.uk', JABBER_PASSWORD)
15
    @reception_thread = Thread.new {
16
      @jabber_client.received_messages do |message|
17
        next unless TRUSTED_REPLICATORS.include?(message.from)
18

  
19
        new_record = Marshal.load(message.body)
20
        new_record.save
21
      end
22
    }
23
  end
24
  
25
end