Permalink
Browse files

Implemented /chat/superfeedr using XMPP

  • Loading branch information...
1 parent 29bd565 commit 0ad52606fc58d0942c19abb8be6647c9117689f8 @miyagawa committed Oct 19, 2009
Showing with 48 additions and 20 deletions.
  1. +48 −20 eg/demo.pl
View
@@ -222,26 +222,54 @@ package main;
}
}
-if ($ENV{FRIENDFEED_USERNAME}) {
- if (try { require AnyEvent::FriendFeed::Realtime }) {
- my $mq = Tatsumaki::MessageQueue->instance("friendfeed");
- my $entry_cb = sub {
- my $entry = shift;
- $mq->publish({
- type => "message", address => 'friendfeed.com', time => scalar localtime,
- name => $entry->{from}{name},
- avatar => "http://friendfeed-api.com/v2/picture/$entry->{from}{id}",
- html => $entry->{body},
- ident => $entry->{url},
- });
- };
- my $client; $client = AnyEvent::FriendFeed::Realtime->new(
- request => "/feed/$ENV{FRIENDFEED_USERNAME}/friends",
- on_entry => $entry_cb,
- on_error => sub { $client },
- );
- warn "FriendFeed stream is available at /chat/friendfeed\n";
- }
+if ($ENV{FRIENDFEED_USERNAME} && try { require AnyEvent::FriendFeed::Realtime }) {
+ my $mq = Tatsumaki::MessageQueue->instance("friendfeed");
+ my $entry_cb = sub {
+ my $entry = shift;
+ $mq->publish({
+ type => "message", address => 'friendfeed.com', time => scalar localtime,
+ name => $entry->{from}{name},
+ avatar => "http://friendfeed-api.com/v2/picture/$entry->{from}{id}",
+ html => $entry->{body},
+ ident => $entry->{url},
+ });
+ };
+ my $client; $client = AnyEvent::FriendFeed::Realtime->new(
+ request => "/feed/$ENV{FRIENDFEED_USERNAME}/friends",
+ on_entry => $entry_cb,
+ on_error => sub { $client },
+ );
+ warn "FriendFeed stream is available at /chat/friendfeed\n";
+}
+
+if ($ENV{SUPERFEEDR_JID} && try { require AnyEvent::Superfeedr }) {
+ $XML::Atom::ForceUnicode = 1;
+ my $mq = Tatsumaki::MessageQueue->instance("superfeedr");
+ my $entry_cb = sub {
+ my($entry, $feed_uri) = @_;
+ warn $feed_uri;
+ my $host = URI->new($feed_uri)->host;
+ $mq->publish({
+ type => "message", address => $host, time => scalar localtime,
+ name => $entry->title,
+ avatar => "http://www.google.com/s2/favicons?domain=$host",
+ html => $entry->summary,
+ ident => $entry->link->href,
+ });
+ };
+ my $superfeedr; $superfeedr = AnyEvent::Superfeedr->new(
+ debug => 0,
+ jid => $ENV{SUPERFEEDR_JID},
+ password => $ENV{SUPERFEEDR_PASSWORD},
+ on_notification => sub {
+ scalar $superfeedr;
+ my $notification = shift;
+ for my $entry ($notification->entries) {
+ $entry_cb->($entry, $notification->feed_uri);
+ }
+ },
+ );
+ warn "Superfeedr channel is available at /chat/superfeedr\n";
}
if (__FILE__ eq $0) {

0 comments on commit 0ad5260

Please sign in to comment.